Skip to content

Commit

Permalink
fixed layouts with partial templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 2, 2009
1 parent 9244982 commit c0d708e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -25,6 +25,7 @@ This file documents the revision history for Perl extension Mojo.
- Fixed param to be CGI.pm compatible.
- Fixed a few cases where exceptions and not found events would
result in empty pages.
- Fixed layouts with partial templates.
- Fixed encoding of non utf8 form data.
- Fixed body callbacks to get automatic buffering.
- Fixed a case where Mojo::Server::Daemon and Mojo::Client were too
Expand Down
19 changes: 15 additions & 4 deletions lib/MojoX/Renderer.pm
Expand Up @@ -77,15 +77,25 @@ sub render {

# Text
if ($c->stash->{text}) {

# Render
$self->handler->{text}->($self, $c, \$output);
$c->stash->{inner_template} = $output if $c->stash->{layout};

# Layout?
$c->stash->{inner_template} = $output
if $c->stash->{layout} && !$partial;
}

# JSON
elsif ($c->stash->{json}) {

# Render
$self->handler->{json}->($self, $c, \$output);
$format = 'json';
$c->stash->{inner_template} = $output if $c->stash->{layout};

# Layout?
$c->stash->{inner_template} = $output
if $c->stash->{layout} && !$partial;
}

# Template or templateless handler
Expand All @@ -95,11 +105,12 @@ sub render {
return unless $self->_render_template($c, \$output, $options);

# Layout?
$c->stash->{inner_template} = $output if $c->stash->{layout};
$c->stash->{inner_template} = $output
if $c->stash->{layout} && !$partial;
}

# Layout
if (my $layout = delete $c->stash->{layout}) {
if (!$partial && (my $layout = delete $c->stash->{layout})) {

# Handler
$handler = $c->stash->{handler} || $self->default_handler;
Expand Down
30 changes: 29 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -7,7 +7,7 @@ use warnings;

use utf8;

use Test::More tests => 94;
use Test::More tests => 98;

# Wait you're the only friend I have...
# You really want a robot for a friend?
Expand All @@ -26,6 +26,16 @@ app->log->level('error');
# Test with lite templates
app->renderer->default_handler('epl');

# GET /outerlayout
get '/outerlayout' => sub {
my $self = shift;
$self->render(
template => 'outerlayout',
layout => 'layout',
handler => 'ep'
);
};

# GET /foo
get '/foo' => sub {
my $self = shift;
Expand Down Expand Up @@ -97,6 +107,17 @@ get '/eperror' => sub { shift->render(handler => 'ep') } => 'eperror';
my $app = Mojolicious::Lite->new;
my $client = Mojo::Client->new(app => $app);

# GET /outerlayout
$client->get(
'/outerlayout' => sub {
my ($self, $tx) = @_;
is($tx->res->code, 200);
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->body, "layouted Hello\nthere!\n\n\n");
}
)->process;

# GET /foo
$client->get(
'/foo' => sub {
Expand Down Expand Up @@ -366,6 +387,13 @@ $client->get(
$app->log->level($level);

__DATA__
@@ outerlayout.html.ep
Hello
<%== $self->render_partial('outermenu') %>
@@ outermenu.html.ep
there!
@@ not_found.html.epl
Oops!
Expand Down

0 comments on commit c0d708e

Please sign in to comment.