Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved template error messages for generator commands and config files

  • Loading branch information...
commit fad6cbc4d2e3934a29aaa4cd21202650bcfedc7d 1 parent 815d10c
@kraih authored
View
3  Changes
@@ -1,5 +1,6 @@
-3.07 2012-07-12
+3.07 2012-07-13
+ - Improved template error messages for generator commands and config files.
- Improved documentation.
- Improved tests.
- Fixed small bug in Mojolicious::Plugin::EPRenderer that prevented code to
View
4 lib/Mojo/Template.pm
@@ -106,13 +106,13 @@ sub build {
}
}
- # Closure
+ # Wrap lines
my $first = $lines[0] ||= '';
$lines[0] = 'package ' . $self->namespace . "; $HELPERS ";
$lines[0] .= "sub { my \$_M = ''; " . $self->prepend . "; do { $first";
$lines[-1] .= $self->append . "; \$_M; } };";
- warn "-- Compiled (@{[$self->name]})\n", join("\n", @lines), "\n\n" if DEBUG;
+ warn "-- Code (@{[$self->name]})\n", join("\n", @lines), "\n\n" if DEBUG;
return $self->code(join "\n", @lines)->tree([]);
}
View
5 lib/Mojolicious/Command.pm
@@ -60,8 +60,9 @@ sub rel_dir { catdir(getcwd(), split /\//, pop) }
sub rel_file { catfile(getcwd(), split /\//, pop) }
sub render_data {
- my $self = shift;
- Mojo::Template->new->render(Mojo::Loader->new->data(ref $self, shift), @_);
+ my ($self, $name) = (shift, shift);
+ Mojo::Template->new->name(qq{template "$name" from DATA section})
+ ->render(Mojo::Loader->new->data(ref $self, $name), @_);
}
sub render_to_file {
View
1  lib/Mojolicious/Command/generate/lite_app.pm
@@ -17,7 +17,6 @@ sub run {
__DATA__
@@ liteapp
-% my $class = shift;
#!/usr/bin/env perl
use Mojolicious::Lite;
View
2  lib/Mojolicious/Plugin/JSONConfig.pm
@@ -33,7 +33,7 @@ sub render {
$prepend .= q[sub app; *app = sub { $app }; use Mojo::Base -strict;];
# Render
- my $mt = Mojo::Template->new($conf->{template} || {});
+ my $mt = Mojo::Template->new($conf->{template} || {})->name($file);
my $json = $mt->prepend($prepend . $mt->prepend)->render($content, $app);
return ref $json ? die($json) : encode('UTF-8', $json);
}
View
5 t/mojolicious/twinkle_lite_app.t
@@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
-use Test::More tests => 31;
+use Test::More tests => 32;
# "Pizza delivery for...
# I. C. Weiner. Aww... I always thought by this stage in my life I'd be the
@@ -46,12 +46,13 @@ my $config = plugin JSONConfig => {
ext => 'conf',
template => {
%$twinkle,
- append => '',
+ append => '$app->defaults(foo_test => 24)',
prepend => 'my $foo = app->defaults("foo_test");'
}
};
is $config->{foo}, 'bar', 'right value';
is $config->{test}, 23, 'right value';
+is app->defaults('foo_test'), 24, 'right value';
# GET /
get '/' => {name => '<sebastian>'} => 'index';
Please sign in to comment.
Something went wrong with that request. Please try again.