Compare commits

...
Author SHA1 Message Date
Ask Bjørn Hansen 9f20c780b8 Add Mojolicious-Plugin-TtRenderer-* to .gitignore 2011-08-01 09:35:17 -07:00
Ask Bjørn Hansen c7c249b51f Update distribution name 2011-08-01 09:34:46 -07:00
Cosimo Streppone dae8329981 [GH#12] Drop MojoX::* namespace
Renamed MojoX:: namespace to Mojolicious::Plugin::TtRenderer::Engine,
so there's ::Engine, ::Helper and ::Provider.

MojoX:: is deprecated and not to be used, according to @sri.
2011-08-01 11:56:25 +02:00
Ask Bjørn Hansen 5e650027c7 Mark 1.13 in Changes 2011-06-07 17:38:43 -07:00
Ask Bjørn Hansen 698fc48b58 Compatibility with Mojolicious 1.3+ 2011-06-07 17:38:10 -07:00
Ask Bjørn Hansen 49075ebe44 v1.12 2011-02-28 00:45:24 -08:00
Htbaa 0acdb2fcde Simplified regex and added comment why backslashes are being converted 2011-02-26 19:56:17 +01:00
Htbaa dc52fec399 Inline wrappers and includes now work on Windows
closes gh-13
2011-02-26 12:46:02 +01:00
Ask Bjørn Hansen a896a311bb Mark 1.11 in Changes 2011-02-06 16:00:58 -08:00
Ask Bjørn Hansen b6a0f10414 Update Changes 2011-02-06 15:59:56 -08:00
Ask Bjørn Hansen 68747b7f2f Merge remote branch 'marcusramberg/master' 2011-02-06 15:57:10 -08:00
Marcus Ramberg 323d5a9294 Change to use relative paths, add exception template for tests 2011-02-06 08:50:02 +01:00
Ask Bjørn Hansen 46715dc95e Mark 1.10 release in Changes 2011-02-05 12:25:48 -08:00
Ask Bjørn Hansen 392b97e81a Ignore .ttc files from tests 2011-02-05 12:22:44 -08:00
Ask Bjørn Hansen a5e276f633 Update Changes 2011-02-05 12:20:42 -08:00
Ask Bjørn Hansen fc453fe4fb Try fixing tests on Strawberry Perl (RT#65282)
(thanks Christiaan Kras)
2011-02-05 12:12:47 -08:00
Ask Bjørn Hansen 32c83d6109 Fix bugtracker URL in META.yml 2011-02-05 12:11:05 -08:00
Maxim Vuets 5e5c23d786 Make Mojolicious 'layout'/'extends' working 2011-02-05 10:02:09 -08:00
Ask Bjørn Hansen fa30565b6b 1.0 released 2011-01-22 17:14:48 -08:00
9 changed files with 99 additions and 42 deletions
+1
View File
@@ -6,6 +6,7 @@ _build*
pm_to_blib* pm_to_blib*
*.tar.gz *.tar.gz
.lwpcookies .lwpcookies
Mojolicious-Plugin-TtRenderer-*
MojoX-Renderer-TT-* MojoX-Renderer-TT-*
cover_db cover_db
*~ *~
+23
View File
@@ -1,6 +1,29 @@
Revision history for MojoX-Renderer-TT Revision history for MojoX-Renderer-TT
{{$NEXT}} {{$NEXT}}
1.14 August 1, 2011
- Drop use of MojoX namespace for Mojolicious::Plugin::TtRenderer::
(GH#12, Cosimo Streppone)
1.13 June 7, 2011
- Compatibility with Mojolicious 1.3+
1.12 February 28, 2011
- Inline wrappers and includes now work on Windows
(GH#13, Christiaan Kras)
1.11 February 6, 2011
- Change to use relative paths (Marcus Ramberg)
- Add exception template for tests
1.10 February 5, 2011
- Support Mojolicious 'layout'/'extends' (Maxim Vuets, Marcus
Ramberg)
- Fix Strawberry Perl tests (RT#65282, Christiaan Kras, Ask)
- Update bugtracker URL in META.yml
1.0 January 22, 2011
- Require (and be compatible with) Mojolicious 1.0+ - Require (and be compatible with) Mojolicious 1.0+
- Added inline template support (Viacheslav Tykhanovskyi & Ask) - Added inline template support (Viacheslav Tykhanovskyi & Ask)
- Fix inline rendering and test failures (Marcus Ramberg) - Fix inline rendering and test failures (Marcus Ramberg)
+7 -8
View File
@@ -1,4 +1,4 @@
name = MojoX-Renderer-TT name = Mojolicious-Plugin-TtRenderer
author = Ask Bjørn Hansen <ask@develooper.com> author = Ask Bjørn Hansen <ask@develooper.com>
license = Perl_5 license = Perl_5
@@ -6,7 +6,7 @@ copyright_holder = Ask Bjørn Hansen
# copyright_year = 2009 # copyright_year = 2009
[Prereqs] [Prereqs]
Mojolicious = 1.01 Mojolicious = 1.3
Template = 2.18 Template = 2.18
[Prereqs / TestRequires ] [Prereqs / TestRequires ]
@@ -21,12 +21,11 @@ bundle = @Basic
remove = Readme remove = Readme
remove = Manifest remove = Manifest
[Repository] [MetaResources]
repository = git://github.com/abh/mojox-renderer-tt.git bugtracker.web = https://github.com/abh/mojox-renderer-tt/issues
web = https://github.com/abh/mojox-renderer-tt repository.web = http://github.com/abh/mojox-renderer-tt
repository.url = git://github.com/abh/mojox-renderer-tt.git
[Bugtracker] repository.type = git
web = https://github.com/abh/mojox-renderer-tt/issues
[Homepage] [Homepage]
+3 -3
View File
@@ -7,14 +7,14 @@ our $VERSION = '0.01';
use base 'Mojolicious::Plugin'; use base 'Mojolicious::Plugin';
use MojoX::Renderer::TT; use Mojolicious::Plugin::TtRenderer::Engine;
sub register { sub register {
my ($self, $app, $args) = @_; my ($self, $app, $args) = @_;
$args ||= {}; $args ||= {};
my $tt = MojoX::Renderer::TT->build(%$args, app => $app); my $tt = Mojolicious::Plugin::TtRenderer::Engine->build(%$args, app => $app);
# Add "tt" handler # Add "tt" handler
$app->renderer->add_handler(tt => $tt); $app->renderer->add_handler(tt => $tt);
@@ -54,6 +54,6 @@ Register renderer in L<Mojolicious> application.
=head1 SEE ALSO =head1 SEE ALSO
L<MojoX::Renderer::TT>, L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>. L<Mojolicious::Plugin::TtRenderer::Engine>, L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
=cut =cut
@@ -1,13 +1,15 @@
package MojoX::Renderer::TT; package Mojolicious::Plugin::TtRenderer::Engine;
use warnings; use warnings;
use strict; use strict;
use base 'Mojo::Base'; use base 'Mojo::Base';
use Carp ();
use File::Spec (); use File::Spec ();
use Mojo::ByteStream 'b'; use Mojo::ByteStream 'b';
use Template (); use Template ();
use Cwd qw/abs_path/;
__PACKAGE__->attr('tt'); __PACKAGE__->attr('tt');
@@ -31,19 +33,18 @@ sub _init {
# take and process options :-) # take and process options :-)
my %config = ( my %config = (
($app ? (INCLUDE_PATH => $app->home->rel_dir('templates')) : ()), ($app ? (INCLUDE_PATH => abs_path($app->home->rel_dir('templates'))) : ()),
COMPILE_EXT => '.ttc', COMPILE_EXT => '.ttc',
COMPILE_DIR => ($dir || File::Spec->tmpdir), COMPILE_DIR => ($dir || abs_path(File::Spec->tmpdir)),
UNICODE => 1, UNICODE => 1,
ENCODING => 'utf-8', ENCODING => 'utf-8',
CACHE_SIZE => 128, CACHE_SIZE => 128,
RELATIVE => 1, RELATIVE => 1,
ABSOLUTE => 1,
%{$args{template_options} || {}}, %{$args{template_options} || {}},
); );
$config{LOAD_TEMPLATES} = $config{LOAD_TEMPLATES} =
[MojoX::Renderer::TT::Provider->new(%config, renderer => $app->renderer)] [Mojolicious::Plugin::TtRenderer::Provider->new(%config, renderer => $app->renderer)]
unless $config{LOAD_TEMPLATES}; unless $config{LOAD_TEMPLATES};
$self->tt(Template->new(\%config)) $self->tt(Template->new(\%config))
@@ -52,7 +53,6 @@ sub _init {
return $self; return $self;
} }
use Data::Dumper;
sub _render { sub _render {
my ($self, $renderer, $c, $output, $options) = @_; my ($self, $renderer, $c, $output, $options) = @_;
@@ -64,24 +64,23 @@ sub _render {
$t = 'inline' if defined $inline; $t = 'inline' if defined $inline;
return unless $t; return unless $t;
# Path
my $path = $renderer->template_path($options);
$path = b($inline)->md5_sum->to_string if defined $inline;
return unless $path;
my $helper = MojoX::Renderer::TT::Helper->new(ctx => $c); my $helper = Mojolicious::Plugin::TtRenderer::Helper->new(ctx => $c);
# Purge previous result
$$output = '';
my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'}); my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'});
$self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->ctx($c); $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->ctx($c);
my $ok = $self->tt->process(defined $inline ? \$inline : $path, @params); my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params);
# Error # Error
unless ($ok) { unless ($ok) {
my $e = Mojo::Exception->new( my $e = Mojo::Exception->new(
$self->tt->error.'', $self->tt->error.'',
$self->tt->service->process(defined $inline ? \$inline : $path)); $self->tt->service->process(defined $inline ? \$inline : $t));
$$output = ''; $$output = '';
$c->app->log->error(qq/Template error in "$t": $e/); $c->app->log->error(qq/Template error in "$t": $e/);
$c->render_exception($e); $c->render_exception($e);
@@ -92,10 +91,10 @@ sub _render {
return 1; return 1;
} }
1; # End of MojoX::Renderer::TT 1; # End of Mojolicious::Plugin::TtRenderer::Engine
package package
MojoX::Renderer::TT::Helper; Mojolicious::Plugin::TtRenderer::Helper;
use strict; use strict;
use warnings; use warnings;
@@ -125,7 +124,7 @@ sub AUTOLOAD {
1; 1;
package package
MojoX::Renderer::TT::Provider; Mojolicious::Plugin::TtRenderer::Provider;
use strict; use strict;
use warnings; use warnings;
@@ -152,6 +151,8 @@ sub _template_content {
my $self = shift; my $self = shift;
my ($path) = @_; my ($path) = @_;
# Convert backslashes to forward slashes to make inline templates work on Windows
$path =~ s/\\/\//g;
my ($t) = ($path =~ m{templates\/(.*)$}); my ($t) = ($path =~ m{templates\/(.*)$});
if (-r $path) { if (-r $path) {
@@ -159,7 +160,7 @@ sub _template_content {
} }
# Try DATA section # Try DATA section
elsif (my $d = $self->renderer->get_inline_template($self->ctx, $t)) { elsif (my $d = $self->renderer->get_data_template($self->ctx, $t)) {
return wantarray ? ($d, '', time) : $d; return wantarray ? ($d, '', time) : $d;
} }
@@ -177,7 +178,7 @@ __END__
=head1 NAME =head1 NAME
MojoX::Renderer::TT - Template Toolkit renderer for Mojo Mojolicious::Plugin::TtRenderer::Engine - Template Toolkit renderer for Mojo
=head1 SYNOPSIS =head1 SYNOPSIS
@@ -190,9 +191,9 @@ Add the handler:
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}}); $self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
# Or manually # Or manually
use MojoX::Renderer::TT; use Mojolicious::Plugin::TtRenderer::Engine;
my $tt = MojoX::Renderer::TT->build( my $tt = Mojolicious::Plugin::TtRenderer::Engine->build(
mojo => $self, mojo => $self,
template_options => { template_options => {
PROCESS => 'tpl/wrapper', PROCESS => 'tpl/wrapper',
@@ -240,7 +241,7 @@ Supported parameters are
=item mojo =item mojo
C<build> currently uses a C<mojo> parameter pointing to the base class (Mojo). C<build> currently uses a C<mojo> parameter pointing to the base class (Mojo).
object. When used the INCLUDE_PATH will be set to object. When used the INCLUDE_PATH will be set to
=item template_options =item template_options
@@ -271,7 +272,7 @@ make changes.
You can find documentation for this module with the perldoc command. You can find documentation for this module with the perldoc command.
perldoc MojoX::Renderer::TT perldoc Mojolicious::Plugin::TtRenderer::Engine
You can also look for information at: You can also look for information at:
+2
View File
@@ -0,0 +1,2 @@
/tmp/
*.ttc
+2 -2
View File
@@ -3,7 +3,7 @@
use Test::More tests => 1; use Test::More tests => 1;
BEGIN { BEGIN {
use_ok( 'MojoX::Renderer::TT' ); use_ok( 'Mojolicious::Plugin::TtRenderer::Engine' );
} }
diag( "Testing MojoX::Renderer::TT $MojoX::Renderer::TT::VERSION, Perl $], $^X" ); diag( "Testing Mojolicious::Plugin::TtRenderer::Engine $Mojolicious::Plugin::TtRenderer::Engine::VERSION, Perl $], $^X" );
+30 -7
View File
@@ -3,9 +3,11 @@
use strict; use strict;
use warnings; use warnings;
BEGIN { $ENV{MOJO_MODE}='testing'; };
use utf8; use utf8;
use Test::More tests => 25; use Test::More tests => 31;
use Mojolicious::Lite; use Mojolicious::Lite;
use Mojo::ByteStream 'b'; use Mojo::ByteStream 'b';
@@ -14,7 +16,7 @@ use Test::Mojo;
# Silence # Silence
app->log->level('fatal'); app->log->level('fatal');
use_ok('MojoX::Renderer::TT'); use_ok('Mojolicious::Plugin::TtRenderer::Engine');
plugin 'tt_renderer' => {template_options => {PRE_CHOMP => 1, POST_CHOMP => 1, TRIM => 1}}; plugin 'tt_renderer' => {template_options => {PRE_CHOMP => 1, POST_CHOMP => 1, TRIM => 1}};
@@ -24,7 +26,11 @@ get '/with_include' => 'include';
get '/with_wrapper' => 'wrapper'; get '/with_wrapper' => 'wrapper';
#get '/with_auto_wrapper' => sub { shift->render(auto_wrapper => layout => 'layout') }; get '/with_auto_wrapper' => 'auto_wrapper';
get '/inheritance_base' => 'inheritance_base';
get '/inheritance_derived' => 'inheritance_derived';
get '/unicode' => 'unicode'; get '/unicode' => 'unicode';
@@ -41,7 +47,7 @@ get '/inline' => sub { shift->render(inline => '[% 1 + 1 %]', handler => 'tt') }
my $t = Test::Mojo->new; my $t = Test::Mojo->new;
# Exception # Exception
$t->get_ok('/exception')->status_is(500)->content_like(qr/error/i); $t->get_ok('/exception')->status_is(500)->content_like(qr/Exception/i);
# Normal rendering # Normal rendering
$t->get_ok('/bar/hello')->content_is("hello"); $t->get_ok('/bar/hello')->content_is("hello");
@@ -53,7 +59,11 @@ $t->get_ok('/with_include')->content_is("HelloInclude!Hallo");
$t->get_ok('/with_wrapper')->content_is("wrapped"); $t->get_ok('/with_wrapper')->content_is("wrapped");
# With auto wrapper # With auto wrapper
#$t->get_ok('/with_auto_wrapper')->content_is("wrapped"); $t->get_ok('/with_auto_wrapper')->content_is("wrapped");
# Inheritance
$t->get_ok('/inheritance_base')->content_is("untouched");
$t->get_ok('/inheritance_derived')->content_is("edited");
# Unicode # Unicode
$t->get_ok('/unicode')->content_is("привет"); $t->get_ok('/unicode')->content_is("привет");
@@ -84,13 +94,13 @@ __DATA__
@@ include.inc @@ include.inc
Hello Hello
@@ includes/include.inc @@ includes/sub/include.inc
Hallo Hallo
@@ include.html.tt @@ include.html.tt
[%- INCLUDE 'include.inc' -%] [%- INCLUDE 'include.inc' -%]
Include! Include!
[% INCLUDE 'includes/include.inc' -%] [% INCLUDE 'includes/sub/include.inc' -%]
@@ layouts/layout.html.tt @@ layouts/layout.html.tt
w[%- content -%]d w[%- content -%]d
@@ -100,9 +110,22 @@ w[%- content -%]d
rappe rappe
[%- END -%] [%- END -%]
@@ layouts/auto_layout.html.tt
w[%- h.content -%]d
@@ auto_wrapper.html.tt @@ auto_wrapper.html.tt
[% CALL h.layout('auto_layout') %]
rappe rappe
@@ inheritance_base.html.tt
[% verb = BLOCK %]untouch[% END %]
[% h.content('verb', verb) %]ed
@@ inheritance_derived.html.tt
[% CALL h.extends('inheritance_base') %]
[% verb = BLOCK %]edit[% END %]
[% h.content('verb', verb) %]
@@ unicode.html.tt @@ unicode.html.tt
привет привет
+8
View File
@@ -0,0 +1,8 @@
% my $s = $self->stash;
% my $e = $self->stash('exception');
% delete $s->{inner_template};
% delete $s->{exception};
% my $dump = dumper $s;
% $s->{exception} = $e;
An Exception has occured: <%= $e->message %>
at <%= $e->line->[0] %> in <%= $e->line->[1] %>