From fe963f65119aebd0937819581b7c45670f26f169 Mon Sep 17 00:00:00 2001 From: Fayland Lam Date: Wed, 24 Apr 2013 17:09:59 +0800 Subject: [PATCH] fix for defaults layout --- lib/Mojolicious/Plugin/TtRenderer/Engine.pm | 6 +++- t/lite_app_with_default_layouts.t | 37 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 t/lite_app_with_default_layouts.t diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index e3eb0f9..18de8d1 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -81,12 +81,16 @@ sub _render { $t = 'inline' if defined $inline; return unless $t; - my $helper = Mojolicious::Plugin::TtRenderer::Helper->new(ctx => $c); # Purge previous result $$output = ''; + # fixes for t/lite_app_with_default_layouts.t + unless ($c->stash->{layout}) { + $c->stash->{content} ||= $c->stash->{'mojo.content'}->{content}; + } + my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'}); my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]; $provider->options($options); diff --git a/t/lite_app_with_default_layouts.t b/t/lite_app_with_default_layouts.t new file mode 100644 index 0000000..c1be371 --- /dev/null +++ b/t/lite_app_with_default_layouts.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +BEGIN { $ENV{MOJO_MODE}='testing'; }; + +use utf8; + +use Test::More tests => 3; + +use Mojolicious::Lite; +use Mojo::ByteStream 'b'; +use Test::Mojo; +use File::Temp qw( tempdir ); + +# Silence +app->log->level('fatal'); + +use_ok('Mojolicious::Plugin::TtRenderer::Engine'); + +plugin 'tt_renderer' => {template_options => {PRE_CHOMP => 1, POST_CHOMP => 1, TRIM => 1, COMPILE_DIR => tempdir( CLEANUP => 1 ) }}; +app->defaults(layout => 'wrapper'); + +get '/test' => 'test'; + +my $t = Test::Mojo->new; + +$t->get_ok('/test')->content_is("WS-hello-EW"); + +__DATA__ + +@@ test.html.tt +hello + +@@ layouts/wrapper.html.tt +WS-[%- content -%]-EW