Compare commits

...
Author SHA1 Message Date
Graham Ollis 20d795cb51 Compatibility with mojo 3.33 2012-08-23 22:20:08 -04:00
Graham Ollis 7455ae1be8 v1.23 2012-08-23 15:27:07 -04:00
Graham Ollis 870d195761 use die instead of render_exception 2012-08-23 15:26:38 -04:00
3 changed files with 30 additions and 22 deletions
+6
View File
@@ -1,6 +1,12 @@
Revision history for Mojolicious::Plugin::TtRenderer Revision history for Mojolicious::Plugin::TtRenderer
{{$NEXT}} {{$NEXT}}
- Compatibility with Mojolicious 3.33+
1.23 August 23, 2012
- Use die instead of render_exception (GH#29)
1.22 August 21, 2012
- Compatibility with Mojolicious 3.05+ (GH#24) - Compatibility with Mojolicious 3.05+ (GH#24)
- Avoid deep recursion when exception template dies (GH#25,GH26) - Avoid deep recursion when exception template dies (GH#25,GH26)
- Fixed test failures (GH#27,GH#28) - Fixed test failures (GH#27,GH#28)
+1 -2
View File
@@ -6,7 +6,7 @@ copyright_holder = Ask Bjørn Hansen
# copyright_year = 2009 # copyright_year = 2009
[Prereqs] [Prereqs]
Mojolicious = 2.51 Mojolicious = 3.33
Template = 2.18 Template = 2.18
[Prereqs / TestRequires ] [Prereqs / TestRequires ]
@@ -39,7 +39,6 @@ version_regexp = ^release/(.*)
[HasVersionTests] [HasVersionTests]
[MetaTests] [MetaTests]
[ReadmeFromPod] [ReadmeFromPod]
[PodCoverageTests]
[Manifest] [Manifest]
[NextRelease] [NextRelease]
+23 -20
View File
@@ -82,27 +82,14 @@ sub _render {
$$output = ''; $$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); my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0];
$provider->options($options);
$provider->ctx($c);
my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params); my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params);
# Error # Error
unless ($ok) { die $self->tt->error unless $ok;
state $rendering_exception;
my $e = Mojo::Exception->new($self->tt->error.'');
$$output = '';
$c->app->log->error(qq/Template error in "$t": $e/);
unless($rendering_exception)
{
$rendering_exception = 1;
$c->render_exception($e);
$rendering_exception = 0;
$self->tt->error('');
}
}
return 1; return 1;
} }
@@ -162,6 +149,7 @@ sub new {
sub renderer { @_ > 1 ? $_[0]->{renderer} = $_[1] : $_[0]->{renderer} } sub renderer { @_ > 1 ? $_[0]->{renderer} = $_[1] : $_[0]->{renderer} }
sub ctx { @_ > 1 ? $_[0]->{ctx} = $_[1] : $_[0]->{ctx} } sub ctx { @_ > 1 ? $_[0]->{ctx} = $_[1] : $_[0]->{ctx} }
sub options { @_ > 1 ? $_[0]->{options} = $_[1] : $_[0]->{options} }
sub _template_modified {1} sub _template_modified {1}
@@ -169,17 +157,32 @@ sub _template_content {
my $self = shift; my $self = shift;
my ($path) = @_; my ($path) = @_;
my $options = delete $self->{options};
# Convert backslashes to forward slashes to make inline templates work on Windows # Convert backslashes to forward slashes to make inline templates work on Windows
$path =~ s/\\/\//g; $path =~ s/\\/\//g;
my ($t) = ($path =~ m{templates\/(.*)$}); my ($t) = ($path =~ m{templates\/(.*)$});
if (-r $path) { if (-r $path) {
return $self->SUPER::_template_content(@_); return $self->SUPER::_template_content(@_);
} }
# Try DATA section # Try DATA section
elsif (my $d = $self->renderer->get_data_template($self->ctx, $t)) { if(defined $options)
return wantarray ? ($d, '', time) : $d; {
my $d = $self->renderer->get_data_template($options);
return wantarray ? ($d, '', time) : $d
if $d;
}
else
{
my $loader = Mojo::Loader->new;
foreach my $class (@{ $self->renderer->classes })
{
my $d = $loader->data($class, $t);
return wantarray ? ($d, '', time) : $d
if $d;
}
} }
my $data = ''; my $data = '';