Merge pull request #34 from rkitover/master
fix reporting not found templates
This commit is contained in:
commit
d4902f8bf0
2 files changed
+55
-3
No files matched your search
@@ -12,6 +12,7 @@ use Mojo::ByteStream 'b';
|
|||||||
use Template ();
|
use Template ();
|
||||||
use Cwd qw/abs_path/;
|
use Cwd qw/abs_path/;
|
||||||
use Scalar::Util 'weaken';
|
use Scalar::Util 'weaken';
|
||||||
|
use POSIX ':errno_h';
|
||||||
|
|
||||||
__PACKAGE__->attr('tt');
|
__PACKAGE__->attr('tt');
|
||||||
|
|
||||||
@@ -87,11 +88,26 @@ sub _render {
|
|||||||
my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0];
|
my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0];
|
||||||
$provider->options($options);
|
$provider->options($options);
|
||||||
$provider->ctx($c);
|
$provider->ctx($c);
|
||||||
$provider->not_found(0);
|
|
||||||
|
|
||||||
my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params);
|
my $ok = do {
|
||||||
|
if (defined $inline) {
|
||||||
|
$self->tt->process(\$inline, @params);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my @ret = $provider->fetch($t);
|
||||||
|
|
||||||
return 0 if $provider->not_found;
|
if (not defined $ret[1]) {
|
||||||
|
$self->tt->process($ret[0], @params);
|
||||||
|
}
|
||||||
|
elsif (not defined $ret[0]) { # not found
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else { # error
|
||||||
|
return 0 if $! == ENOENT && (not ref $ret[0]); # not found when not blessed exception
|
||||||
|
die $ret[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
# Error
|
# Error
|
||||||
die $self->tt->error unless $ok;
|
die $self->tt->error unless $ok;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Test::More tests => 3;
|
||||||
|
use Test::Mojo;
|
||||||
|
use File::Temp qw( tempdir );
|
||||||
|
use FindBin '$Bin';
|
||||||
|
|
||||||
|
use Mojolicious::Lite;
|
||||||
|
use Mojolicious::Plugin::TtRenderer::Engine ();
|
||||||
|
|
||||||
|
my $tt = Mojolicious::Plugin::TtRenderer::Engine->build(
|
||||||
|
mojo => app,
|
||||||
|
template_options => {
|
||||||
|
UNICODE => 1,
|
||||||
|
ENCODING => 'UTF-8',
|
||||||
|
INCLUDE_PATH => "$Bin/templates",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
app->renderer->add_handler(tt => $tt);
|
||||||
|
app->renderer->default_handler('tt');
|
||||||
|
|
||||||
|
get '/' => sub {
|
||||||
|
die 'foo';
|
||||||
|
};
|
||||||
|
|
||||||
|
my $t = Test::Mojo->new;
|
||||||
|
|
||||||
|
$t->get_ok('/')
|
||||||
|
->status_is(500)
|
||||||
|
->content_like(qr{foo});
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
|
||||||
|
@@ index.html.tt
|
||||||
|
anything
|
||||||
Reference in new issue
Block a user