Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0acdb2fcde | ||
|
|
dc52fec399 | ||
|
|
a896a311bb | ||
|
|
b6a0f10414 | ||
|
|
68747b7f2f | ||
|
|
323d5a9294 | ||
|
|
46715dc95e | ||
|
|
392b97e81a | ||
|
|
a5e276f633 | ||
|
|
fc453fe4fb | ||
|
|
32c83d6109 | ||
|
|
5e5c23d786 | ||
|
|
fa30565b6b |
@@ -1,6 +1,20 @@
|
|||||||
Revision history for MojoX-Renderer-TT
|
Revision history for MojoX-Renderer-TT
|
||||||
|
|
||||||
{{$NEXT}}
|
{{$NEXT}}
|
||||||
|
- 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)
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -8,6 +8,7 @@ use base 'Mojo::Base';
|
|||||||
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,14 +32,13 @@ 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} || {}},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -52,7 +52,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 +63,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 = MojoX::Renderer::TT::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);
|
||||||
@@ -152,6 +150,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) {
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/tmp/
|
||||||
|
*.ttc
|
||||||
+29
-6
@@ -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';
|
||||||
@@ -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
|
||||||
привет
|
привет
|
||||||
|
|
||||||
|
|||||||
@@ -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] %>
|
||||||
Reference in New Issue
Block a user