Compare commits

...

9 Commits

Author SHA1 Message Date
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
5 changed files with 34 additions and 16 deletions

11
Changes
View File

@@ -1,6 +1,17 @@
Revision history for MojoX-Renderer-TT
{{$NEXT}}
- 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)

View File

@@ -6,7 +6,7 @@ copyright_holder = Ask Bjørn Hansen
# copyright_year = 2009
[Prereqs]
Mojolicious = 1.01
Mojolicious = 1.3
Template = 2.18
[Prereqs / TestRequires ]

View File

@@ -8,6 +8,7 @@ use base 'Mojo::Base';
use File::Spec ();
use Mojo::ByteStream 'b';
use Template ();
use Cwd qw/abs_path/;
__PACKAGE__->attr('tt');
@@ -31,14 +32,13 @@ sub _init {
# take and process options :-)
my %config = (
($app ? (INCLUDE_PATH => $app->home->rel_dir('templates')) : ()),
($app ? (INCLUDE_PATH => abs_path($app->home->rel_dir('templates'))) : ()),
COMPILE_EXT => '.ttc',
COMPILE_DIR => ($dir || File::Spec->tmpdir),
COMPILE_DIR => ($dir || abs_path(File::Spec->tmpdir)),
UNICODE => 1,
ENCODING => 'utf-8',
CACHE_SIZE => 128,
RELATIVE => 1,
ABSOLUTE => 1,
%{$args{template_options} || {}},
);
@@ -52,7 +52,6 @@ sub _init {
return $self;
}
use Data::Dumper;
sub _render {
my ($self, $renderer, $c, $output, $options) = @_;
@@ -64,10 +63,6 @@ sub _render {
$t = 'inline' if defined $inline;
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);
@@ -77,14 +72,14 @@ sub _render {
my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'});
$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
unless ($ok) {
my $e = Mojo::Exception->new(
$self->tt->error.'',
$self->tt->service->process(defined $inline ? \$inline : $path));
$self->tt->service->process(defined $inline ? \$inline : $t));
$$output = '';
$c->app->log->error(qq/Template error in "$t": $e/);
$c->render_exception($e);
@@ -155,14 +150,16 @@ sub _template_content {
my $self = shift;
my ($path) = @_;
my ($t) = ($path =~ m{templates[\/|\\](.*)$});
# Convert backslashes to forward slashes to make inline templates work on Windows
$path =~ s/\\/\//g;
my ($t) = ($path =~ m{templates\/(.*)$});
if (-r $path) {
return $self->SUPER::_template_content(@_);
}
# 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;
}

View File

@@ -3,6 +3,8 @@
use strict;
use warnings;
BEGIN { $ENV{MOJO_MODE}='testing'; };
use utf8;
use Test::More tests => 31;
@@ -45,7 +47,7 @@ get '/inline' => sub { shift->render(inline => '[% 1 + 1 %]', handler => 'tt') }
my $t = Test::Mojo->new;
# 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
$t->get_ok('/bar/hello')->content_is("hello");
@@ -92,13 +94,13 @@ __DATA__
@@ include.inc
Hello
@@ includes/include.inc
@@ includes/sub/include.inc
Hallo
@@ include.html.tt
[%- INCLUDE 'include.inc' -%]
Include!
[% INCLUDE 'includes/include.inc' -%]
[% INCLUDE 'includes/sub/include.inc' -%]
@@ layouts/layout.html.tt
w[%- content -%]d

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] %>