Skip to content

Commit

Permalink
Merge pull request #4 from garu/master
Browse files Browse the repository at this point in the history
updating dist to newer, back-incompat, mojolicious
  • Loading branch information
garu committed Aug 14, 2012
2 parents ff86c8b + 4170c8f commit 8edc871
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -37,7 +37,7 @@ WriteMakefile(

PREREQ_PM => {
'Text::Haml' => '0.990103',
'Mojolicious' => '0.999924'
'Mojolicious' => '1.13'
},

test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t t/*/*/*/*.t'}
Expand Down
22 changes: 9 additions & 13 deletions lib/MojoX/Renderer/Haml.pm
Expand Up @@ -31,6 +31,7 @@ sub _render {
unless ($path = $c->stash->{'template_path'}) {
$path = $r->template_path($options);
}
return unless defined $path;

my $list = join ', ', sort keys %{$c->stash};
my $cache = b("$path($list)")->md5_sum->to_string;
Expand All @@ -47,6 +48,7 @@ sub _render {
if ( $c->app->mode ne 'development' && $haml && $haml->compiled) {
$haml->helpers_arg($c);

$c->app->log->debug("Rendering cached $t.");
$$output = $haml->interpret(%args);
}

Expand All @@ -55,41 +57,35 @@ sub _render {
$haml ||= Text::Haml->new(escape => $ESCAPE);

$haml->helpers_arg($c);
$haml->helpers($r->helper);
$haml->helpers($r->helpers);

# Try template
if (-r $path) {
$c->app->log->debug("Rendering template '$t'.");
$$output = $haml->render_file($path, %args);
}

# Try DATA section
elsif (my $d = $r->get_inline_template($c, $t)) {
elsif (my $d = $r->get_data_template($c, $t)) {
$c->app->log->debug("Rendering template '$t' from DATA section.");
$$output = $haml->render($d, %args);
}

# No template
else {
$c->app->log->error(qq/Template "$t" missing or not readable./);
$c->render_not_found;
$c->app->log->debug(qq/Template "$t" missing or not readable./);
return;
}
}

unless (defined $$output) {
$$output = '';

my $e = Mojo::Exception->new($haml->error);

$c->app->log->error( qq/Template error in "$t": / . $haml->error);

$c->render_exception($e);

return 0;
die(qq/Template error in "$t": / . $haml->error);
}

$r->{_haml_cache}->{$cache} ||= $haml;

return 1;
return ref $$output ? die($$output) : 1;
}

1;
Expand Down
5 changes: 2 additions & 3 deletions t/lite_app.t
Expand Up @@ -6,7 +6,7 @@ use warnings;
use Test::More tests => 18;

use Test::Mojo;
use Mojo::Client;
use Mojo::UserAgent;
use Mojolicious::Lite;

# Silence
Expand All @@ -25,7 +25,6 @@ get '/error' => 'error';
get '/with_wrapper' => 'with_wrapper';

my $t = Test::Mojo->new;
$t->client(Mojo::Client->new);

# No cache
$t->get_ok('/')->status_is(200)->content_is("<foo>1 + 1 &lt; 2</foo>\n");
Expand All @@ -43,7 +42,7 @@ $t->get_ok('/with_wrapper')->status_is(200)->content_is("<foo>Hello!\n</foo>\n")
$t->get_ok('/foo')->status_is(404)->content_is("Not found\n");

# Error
$t->get_ok('/error')->status_is(500)->content_like(qr/^Exception:\nsyntax error/);
$t->get_ok('/error')->status_is(500)->content_like(qr/^Exception:.+syntax error/s);

1;
__DATA__
Expand Down

0 comments on commit 8edc871

Please sign in to comment.