Skip to content

Commit

Permalink
improved template error messages for generator commands and config files
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 13, 2012
1 parent 815d10c commit fad6cbc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion 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
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Template.pm
Expand Up @@ -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([]);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Command.pm
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion lib/Mojolicious/Command/generate/lite_app.pm
Expand Up @@ -17,7 +17,6 @@ sub run {
__DATA__
@@ liteapp
% my $class = shift;
#!/usr/bin/env perl
use Mojolicious::Lite;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/JSONConfig.pm
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit fad6cbc

Please sign in to comment.