Navigation Menu

Skip to content

Commit

Permalink
improved template inheritance by ignoring whitespace-only content
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 2, 2011
1 parent 98cd58b commit 03f9ed4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Mojolicious.

2.22 2011-11-02 00:00:00
- Added EXPERIMENTAL --verbose flag to routes command.
- Improved template inheritance by ignoring whitespace-only content.
- Fixed a few template inheritance bugs. (ruz)

2.21 2011-11-02 00:00:00
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -142,7 +142,7 @@ sub render {
$options->{format} = $stash->{format} || $self->default_format;
$options->{template} = $extends;
$self->_render_template($c, \$output, $options);
$content->{content} = b($output);
$content->{content} = b($output) if $output =~ /\S/;
}

# Encoding (JSON is already encoded)
Expand Down
35 changes: 34 additions & 1 deletion t/mojolicious/layouted_lite_app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 87;
use Test::More tests => 97;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -110,6 +110,12 @@ get '/content_for';
# GET /layout_inheritance
get '/layout_inheritance';

# GET /partial_inheritance
get '/partial_inheritance';

# GET /unknown_layout
get '/unknown_layout';

my $t = Test::Mojo->new;

# GET /works
Expand Down Expand Up @@ -223,6 +229,18 @@ $t->get_ok('/layout_inheritance')->status_is(200)
->content_is(
"Title: Welcome\nBase: Specific: Welcome to Mojolicious!\n\n\n");

# GET /partial_inheritance
$t->get_ok('/partial_inheritance')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("HeaderLast template.\n\n");

# GET /unknown_layout
$t->get_ok('/unknown_layout')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("This layout does not exist.\n");

__DATA__
@@ layouts/default.html.ep
Default<%= title %><%= content %>
Expand Down Expand Up @@ -353,3 +371,18 @@ Specific: <%= content %>
% layout 'specific';
% title 'Welcome';
Welcome to Mojolicious!
@@ blocks_and_content.html.ep
<%= content 'header' %><%= content %>
@@ just_blocks.html.ep
% extends 'blocks_and_content';
<% content header => begin %>Header<% end %>
@@ partial_inheritance.html.ep
% extends 'just_blocks';
Last template.
@@ unknown_layout.html.ep
% layout 'does_not_exist';
This layout does not exist.

0 comments on commit 03f9ed4

Please sign in to comment.