Skip to content

Commit

Permalink
Made Mojolicious' layouts workable
Browse files Browse the repository at this point in the history
  • Loading branch information
vti committed Oct 9, 2010
1 parent 2017749 commit 0835702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/MojoX/Renderer/TT.pm
Expand Up @@ -73,7 +73,10 @@ sub _render {
my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'});
$self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->ctx($c);

my $in_layout = $$output ? 0 : 1;
$$output = '';

This comment has been minimized.

Copy link
@abh

abh Oct 9, 2010

Is this unconditional resetting of $$output here really right?

This comment has been minimized.

Copy link
@mvuets

mvuets Oct 9, 2010

TT appends its product to $$output and this duplicates final result. Shouldn't be a problem; at least ep renderer just overrides $$output.

my $ok = $self->tt->process(defined $inline ? \$inline : $path, @params);
$c->stash->{content} = $$output if $in_layout;

This comment has been minimized.

Copy link
@mvuets

mvuets Oct 9, 2010

Overriding 'content' will mess up TT's WRAPPER content and Mojolicious content helper. I propose to remove this line.
Here is my solution and additional tests for 'extends': mvuets/mojox-renderer-tt@395e9e6863dd9c7d21b87970ebf61a52d0a2f265 Request a pull?

This comment has been minimized.

Copy link
@vti

vti Oct 10, 2010

Owner

How if there are tests with WRAPPER and they pass?


# Error
unless ($ok) {
Expand Down
6 changes: 3 additions & 3 deletions t/lite_app.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use utf8;

use Test::More tests => 25;
use Test::More tests => 27;

use Mojolicious::Lite;
use Mojo::ByteStream 'b';
Expand All @@ -24,7 +24,7 @@ get '/with_include' => 'include';

get '/with_wrapper' => 'wrapper';

#get '/with_auto_wrapper' => sub { shift->render(auto_wrapper => layout => 'layout') };
get '/with_auto_wrapper' => sub { shift->render(auto_wrapper => layout => 'layout') };

get '/unicode' => 'unicode';

Expand Down Expand Up @@ -53,7 +53,7 @@ $t->get_ok('/with_include')->content_is("HelloInclude!Hallo");
$t->get_ok('/with_wrapper')->content_is("wrapped");

# With auto wrapper
#$t->get_ok('/with_auto_wrapper')->content_is("wrapped");
$t->get_ok('/with_auto_wrapper')->content_is("wrapped");

# Unicode
$t->get_ok('/unicode')->content_is(b("привет")->encode('UTF-8')->to_string);
Expand Down

0 comments on commit 0835702

Please sign in to comment.