Skip to content

Commit

Permalink
link to Mojo::Template
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 7, 2016
1 parent cf16599 commit cb50ada
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 5 additions & 4 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -62,10 +62,11 @@ plugins, but more about that later.
=head2 Embedded Perl

L<Mojolicious> includes a minimalistic but very powerful template system out of
the box called Embedded Perl or C<ep> for short. It allows the embedding of
Perl code right into actual content using a small set of special tags and line
start characters. For all templates L<strict>, L<warnings>, L<utf8> and Perl
5.10 L<features|feature> are automatically enabled.
the box called Embedded Perl or C<ep> for short. It is based on
L<Mojo::Template> and allows the embedding of Perl code right into actual
content using a small set of special tags and line start characters. For all
templates L<strict>, L<warnings>, L<utf8> and Perl 5.10 L<features|feature> are
automatically enabled.

<% Perl code %>
<%= Perl expression, replaced with XML escaped result %>
Expand Down
13 changes: 6 additions & 7 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -10,12 +10,12 @@ sub register {
my ($self, $app, $conf) = @_;

# Auto escape by default to prevent XSS attacks
my $dialect = {auto_escape => 1, %{$conf->{template} || {}}, vars => 1};
my $ns = $self->{namespace} = $dialect->{namespace}
my $ep = {auto_escape => 1, %{$conf->{template} || {}}, vars => 1};
my $ns = $self->{namespace} = $ep->{namespace}
//= 'Mojo::Template::Sandbox::' . md5_sum "$self";
# Make "$self" and "$c" available in templates
$dialect->{prepend} = 'my $self = my $c = _C;' . ($dialect->{prepend} // '');
$ep->{prepend} = 'my $self = my $c = _C;' . ($ep->{prepend} // '');

# Add "ep" handler and make it the default
$app->renderer->default_handler('ep')->add_handler(
Expand All @@ -28,7 +28,7 @@ sub register {

my $cache = $renderer->cache;
my $mt = $cache->get($key);
$cache->set($key => $mt = Mojo::Template->new($dialect)) unless $mt;
$cache->set($key => $mt = Mojo::Template->new($ep)) unless $mt;

# Export helpers only once
++$self->{helpers} and _helpers($ns, $renderer->helpers)
Expand Down Expand Up @@ -74,9 +74,8 @@ Mojolicious::Plugin::EPRenderer - Embedded Perl renderer plugin
=head1 DESCRIPTION
L<Mojolicious::Plugin::EPRenderer> is a renderer for C<ep> or C<Embedded Perl>
templates. For more information see
L<Mojolicious::Guides::Rendering/"Embedded Perl">.
L<Mojolicious::Plugin::EPRenderer> is a renderer for Embedded Perl templates.
For more information see L<Mojolicious::Guides::Rendering/"Embedded Perl">.
This is a core plugin, that means it is always enabled and its code a good
example for learning to build new plugins, you're welcome to fork it.
Expand Down

0 comments on commit cb50ada

Please sign in to comment.