Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
460b36497a | ||
|
|
91a817b322 | ||
|
|
e779579347 | ||
|
|
e3db05fcb6 | ||
|
|
3c8ec94a70 | ||
|
|
a3b6ccdb2b | ||
|
|
bbabbf9ac1 | ||
|
|
0a42dd4f90 | ||
|
|
dc1c1570e1 | ||
|
|
1bcae03e9c | ||
|
|
e0b5f09326 | ||
|
|
8402f4f597 | ||
|
|
44f5312fef | ||
|
|
62146bb307 | ||
|
|
68783f08e2 | ||
|
|
9dce1eb021 |
@@ -1,5 +1,19 @@
|
|||||||
Revision history for MojoX-Renderer-TT
|
Revision history for MojoX-Renderer-TT
|
||||||
|
|
||||||
|
0.20 December 9, 2008
|
||||||
|
- Updates to work with Mojo 0.9
|
||||||
|
- Add default INCLUDE_PATH
|
||||||
|
- Made default compile dir not Unix specific (Viacheslav
|
||||||
|
Tikhanovskii)
|
||||||
|
|
||||||
|
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
|
0.02 November 10, 2008
|
||||||
- Add template_options parameter
|
- Add template_options parameter
|
||||||
- Fix Template dependency
|
- Fix Template dependency
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ lib/MojoX/Renderer/TT.pm
|
|||||||
t/00-load.t
|
t/00-load.t
|
||||||
t/pod-coverage.t
|
t/pod-coverage.t
|
||||||
t/pod.t
|
t/pod.t
|
||||||
|
t/render.t
|
||||||
|
t/render/template-error.tt2
|
||||||
|
t/render/template.tt2
|
||||||
.perltidyrc
|
.perltidyrc
|
||||||
|
|||||||
@@ -3,3 +3,5 @@
|
|||||||
\.shipit$
|
\.shipit$
|
||||||
.*\.bak$
|
.*\.bak$
|
||||||
^\.gitignore$
|
^\.gitignore$
|
||||||
|
\.DS_Store
|
||||||
|
Makefile
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ WriteMakefile(
|
|||||||
PL_FILES => {},
|
PL_FILES => {},
|
||||||
PREREQ_PM => {
|
PREREQ_PM => {
|
||||||
'Test::More' => 0,
|
'Test::More' => 0,
|
||||||
'Mojo' => 0.8009,
|
'Mojo' => 0.9,
|
||||||
'Template' => 2.18,
|
'Template' => 2.18,
|
||||||
},
|
},
|
||||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ perldoc command.
|
|||||||
|
|
||||||
You can also look for information at:
|
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
|
RT, CPAN's request tracker
|
||||||
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT
|
||||||
|
|
||||||
|
|||||||
+37
-29
@@ -6,10 +6,15 @@ use base 'Mojo::Base';
|
|||||||
|
|
||||||
use Template ();
|
use Template ();
|
||||||
use Carp ();
|
use Carp ();
|
||||||
|
use File::Spec ();
|
||||||
|
|
||||||
__PACKAGE__->attr('tt', chained => 1,);
|
our $VERSION = '0.20';
|
||||||
|
|
||||||
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(@_);
|
my $self = shift->SUPER::new(@_);
|
||||||
$self->_init(@_);
|
$self->_init(@_);
|
||||||
return sub { $self->_render(@_) }
|
return sub { $self->_render(@_) }
|
||||||
@@ -27,8 +32,9 @@ sub _init {
|
|||||||
# take and process options :-)
|
# take and process options :-)
|
||||||
|
|
||||||
my %config = (
|
my %config = (
|
||||||
|
( $mojo ? (INCLUDE_PATH => $mojo->home->rel_dir('templates') ) : () ),
|
||||||
COMPILE_EXT => '.ttc',
|
COMPILE_EXT => '.ttc',
|
||||||
COMPILE_DIR => ($dir || "/tmp"),
|
COMPILE_DIR => ($dir || File::Spec->tmpdir),
|
||||||
UNICODE => 1,
|
UNICODE => 1,
|
||||||
ENCODING => 'utf-8',
|
ENCODING => 'utf-8',
|
||||||
CACHE_SIZE => 128,
|
CACHE_SIZE => 128,
|
||||||
@@ -44,32 +50,36 @@ sub _init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub _render {
|
sub _render {
|
||||||
my ($self, $mojo, $tx, $path, $args) = @_;
|
my ($self, $renderer, $c, $output) = @_;
|
||||||
|
|
||||||
$args ||= {};
|
my $template_path = $c->stash->{template_path};
|
||||||
|
|
||||||
#use Data::Dump qw(dump);
|
unless (
|
||||||
#warn dump(\$args);
|
$self->tt->process(
|
||||||
|
$template_path, {%{$c->stash}, c => $c},
|
||||||
my $output;
|
$output, {binmode => ":utf8"}
|
||||||
unless ($self->tt->process($path, {%$args, tx => $tx}, \$output, {binmode => ":utf8"})) {
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
Carp::carp $self->tt->error . "\n";
|
Carp::carp $self->tt->error . "\n";
|
||||||
return $self->tt->error;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $output;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1; # End of MojoX::Renderer::TT
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=encoding utf-8
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
MojoX::Renderer::TT - Template Toolkit renderer for Mojo
|
MojoX::Renderer::TT - Template Toolkit renderer for Mojo
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
our $VERSION = '0.02';
|
|
||||||
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
Add the handler:
|
Add the handler:
|
||||||
@@ -79,7 +89,7 @@ Add the handler:
|
|||||||
sub startup {
|
sub startup {
|
||||||
...
|
...
|
||||||
|
|
||||||
my $tt = MojoX::Renderer::TT->new(
|
my $tt = MojoX::Renderer::TT->build(
|
||||||
mojo => $self,
|
mojo => $self,
|
||||||
template_options =>
|
template_options =>
|
||||||
{ PROCESS => 'tpl/wrapper',
|
{ PROCESS => 'tpl/wrapper',
|
||||||
@@ -98,9 +108,9 @@ MojoX::Renderer::TT renderer.
|
|||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
=head2 new
|
=head2 build
|
||||||
|
|
||||||
This method returns not a TT object, but a handler for the Mojo renderer.
|
This method returns a handler for the Mojo renderer.
|
||||||
|
|
||||||
Supported parameters are
|
Supported parameters are
|
||||||
|
|
||||||
@@ -123,11 +133,9 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
|
|||||||
|
|
||||||
=head1 TODO
|
=head1 TODO
|
||||||
|
|
||||||
* Rename C<new> to something more sensical?
|
|
||||||
* Better support non-Mojolicious frameworks
|
* Better support non-Mojolicious frameworks
|
||||||
* Don't require the mojo parameter
|
* Don't require the mojo parameter
|
||||||
* Move the default template cache directory?
|
* 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)
|
* Better way to pass parameters to the templates? (stash)
|
||||||
* More sophisticated default search path?
|
* More sophisticated default search path?
|
||||||
|
|
||||||
@@ -146,19 +154,21 @@ You can find documentation for this module with the perldoc command.
|
|||||||
|
|
||||||
perldoc MojoX::Renderer::TT
|
perldoc MojoX::Renderer::TT
|
||||||
|
|
||||||
|
|
||||||
You can also look for information at:
|
You can also look for information at:
|
||||||
|
|
||||||
=over 4
|
=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
|
=item * RT: CPAN's request tracker
|
||||||
|
|
||||||
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT>
|
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
|
=item * CPAN Ratings
|
||||||
|
|
||||||
L<http://cpanratings.perl.org/d/MojoX-Renderer-TT>
|
L<http://cpanratings.perl.org/d/MojoX-Renderer-TT>
|
||||||
@@ -182,5 +192,3 @@ under the same terms as Perl itself.
|
|||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
1; # End of MojoX::Renderer::TT
|
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
#!perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Test::More tests => 5;
|
||||||
|
|
||||||
|
use Mojo::Transaction;
|
||||||
|
use MojoX::Context;
|
||||||
|
|
||||||
|
use_ok('MojoX::Renderer::TT');
|
||||||
|
|
||||||
|
my $c = MojoX::Context->new;
|
||||||
|
|
||||||
|
my $mt = MojoX::Renderer::TT->build;
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
my $rv;
|
||||||
|
|
||||||
|
$c->stash->{template_path} = 't/render/template.tt2';
|
||||||
|
|
||||||
|
$rv = $mt->(undef, $c, \$output);
|
||||||
|
is($rv, 1);
|
||||||
|
is($output, "4\n");
|
||||||
|
|
||||||
|
$c->stash->{template_path} = 't/render/error.tt2';
|
||||||
|
$rv = $mt->(undef, $c, \$output);
|
||||||
|
is($rv, 0);
|
||||||
|
ok($output);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[% = 2 %]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[% 2 + 2 %]
|
||||||
Reference in New Issue
Block a user