Compare commits

...

10 Commits

Author SHA1 Message Date
Ask Bjørn Hansen
dc1c1570e1 Require Mojo 0.8011 (using named parameters) 2008-11-12 00:16:05 -08:00
Ask Bjørn Hansen
1bcae03e9c perltidy 2008-11-12 00:13:47 -08:00
Ask Bjørn Hansen
e0b5f09326 prepare v0.10 2008-11-12 00:07:20 -08:00
Ask Bjørn Hansen
8402f4f597 Update to work with named parameters in new version of Mojo
Instead of "tx" pass the context in the "c" variable
2008-11-12 00:06:20 -08:00
Ask Bjørn Hansen
44f5312fef Move the VERSION definition out of the pod section 2008-11-12 00:04:13 -08:00
Ask Bjørn Hansen
62146bb307 Rename "new" to "build"
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-12 00:04:09 -08:00
vti
68783f08e2 fixes due to new Mojo::Renderer error handling, tests
Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-11 23:53:28 -08:00
Ask Bjørn Hansen
9dce1eb021 Add note about the git repositories
Fix POD encoding

Signed-off-by: Ask Bjørn Hansen <ask@develooper.com>
2008-11-11 04:05:39 -08:00
Ask Bjørn Hansen
bf71ca8cec Accept options for the Template object
Prepare 0.02
2008-11-10 11:14:38 -08:00
Ask Bjørn Hansen
d6ac8a1c94 Template.pm is required (duh) 2008-11-10 10:12:49 -08:00
7 changed files with 105 additions and 35 deletions

16
Changes
View File

@@ -1,5 +1,17 @@
Revision history for MojoX-Renderer-TT
0.01 November 9, 2008
First version, released on an unsuspecting world.
0.10 November 12, 2008
- 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
(Viacheslav Tikhanovskii)
0.02 November 10, 2008
- Add template_options parameter
- Fix Template dependency
0.01 November 9, 2008
- First version, released on an unsuspecting world.

View File

@@ -13,7 +13,8 @@ WriteMakefile(
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'Mojo' => 0.8009,
'Mojo' => 0.8011,
'Template' => 2.18,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'MojoX-Renderer-TT-*' },

4
README
View File

@@ -21,6 +21,10 @@ perldoc command.
You can also look for information at:
Git repository
http://git.develooper.com/?p=MojoX-Renderer-TT.git;a=summary
git://git.develooper.com/MojoX-Renderer-TT.git
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT

View File

@@ -7,9 +7,13 @@ use base 'Mojo::Base';
use Template ();
use Carp ();
__PACKAGE__->attr('tt', chained => 1,);
our $VERSION = '0.10';
sub new {
__PACKAGE__->attr('tt', chained => 1);
sub new { Carp::croak "MojoX::Renderer::TT->new() is now ->build()" }
sub build {
my $self = shift->SUPER::new(@_);
$self->_init(@_);
return sub { $self->_render(@_) }
@@ -34,6 +38,7 @@ sub _init {
CACHE_SIZE => 128,
RELATIVE => 1,
ABSOLUTE => 1,
%{$args{template_options} || {}},
);
$self->tt(Template->new(\%config))
@@ -43,36 +48,39 @@ sub _init {
}
sub _render {
my ($self, $mojo, $tx, $path, $args) = @_;
my ($self, $mojo, $args) = @_;
$args ||= {};
$args->{args} ||= {};
#use Data::Dump qw(dump);
#warn dump(\$args);
my $output;
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 $self->tt->error;
return 0;
}
else {
return $output;
return 1;
}
}
1; # End of MojoX::Renderer::TT
__END__
=encoding utf-8
=head1 NAME
MojoX::Renderer::TT - Template Toolkit renderer for Mojo
=head1 VERSION
Version 0.01
=cut
our $VERSION = '0.01';
=head1 SYNOPSIS
Add the handler:
@@ -81,7 +89,16 @@ Add the handler:
sub startup {
...
$self->renderer->add_handler( tt => MojoX::Renderer::TT->new( mojo => $self ) );
my $tt = MojoX::Renderer::TT->new(
mojo => $self,
template_options =>
{ PROCESS => 'tpl/wrapper',
FILTERS => [ foo => [ \&filter_factory, 1]
}
);
$self->renderer->add_handler( html => $tt );
}
And then in the handler call render which will call the
@@ -92,10 +109,24 @@ MojoX::Renderer::TT renderer.
=head1 METHODS
=head2 new
=head2 build
This method returns a handler for the Mojo renderer.
Supported parameters are
=over 4
=item mojo
C<new> currently requires a C<mojo> parameter pointing to the base class (Mojo).
object.
=item template_options
A hash reference of options that are passed to Template->new().
=back
This currently requires a C<mojo> parameter pointing to the base class (Mojo).
object. This method returns not a TT object, but a handler for the Mojo renderer.
=head1 AUTHOR
@@ -103,13 +134,10 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
=head1 TODO
* Rename C<new> to something more sensical?
* 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?
* Accept options for setting up the Tempate object
* Better way to pass parameters to the templates?
* Better way to pass parameters to the templates? (stash)
* More sophisticated default search path?
=head1 BUGS
@@ -127,19 +155,21 @@ You can find documentation for this module with the perldoc command.
perldoc MojoX::Renderer::TT
You can also look for information at:
=over 4
=item * git repository
L<http://git.develooper.com/?p=MojoX-Renderer-TT.git;a=summary>,
L<git://git.develooper.com/MojoX-Renderer-TT.git>
L<http://github.com/abh/mojox-renderer-tt/>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/MojoX-Renderer-TT>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/MojoX-Renderer-TT>
@@ -163,5 +193,3 @@ under the same terms as Perl itself.
=cut
1; # End of MojoX::Renderer::TT

23
t/render.t Normal file
View File

@@ -0,0 +1,23 @@
#!perl
use strict;
use warnings;
use Test::More tests => 5;
use Mojo::Transaction;
use_ok('MojoX::Renderer::TT');
my $mt = MojoX::Renderer::TT->build;
my $output;
my $rv;
$rv = $mt->(undef, { path => 't/render/template.tt2', output => \$output });
is($rv, 1);
is($output, "4\n");
$rv = $mt->(undef, { path => 't/render/template-error.tt2', output => \$output });
is($rv, 0);
ok($output);

View File

@@ -0,0 +1 @@
[% = 2 %]

1
t/render/template.tt2 Normal file
View File

@@ -0,0 +1 @@
[% 2 + 2 %]