Update to work with named parameters in new version of Mojo

Instead of "tx" pass the context in the "c" variable
This commit is contained in:
Ask Bjørn Hansen
2008-11-12 00:06:20 -08:00
parent 44f5312fef
commit 8402f4f597
3 changed files with 13 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
Revision history for MojoX-Renderer-TT
0.03
- Update to work with named parameters in new version of Mojo
- Instead of "tx" pass the context in the "c" variable
- Rename "new" to "build"
- Add real tests (Viacheslav Tikhanovskii)
- Update to work with new error handling in Mojo

View File

@@ -48,17 +48,22 @@ sub _init {
}
sub _render {
my ($self, $mojo, $path, $output, $tx, $args) = @_;
my ($self, $mojo, $args) = @_;
$args ||= {};
$args->{args} ||= {};
#use Data::Dump qw(dump);
#warn dump(\$args);
unless ($self->tt->process($path, {%$args, tx => $tx}, $output, {binmode => ":utf8"})) {
unless ($self->tt->process($args->{path},
{%{$args->{args}},
c => $args->{c}},
$args->{output},
{binmode => ":utf8"})) {
Carp::carp $self->tt->error . "\n";
return 0;
} else {
}
else {
return 1;
}
}
@@ -130,7 +135,6 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
* Better support non-Mojolicious frameworks
* Don't require the mojo parameter
* Move the default template cache directory?
* Should the "tx" tpl parameter be called "c" (for context) instead?
* Better way to pass parameters to the templates? (stash)
* More sophisticated default search path?

View File

@@ -14,10 +14,10 @@ my $mt = MojoX::Renderer::TT->build;
my $output;
my $rv;
$rv = $mt->(undef, 't/render/template.tt2', \$output);
$rv = $mt->(undef, { path => 't/render/template.tt2', output => \$output });
is($rv, 1);
is($output, "4\n");
$rv = $mt->(undef, 't/render/template-error.tt2', \$output);
$rv = $mt->(undef, { path => 't/render/template-error.tt2', output => \$output });
is($rv, 0);
ok($output);