Skip to content

Instantly share code, notes, and snippets.

@vti
Created October 12, 2010 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vti/ed6966ddc8858449d211 to your computer and use it in GitHub Desktop.
Save vti/ed6966ddc8858449d211 to your computer and use it in GitHub Desktop.
diff --git a/lib/MojoX/Renderer.pm b/lib/MojoX/Renderer.pm
index 54bd7e8..38b0917 100644
--- a/lib/MojoX/Renderer.pm
+++ b/lib/MojoX/Renderer.pm
@@ -100,6 +100,9 @@ sub render {
# Template
my $template = delete $stash->{template};
+ # Template class
+ my $template_class = delete $stash->{template_class};
+
# Format
my $format = $stash->{format} || $self->default_format;
@@ -125,7 +128,7 @@ sub render {
handler => $handler,
encoding => $self->encoding,
inline => $inline,
- template_class => $stash->{template_class}
+ template_class => $template_class
};
my $output;
@@ -177,6 +180,10 @@ sub render {
# Extends
while ((my $extends = $self->_extends($c)) && !$json && !$data) {
+ # Template class
+ $template_class = $c->stash('template_class');
+ $options->{template_class} = $template_class;
+
# Handler
$handler = $c->stash->{handler};
$options->{handler} = $handler;
diff --git a/t/mojolicious/lite_app.t b/t/mojolicious/lite_app.t
index da605b0..7402cc1 100644
--- a/t/mojolicious/lite_app.t
+++ b/t/mojolicious/lite_app.t
@@ -14,7 +14,7 @@ use Test::More;
# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
-plan tests => 658;
+plan tests => 661;
# Pollution
123 =~ m/(\d+)/;
@@ -46,6 +46,10 @@ app->renderer->default_handler('epl');
# Header condition plugin
plugin 'header_condition';
+# Plugin with a template
+use lib 't/mojolicious';
+plugin 'PluginWithTemplate';
+
# Default
app->defaults(default => 23);
@@ -1598,6 +1602,8 @@ $t->get_ok('/captures/♥/☃')->status_is(200)
is b($t->tx->res->body)->url_unescape->decode('UTF-8'),
'/captures/♥/☃', 'right result';
+$t->get_ok('/plugin_with_template')->status_is(200)->content_is("layout_with_template\nwith template\n\n");
+
# Client timer
$client->ioloop->one_tick('0.1');
is $timer,
@@ -1719,6 +1725,10 @@ Default header!
Default footer!
<% end =%>
+@@ layouts/plugin_with_template.html.ep
+layout_with_template
+<%= content %>
+
@@ double_inheritance.html.ep
% extends 'template_inheritance';
<% content sidebar => begin =%>
package PluginWithTemplate;
use strict;
use warnings;
use base 'Mojolicious::Plugin';
sub register {
my ($self, $app) = @_;
$app->routes->route('/plugin_with_template')->to(
cb => sub {
my $self = shift;
$self->render(
'template',
template_class => __PACKAGE__,
layout => 'plugin_with_template'
);
}
);
}
1;
__DATA__
@@ template.html.ep
% stash template_class => 'main';
with template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment