diff --git a/Changes b/Changes index 9fae797..fe5b642 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for MojoX-Renderer-TT + - revert the change of stash key, template_path is the prior + source for the template file again (Sebastian Knapp) + - 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) diff --git a/lib/MojoX/Renderer/TT.pm b/lib/MojoX/Renderer/TT.pm index 37c0ca4..24e8333 100644 --- a/lib/MojoX/Renderer/TT.pm +++ b/lib/MojoX/Renderer/TT.pm @@ -10,7 +10,7 @@ use File::Spec (); our $VERSION = '0.21'; -__PACKAGE__->attr('tt', chained => 1); +__PACKAGE__->attr('tt'); sub new { Carp::croak "MojoX::Renderer::TT->new() is now ->build()" } @@ -50,9 +50,12 @@ sub _init { } sub _render { - my ($self, $renderer, $c, $output) = @_; + my ($self, $renderer, $c, $output, $options) = @_; - my $template_path = $c->stash->{template}; + my $template_path; + unless($template_path = $c->stash->{'template_path'}) { + $template_path = $renderer->template_path($options); + } unless ( $self->tt->process( @@ -103,22 +106,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 build -This method returns a handler for the Mojo renderer. +This method returns a handler for the Mojolicious renderer. Supported parameters are =over 4 =item mojo -C currently requires a C parameter pointing to the base class (Mojo). -object. +C currently uses a C parameter pointing to the base class (Mojo). +object. When used the INCLUDE_PATH will be set to =item template_options @@ -134,7 +138,6 @@ Ask Bjørn Hansen, C<< >> =head1 TODO * Better support non-Mojolicious frameworks - * Don't require the mojo parameter * Move the default template cache directory? * Better way to pass parameters to the templates? (stash) * More sophisticated default search path? diff --git a/t/render.t b/t/render.t index 3f9dfd6..85dd8ec 100644 --- a/t/render.t +++ b/t/render.t @@ -3,27 +3,37 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 6; -use Mojo::Transaction; -use MojoX::Context; +use Mojolicious; +use Mojolicious::Controller; +use MojoX::Renderer; use_ok('MojoX::Renderer::TT'); -my $c = MojoX::Context->new; +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} = 't/render/template.tt2'; - +$c->stash->{template_path} = 't/render/template.tt2'; $rv = $mt->(undef, $c, \$output); is($rv, 1); is($output, "4\n"); -$c->stash->{template} = 't/render/error.tt2'; +$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"); + + diff --git a/t/render/template.html.tt2 b/t/render/template.html.tt2 new file mode 100644 index 0000000..4c06c07 --- /dev/null +++ b/t/render/template.html.tt2 @@ -0,0 +1 @@ +[% 2 + 2 %]