From 408cba6c35d13635b3cbab748ff0876d0e7ee2df Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Sun, 27 Jan 2013 22:48:55 -0500 Subject: [PATCH] fix but where DATA templates are not being rendered --- Changes | 3 ++ lib/Mojolicious/Plugin/TtRenderer/Engine.pm | 2 +- t/default_template.t | 10 ++++-- t/default_template2.t | 10 ++++-- t/default_template3.t | 37 +++++++++++++++++++++ t/templates/grimlock.html.tt | 1 + 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 t/default_template3.t create mode 100644 t/templates/grimlock.html.tt diff --git a/Changes b/Changes index 7010836..b2e54fb 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ Revision history for Mojolicious::Plugin::TtRenderer {{$NEXT}} + - fixed but where DATA templates were not being rendered with empty renderer path + +1.37 January 12, 2013 - fix default_template2.t to use temp directory for COMPILE_DIR 1.36 January 9, 2013 diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index de7f059..ce10fe2 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -46,7 +46,7 @@ sub _init { my %config = ( ( @renderer_paths > 0 ? (INCLUDE_PATH => [@renderer_paths, 'templates']) - : () + : (INCLUDE_PATH => ['templates']) ), COMPILE_EXT => '.ttc', COMPILE_DIR => ($dir || abs_path(File::Spec->tmpdir)), diff --git a/t/default_template.t b/t/default_template.t index 5babbcb..edcf36c 100644 --- a/t/default_template.t +++ b/t/default_template.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 9; use Test::Mojo; use File::Temp qw( tempdir ); @@ -11,7 +11,7 @@ app->plugin( tt_renderer => { template_options => { # These options are specific to TT - INCLUDE_PATH => 'templates', + #INCLUDE_PATH => 'templates', COMPILE_DIR => tempdir( CLEANUP => 1 ), COMPILE_EXT => '.ttc', # ... anything else to be passed on to TT should go here @@ -27,6 +27,8 @@ get '/' => sub { get '/bar' => 'bar'; +get '/grimlock' => 'grimlock'; + my $t = Test::Mojo->new; $t->get_ok('/') @@ -37,7 +39,9 @@ $t->get_ok('/bar') ->status_is(200) ->content_like(qr{bar}); -#note $t->tx->res->to_string; +$t->get_ok('/grimlock') + ->status_is(200) + ->content_like(qr{King}); __DATA__ diff --git a/t/default_template2.t b/t/default_template2.t index 574f8c6..5e8c8b4 100644 --- a/t/default_template2.t +++ b/t/default_template2.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 9; use Test::Mojo; use File::Temp qw( tempdir ); use FindBin '$Bin'; @@ -13,7 +13,7 @@ my $tt = Mojolicious::Plugin::TtRenderer::Engine->build( template_options => { UNICODE => 1, ENCODING => 'UTF-8', - INCLUDE_PATH => "$Bin/templates", + #INCLUDE_PATH => "$Bin/templates", COMPILE_DIR => tempdir( CLEANUP => 1 ), } ); @@ -27,6 +27,8 @@ get '/' => sub { get '/bar' => 'bar'; +get '/grimlock' => 'grimlock'; + my $t = Test::Mojo->new; $t->get_ok('/') @@ -37,7 +39,9 @@ $t->get_ok('/bar') ->status_is(200) ->content_like(qr{bar}); -#note $t->tx->res->to_string; +$t->get_ok('/grimlock') + ->status_is(200) + ->content_like(qr{King}); __DATA__ diff --git a/t/default_template3.t b/t/default_template3.t new file mode 100644 index 0000000..8e2854a --- /dev/null +++ b/t/default_template3.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use File::Temp qw( tempdir ); +BEGIN { $ENV{MOJO_HOME} = tempdir( CLEANUP => 1) } +use Test::More tests => 6; +use Test::Mojo; + +use Mojolicious::Lite; +plugin 'tt_renderer'; +app->renderer->default_handler('tt'); + +get '/' => sub { + die 'foo'; +}; + +get '/bar' => 'bar'; + +my $t = Test::Mojo->new; + +$t->get_ok('/') + ->status_is(500) + ->content_like(qr{foo}); + +$t->get_ok('/bar') + ->status_is(200) + ->content_like(qr{bar}); + +#note $t->tx->res->to_string; + +__DATA__ + +@@ index.html.tt +anything + +@@ bar.html.tt +sometimes, the bar, he eats you... + diff --git a/t/templates/grimlock.html.tt b/t/templates/grimlock.html.tt new file mode 100644 index 0000000..bcf7c43 --- /dev/null +++ b/t/templates/grimlock.html.tt @@ -0,0 +1 @@ +Me Grimlock King!