Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better example for custom template systems
  • Loading branch information
kraih committed Dec 27, 2012
1 parent cdbf89a commit 947e67f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.71 2012-12-26
3.71 2012-12-27
- Improved documentation.

3.70 2012-12-23
Expand Down
28 changes: 19 additions & 9 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -894,12 +894,16 @@ L<Mojo::Template> contains the whole list of available options.
=head2 Adding your favorite template system

Maybe you would prefer a different template system than C<ep>, all you have to
do is add a new C<handler>.
do is add a new C<handler> when C<register> is called.

use Mojolicious::Lite;
package Mojolicious::Plugin::MyRenderer;
use Mojo::Base 'Mojolicious::Plugin';

sub register {
my ($self, $app) = @_;

app->renderer->add_handler(
mine => sub {
# Add "mine" handler
$app->renderer->add_handler(mine => sub {
my ($renderer, $c, $output, $options) = @_;

# Check for one time use inline template
Expand All @@ -922,8 +926,17 @@ do is add a new C<handler>.

# And return true if something has been rendered or false otherwise
return 1;
}
);
});
}

1;

Since most template systems don't support templates in the C<DATA> section,
the renderer provides methods to help you with that.

use Mojolicious::Lite;

plugin 'MyRenderer';

get '/' => 'index';

Expand All @@ -933,9 +946,6 @@ do is add a new C<handler>.
@@ index.html.mine
...

Since most template systems don't support templates in the C<DATA> section,
the renderer provides methods to help you with that.

=head2 Post-processing content

While post-processing tasks are generally very easy with the C<after_dispatch>
Expand Down
16 changes: 7 additions & 9 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -746,17 +746,15 @@ You can also package your conditions as reusable plugins.
my ($self, $app) = @_;

# Add "werewolf" condition
$app->routes->add_condition(
werewolf => sub {
my ($route, $c, $captures, $days) = @_;
$app->routes->add_condition(werewolf => sub {
my ($route, $c, $captures, $days) = @_;

# Keep the werewolfs out!
return undef if abs(14 - (phase(time))[2]) > ($days / 2);
# Keep the werewolfs out!
return undef if abs(14 - (phase(time))[2]) > ($days / 2);

# It's ok, no werewolf
return 1;
}
);
# It's ok, no werewolf
return 1;
});
}

1;
Expand Down

0 comments on commit 947e67f

Please sign in to comment.