Compare commits

...
Author SHA1 Message Date
Ask Bjørn Hansen c4c554a46a Prepare 0.31 2009-09-11 16:02:24 -07:00
Ask Bjørn Hansen f2d62f0a25 Remove deprecated 'new' method 2009-09-11 16:01:24 -07:00
Ask Bjørn Hansen 72855bad28 Update MANIFEST (oops, thanks Sebastian) 2009-09-11 15:56:30 -07:00
Ask Bjørn Hansen 29a6a8c946 Update copyright year 2009-09-11 11:55:21 -07:00
Ask Bjørn Hansen 270ec1e6e5 Make changes file formatted nicer 2009-09-11 11:55:03 -07:00
Ask Bjørn Hansen ec4e464d90 Prepare 0.30; update Mojo dependency 2009-09-09 21:18:55 -07:00
giftnussandAsk Bjørn Hansen d7726cfa0e Keep plugin in sync with mojo project
- Add test template with new naming schema

Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2009-09-09 21:15:44 -07:00
Ask Bjørn Hansen 68438d57cb Mojo can't run with -T currently 2009-09-09 21:15:38 -07:00
Ask Bjørn Hansen 6cae190a7a Prepare v0.21 to work with new Mojo's 2009-07-29 15:49:24 -07:00
giftnussandAsk Bjørn Hansen 165c3b39f2 Update stash key from 'template_path' to 'template' to match mojo change
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2009-07-29 15:44:10 -07:00
Ask Bjørn Hansen 460b36497a prepare 0.20 release 2008-12-09 17:20:18 -08:00
Ask Bjørn Hansen 91a817b322 Add default INCLUDE_PATH (templates) 2008-12-09 17:19:43 -08:00
vtiandAsk Bjørn Hansen e779579347 test fix 2008-12-09 16:45:28 -08:00
Ask Bjørn Hansen e3db05fcb6 Merge commit 'vti/vti' 2008-12-08 20:44:26 -08:00
vti 3c8ec94a70 changes due to the new options passed to handler 2008-12-07 01:08:07 +01:00
Ask Bjørn Hansen a3b6ccdb2b Update MANIFEST files
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-24 03:42:19 -08:00
vtiandAsk Bjørn Hansen bbabbf9ac1 Made default compile dir not unix specific
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-17 02:54:22 -08:00
Ask Bjørn Hansen 0a42dd4f90 Update synopsis (thanks to Fayland 林) 2008-11-17 02:45:49 -08:00
Ask Bjørn Hansen dc1c1570e1 Require Mojo 0.8011 (using named parameters) 2008-11-12 00:16:05 -08:00
Ask Bjørn Hansen 1bcae03e9c perltidy 2008-11-12 00:13:47 -08:00
Ask Bjørn Hansen e0b5f09326 prepare v0.10 2008-11-12 00:07:20 -08:00
Ask Bjørn Hansen 8402f4f597 Update to work with named parameters in new version of Mojo
Instead of "tx" pass the context in the "c" variable
2008-11-12 00:06:20 -08:00
Ask Bjørn Hansen 44f5312fef Move the VERSION definition out of the pod section 2008-11-12 00:04:13 -08:00
Ask Bjørn Hansen 62146bb307 Rename "new" to "build"
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-12 00:04:09 -08:00
vtiandAsk Bjørn Hansen 68783f08e2 fixes due to new Mojo::Renderer error handling, tests
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-11 23:53:28 -08:00
Ask Bjørn Hansen 9dce1eb021 Add note about the git repositories
Fix POD encoding

Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-11 04:05:39 -08:00
12 changed files with 171 additions and 54 deletions
-9
View File
@@ -1,9 +0,0 @@
# auto-generated shipit config file.
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist
git.tagpattern = release/%v
# svn.tagpattern = MyProj-%v
# svn.tagpattern = http://code.example.com/svn/tags/MyProj-%v
# CheckChangeLog.files = ChangeLog, MyProj.CHANGES
+27
View File
@@ -1,5 +1,32 @@
Revision history for MojoX-Renderer-TT
0.31 September 11, 2009
- Remove deprecated 'new' method
- Update MANIFEST (oops, thanks Sebastian)
0.30 September 9, 2009
- Revert the change of template_path stash key
- Reflect recent changes in mojo project (v0.991251) (Sebastian Knapp)
- One test with Mojolicious added (Sebastian Knapp)
0.21 July 29, 2009
- Update stash key from 'template_path' to 'template' to
match mojo change (Sebastian Knapp)
0.20 December 9, 2008
- Updates to work with Mojo 0.9
- Add default INCLUDE_PATH
- Made default compile dir not Unix specific (Viacheslav
Tikhanovskii)
0.10 November 12, 2008
- Update to work with named parameters in new version of Mojo
- Instead of "tx" pass the context in the "c" variable
- Rename "new" to "build"
- Add real tests (Viacheslav Tikhanovskii)
- Update to work with new error handling in Mojo
(Viacheslav Tikhanovskii)
0.02 November 10, 2008
- Add template_options parameter
- Fix Template dependency
+8 -3
View File
@@ -1,10 +1,15 @@
.gitignore
.perltidyrc
Changes
lib/MojoX/Renderer/TT.pm
Makefile.PL
MANIFEST
MANIFEST.SKIP
Makefile.PL
README
lib/MojoX/Renderer/TT.pm
t/00-load.t
t/pod-coverage.t
t/pod.t
.perltidyrc
t/render.t
t/render/template-error.tt2
t/render/template.html.tt2
t/render/template.tt2
+44 -5
View File
@@ -1,5 +1,44 @@
\.git\/
.*~$
\.shipit$
.*\.bak$
^\.gitignore$
# Avoid version control files.
\bRCS\b
\bCVS\b
\bSCCS\b
,v$
\B\.svn\b
\B\.git\b
\b_darcs\b
# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
# Avoid Devel::Cover files.
\bcover_db\b
### DEFAULT MANIFEST.SKIP ENDS HERE ####
\.DS_Store$
\.sw.$
(\w+-)*(\w+)-\d\.\d+(?:\.tar\.gz)?$
\.t\.log$
\.prove$
# XS shit
\.(?:bs|c|o)$
+1 -1
View File
@@ -13,7 +13,7 @@ WriteMakefile(
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'Mojo' => 0.8009,
'Mojo' => 0.991251,
'Template' => 2.18,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+5 -1
View File
@@ -21,6 +21,10 @@ perldoc command.
You can also look for information at:
Git repository
http://git.develooper.com/?p=MojoX-Renderer-TT.git;a=summary
git://git.develooper.com/MojoX-Renderer-TT.git
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT
@@ -33,7 +37,7 @@ You can also look for information at:
COPYRIGHT AND LICENCE
Copyright (C) 2008 Ask Bjørn Hansen
Copyright (C) 2008-2009 Ask Bjørn Hansen
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
+43 -34
View File
@@ -6,10 +6,13 @@ use base 'Mojo::Base';
use Template ();
use Carp ();
use File::Spec ();
__PACKAGE__->attr('tt', chained => 1,);
our $VERSION = '0.31';
sub new {
__PACKAGE__->attr('tt');
sub build {
my $self = shift->SUPER::new(@_);
$self->_init(@_);
return sub { $self->_render(@_) }
@@ -27,8 +30,9 @@ sub _init {
# take and process options :-)
my %config = (
( $mojo ? (INCLUDE_PATH => $mojo->home->rel_dir('templates') ) : () ),
COMPILE_EXT => '.ttc',
COMPILE_DIR => ($dir || "/tmp"),
COMPILE_DIR => ($dir || File::Spec->tmpdir),
UNICODE => 1,
ENCODING => 'utf-8',
CACHE_SIZE => 128,
@@ -44,32 +48,39 @@ sub _init {
}
sub _render {
my ($self, $mojo, $tx, $path, $args) = @_;
my ($self, $renderer, $c, $output, $options) = @_;
$args ||= {};
my $template_path;
unless($template_path = $c->stash->{'template_path'}) {
$template_path = $renderer->template_path($options);
}
#use Data::Dump qw(dump);
#warn dump(\$args);
my $output;
unless ($self->tt->process($path, {%$args, tx => $tx}, \$output, {binmode => ":utf8"})) {
unless (
$self->tt->process(
$template_path, {%{$c->stash}, c => $c},
$output, {binmode => ":utf8"}
)
)
{
Carp::carp $self->tt->error . "\n";
return $self->tt->error;
return 0;
}
else {
return $output;
return 1;
}
}
1; # End of MojoX::Renderer::TT
__END__
=encoding utf-8
=head1 NAME
MojoX::Renderer::TT - Template Toolkit renderer for Mojo
=cut
our $VERSION = '0.02';
=head1 SYNOPSIS
Add the handler:
@@ -79,7 +90,7 @@ Add the handler:
sub startup {
...
my $tt = MojoX::Renderer::TT->new(
my $tt = MojoX::Renderer::TT->build(
mojo => $self,
template_options =>
{ PROCESS => 'tpl/wrapper',
@@ -93,22 +104,23 @@ Add the handler:
And then in the handler call render which will call the
MojoX::Renderer::TT renderer.
$c->render(foo => 123, bar => [qw(giz mo)]);
$c->render(templatename, format => 'tex', handler => 'tt2');
Template parameter are taken from $c->stash
=head1 METHODS
=head2 new
=head2 build
This method returns not a TT object, but a handler for the Mojo renderer.
This method returns a handler for the Mojolicious renderer.
Supported parameters are
=over 4
=item mojo
C<new> currently requires a C<mojo> parameter pointing to the base class (Mojo).
object.
C<build> currently uses a C<mojo> parameter pointing to the base class (Mojo).
object. When used the INCLUDE_PATH will be set to
=item template_options
@@ -123,11 +135,8 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
=head1 TODO
* Rename C<new> to something more sensical?
* Better support non-Mojolicious frameworks
* Don't require the mojo parameter
* Move the default template cache directory?
* Should the "tx" tpl parameter be called "c" (for context) instead?
* Better way to pass parameters to the templates? (stash)
* More sophisticated default search path?
@@ -146,19 +155,21 @@ You can find documentation for this module with the perldoc command.
perldoc MojoX::Renderer::TT
You can also look for information at:
=over 4
=item * git repository
L<http://git.develooper.com/?p=MojoX-Renderer-TT.git;a=summary>,
L<git://git.develooper.com/MojoX-Renderer-TT.git>
L<http://github.com/abh/mojox-renderer-tt/>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/MojoX-Renderer-TT>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/MojoX-Renderer-TT>
@@ -175,12 +186,10 @@ L<http://search.cpan.org/dist/MojoX-Renderer-TT/>
=head1 COPYRIGHT & LICENSE
Copyright 2008 Ask Bjørn Hansen, all rights reserved.
Copyright 2008-2009 Ask Bjørn Hansen, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of MojoX::Renderer::TT
+1 -1
View File
@@ -1,4 +1,4 @@
#!perl -T
#!perl
use Test::More tests => 1;
+39
View File
@@ -0,0 +1,39 @@
#!perl
use strict;
use warnings;
use Test::More tests => 6;
use Mojolicious;
use Mojolicious::Controller;
use MojoX::Renderer;
use_ok('MojoX::Renderer::TT');
my $c = Mojolicious::Controller->new(app => Mojolicious->new);
$c->app->log->path(undef);
$c->app->log->level('fatal');
my $mt = MojoX::Renderer::TT->build;
my $output;
my $rv;
$c->stash->{template_path} = 't/render/template.tt2';
$rv = $mt->(undef, $c, \$output);
is($rv, 1);
is($output, "4\n");
$c->stash->{template_path} = 't/render/error.tt2';
$rv = $mt->(undef, $c, \$output);
is($rv, 0);
ok($output);
delete $c->stash->{template_path};
$c->app->renderer->root('./')->add_handler(tt2 => $mt);
is($c->render('t/render/template','partial' => 1,handler => 'tt2'),"4\n");
+1
View File
@@ -0,0 +1 @@
[% = 2 %]
+1
View File
@@ -0,0 +1 @@
[% 2 + 2 %]
+1
View File
@@ -0,0 +1 @@
[% 2 + 2 %]