Skip to content

Commit

Permalink
fixed small bug in Mojolicious::Plugin::JSONConfig that prevented cod…
Browse files Browse the repository at this point in the history
…e to be added to config files
  • Loading branch information
kraih committed Jul 12, 2012
1 parent 823efd7 commit 35ff80a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Changes
Expand Up @@ -3,7 +3,9 @@
- Improved documentation.
- Improved tests.
- Fixed small bug in Mojolicious::Plugin::EPRenderer that prevented code to
be added to all templates.
be added to templates.
- Fixed small bug in Mojolicious::Plugin::JSONConfig that prevented code to
be added to config files.

3.06 2012-07-11
- Added tls_verify option to Mojo::IOLoop::Server->listen. (scottw)
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/JSONConfig.pm
Expand Up @@ -34,7 +34,7 @@ sub render {

# Render
my $mt = Mojo::Template->new($conf->{template} || {});
my $json = $mt->prepend($prepend)->render($content, $app);
my $json = $mt->prepend($prepend . $mt->prepend)->render($content, $app);
return ref $json ? die($json) : encode('UTF-8', $json);
}

Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/twinkle_lite_app.conf
@@ -1,4 +1,4 @@
. my $foo = 23;
. my $bar = $foo;
{
"test": *** $foo **
"test": *** $bar **
}
23 changes: 17 additions & 6 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 29;
use Test::More tests => 31;

# "Pizza delivery for...
# I. C. Weiner. Aww... I always thought by this stage in my life I'd be the
Expand All @@ -19,6 +19,7 @@ app->renderer->default_format('foo');

# Twinkle template syntax
my $twinkle = {
append => '$self->res->headers->header("X-Append" => $prepended);',
auto_escape => 0,
capture_end => '-',
capture_start => '+',
Expand All @@ -32,13 +33,23 @@ my $twinkle = {
trim_mark => '*'
};

# Plugins
# Renderer
plugin EPRenderer => {name => 'twinkle', template => $twinkle};
plugin PODRenderer => {no_perldoc => 1};
plugin PODRenderer =>
{name => 'teapod', preprocess => 'twinkle', no_perldoc => 1};
my $config = plugin JSONConfig =>
{default => {foo => 'bar'}, ext => 'conf', template => $twinkle};

# Configuration
app->defaults(foo_test => 23);
my $config = plugin JSONConfig => {
default => {foo => 'bar'},
ext => 'conf',
template => {
%$twinkle,
append => '',
prepend => 'my $foo = app->defaults("foo_test");'
}
};
is $config->{foo}, 'bar', 'right value';
is $config->{test}, 23, 'right value';

Expand Down Expand Up @@ -71,11 +82,11 @@ get '/dead' => sub {die};
my $t = Test::Mojo->new;

# GET /
$t->get_ok('/')->status_is(200)
$t->get_ok('/')->status_is(200)->header_is('X-Append' => 'bar')
->content_like(qr/testHello <sebastian>!bar TwinkleSandBoxTest123/);

# GET /advanced
$t->get_ok('/advanced')->status_is(200)
$t->get_ok('/advanced')->status_is(200)->header_is('X-Append' => 'bar')
->content_is("&lt;escape me&gt;\n123423");

# GET /docs
Expand Down

0 comments on commit 35ff80a

Please sign in to comment.