Compare commits
52
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0d8b522ff | ||
|
|
388422491f | ||
|
|
1e7dc3044b | ||
|
|
01b8f94a2b | ||
|
|
26d555938f | ||
|
|
0d419c9ecd | ||
|
|
0708cfd051 | ||
|
|
3495571029 | ||
|
|
d51eea608b | ||
|
|
c3e8c9ff73 | ||
|
|
0588884a9f | ||
|
|
084c79825f | ||
|
|
3bddf34485 | ||
|
|
201774941a | ||
|
|
be2d2ed0ec | ||
|
|
89e744d8de | ||
|
|
b981e7080d | ||
|
|
5315d1efda | ||
|
|
d7f3b740f5 | ||
|
|
9f26a20192 | ||
|
|
731fe52836 | ||
|
|
988d1f954b | ||
|
|
1e4eeba737 | ||
|
|
857e517039 | ||
|
|
96d2be17b4 | ||
|
|
a2ce996b97 | ||
|
|
c4c554a46a | ||
|
|
f2d62f0a25 | ||
|
|
72855bad28 | ||
|
|
29a6a8c946 | ||
|
|
270ec1e6e5 | ||
|
|
ec4e464d90 | ||
|
|
d7726cfa0e | ||
|
|
68438d57cb | ||
|
|
6cae190a7a | ||
|
|
165c3b39f2 | ||
|
|
460b36497a | ||
|
|
91a817b322 | ||
|
|
e779579347 | ||
|
|
e3db05fcb6 | ||
|
|
3c8ec94a70 | ||
|
|
a3b6ccdb2b | ||
|
|
bbabbf9ac1 | ||
|
|
0a42dd4f90 | ||
|
|
dc1c1570e1 | ||
|
|
1bcae03e9c | ||
|
|
e0b5f09326 | ||
|
|
8402f4f597 | ||
|
|
44f5312fef | ||
|
|
62146bb307 | ||
|
|
68783f08e2 | ||
|
|
9dce1eb021 |
@@ -10,3 +10,4 @@ MojoX-Renderer-TT-*
|
|||||||
cover_db
|
cover_db
|
||||||
*~
|
*~
|
||||||
*.bak
|
*.bak
|
||||||
|
.build
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# auto-generated shipit config file.
|
|
||||||
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist
|
|
||||||
|
|
||||||
git.tagpattern = release/%v
|
|
||||||
|
|
||||||
# svn.tagpattern = MyProj-%v
|
|
||||||
# svn.tagpattern = http://code.example.com/svn/tags/MyProj-%v
|
|
||||||
|
|
||||||
# CheckChangeLog.files = ChangeLog, MyProj.CHANGES
|
|
||||||
@@ -1,5 +1,46 @@
|
|||||||
Revision history for MojoX-Renderer-TT
|
Revision history for MojoX-Renderer-TT
|
||||||
|
|
||||||
|
{{$NEXT}}
|
||||||
|
- Require (and be compatible with) Mojolicious 1.0+
|
||||||
|
- Added inline template support (Viacheslav Tykhanovskyi & Ask)
|
||||||
|
- Fix inline rendering and test failures (Marcus Ramberg)
|
||||||
|
- Fixed helper compatibility with Mojolicious 1.0 (Árpád Szász)
|
||||||
|
- Support new mojolicious error template (Marcus)
|
||||||
|
- Fix unicode test (Marcus & Spleenjack)
|
||||||
|
- Replaced deprecated Mojo dependence with Mojolicious (spleenjack)
|
||||||
|
|
||||||
|
0.40 August 2, 2010
|
||||||
|
- Updated for newer Mojo (Viacheslav Tykhanovskyi)
|
||||||
|
- Added helpers (Viacheslav Tykhanovskyi)
|
||||||
|
- Documentation updates
|
||||||
|
|
||||||
|
0.31 September 11, 2009
|
||||||
|
- Remove deprecated 'new' method
|
||||||
|
- Update MANIFEST (oops, thanks Sebastian)
|
||||||
|
|
||||||
|
0.30 September 9, 2009
|
||||||
|
- Revert the change of template_path stash key
|
||||||
|
- Reflect recent changes in mojo project (v0.991251) (Sebastian Knapp)
|
||||||
|
- One test with Mojolicious added (Sebastian Knapp)
|
||||||
|
|
||||||
|
0.21 July 29, 2009
|
||||||
|
- Update stash key from 'template_path' to 'template' to
|
||||||
|
match mojo change (Sebastian Knapp)
|
||||||
|
|
||||||
|
0.20 December 9, 2008
|
||||||
|
- Updates to work with Mojo 0.9
|
||||||
|
- Add default INCLUDE_PATH
|
||||||
|
- Made default compile dir not Unix specific (Viacheslav
|
||||||
|
Tykhanovskyi)
|
||||||
|
|
||||||
|
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 Tykhanovskyi)
|
||||||
|
- Update to work with new error handling in Mojo
|
||||||
|
(Viacheslav Tykhanovskyi)
|
||||||
|
|
||||||
0.02 November 10, 2008
|
0.02 November 10, 2008
|
||||||
- Add template_options parameter
|
- Add template_options parameter
|
||||||
- Fix Template dependency
|
- Fix Template dependency
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
Changes
|
|
||||||
MANIFEST
|
|
||||||
MANIFEST.SKIP
|
|
||||||
Makefile.PL
|
|
||||||
README
|
|
||||||
lib/MojoX/Renderer/TT.pm
|
|
||||||
t/00-load.t
|
|
||||||
t/pod-coverage.t
|
|
||||||
t/pod.t
|
|
||||||
.perltidyrc
|
|
||||||
+46
-5
@@ -1,5 +1,46 @@
|
|||||||
\.git\/
|
# Avoid version control files.
|
||||||
.*~$
|
\bRCS\b
|
||||||
\.shipit$
|
\bCVS\b
|
||||||
.*\.bak$
|
\bSCCS\b
|
||||||
^\.gitignore$
|
,v$
|
||||||
|
\B\.svn\b
|
||||||
|
\B\.git\b
|
||||||
|
\b_darcs\b
|
||||||
|
|
||||||
|
# Avoid Makemaker generated and utility files.
|
||||||
|
\bMANIFEST\.bak
|
||||||
|
\bMakefile$
|
||||||
|
\bblib/
|
||||||
|
\bMakeMaker-\d
|
||||||
|
\bpm_to_blib\.ts$
|
||||||
|
\bpm_to_blib$
|
||||||
|
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
|
||||||
|
|
||||||
|
# Avoid Module::Build generated and utility files.
|
||||||
|
\bBuild$
|
||||||
|
\b_build/
|
||||||
|
|
||||||
|
# Avoid temp and backup files.
|
||||||
|
~$
|
||||||
|
\.old$
|
||||||
|
\#$
|
||||||
|
\b\.#
|
||||||
|
\.bak$
|
||||||
|
|
||||||
|
# Avoid Devel::Cover files.
|
||||||
|
\bcover_db\b
|
||||||
|
|
||||||
|
### DEFAULT MANIFEST.SKIP ENDS HERE ####
|
||||||
|
|
||||||
|
t/tmp/ctpl
|
||||||
|
|
||||||
|
\.DS_Store$
|
||||||
|
\.sw.$
|
||||||
|
(\w+-)*(\w+)-\d\.\d+(?:\.tar\.gz)?$
|
||||||
|
|
||||||
|
\.t\.log$
|
||||||
|
|
||||||
|
\.prove$
|
||||||
|
|
||||||
|
# XS shit
|
||||||
|
\.(?:bs|c|o)$
|
||||||
|
|||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
use ExtUtils::MakeMaker;
|
|
||||||
|
|
||||||
WriteMakefile(
|
|
||||||
NAME => 'MojoX::Renderer::TT',
|
|
||||||
AUTHOR => 'Ask Bjørn Hansen <ask@develooper.com>',
|
|
||||||
VERSION_FROM => 'lib/MojoX/Renderer/TT.pm',
|
|
||||||
ABSTRACT_FROM => 'lib/MojoX/Renderer/TT.pm',
|
|
||||||
($ExtUtils::MakeMaker::VERSION >= 6.3002
|
|
||||||
? ('LICENSE'=> 'perl')
|
|
||||||
: ()),
|
|
||||||
PL_FILES => {},
|
|
||||||
PREREQ_PM => {
|
|
||||||
'Test::More' => 0,
|
|
||||||
'Mojo' => 0.8009,
|
|
||||||
'Template' => 2.18,
|
|
||||||
},
|
|
||||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
|
||||||
clean => { FILES => 'MojoX-Renderer-TT-*' },
|
|
||||||
);
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
MojoX-Renderer-TT
|
|
||||||
|
|
||||||
This module implements a Template Toolkit renderer for the Mojo
|
|
||||||
framework.
|
|
||||||
|
|
||||||
INSTALLATION
|
|
||||||
|
|
||||||
To install this module, run the following commands:
|
|
||||||
|
|
||||||
perl Makefile.PL
|
|
||||||
make
|
|
||||||
make test
|
|
||||||
make install
|
|
||||||
|
|
||||||
SUPPORT AND DOCUMENTATION
|
|
||||||
|
|
||||||
After installing, you can find documentation for this module with the
|
|
||||||
perldoc command.
|
|
||||||
|
|
||||||
perldoc MojoX::Renderer::TT
|
|
||||||
|
|
||||||
You can also look for information at:
|
|
||||||
|
|
||||||
RT, CPAN's request tracker
|
|
||||||
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT
|
|
||||||
|
|
||||||
CPAN Ratings
|
|
||||||
http://cpanratings.perl.org/d/MojoX-Renderer-TT
|
|
||||||
|
|
||||||
Search CPAN
|
|
||||||
http://search.cpan.org/dist/MojoX-Renderer-TT/
|
|
||||||
|
|
||||||
|
|
||||||
COPYRIGHT AND LICENCE
|
|
||||||
|
|
||||||
Copyright (C) 2008 Ask Bjørn Hansen
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
|
||||||
under the same terms as Perl itself.
|
|
||||||
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
name = MojoX-Renderer-TT
|
||||||
|
author = Ask Bjørn Hansen <ask@develooper.com>
|
||||||
|
license = Perl_5
|
||||||
|
|
||||||
|
copyright_holder = Ask Bjørn Hansen
|
||||||
|
# copyright_year = 2009
|
||||||
|
|
||||||
|
[Prereqs]
|
||||||
|
Mojolicious = 1.01
|
||||||
|
Template = 2.18
|
||||||
|
|
||||||
|
[Prereqs / TestRequires ]
|
||||||
|
Test::More = 0
|
||||||
|
|
||||||
|
[@Git]
|
||||||
|
tag_format = release/%v
|
||||||
|
# push_to = all
|
||||||
|
|
||||||
|
[@Filter]
|
||||||
|
bundle = @Basic
|
||||||
|
remove = Readme
|
||||||
|
remove = Manifest
|
||||||
|
|
||||||
|
[Repository]
|
||||||
|
repository = git://github.com/abh/mojox-renderer-tt.git
|
||||||
|
web = https://github.com/abh/mojox-renderer-tt
|
||||||
|
|
||||||
|
[Bugtracker]
|
||||||
|
web = https://github.com/abh/mojox-renderer-tt/issues
|
||||||
|
|
||||||
|
[Homepage]
|
||||||
|
|
||||||
|
[BumpVersionFromGit]
|
||||||
|
version_regexp = ^release/(.*)
|
||||||
|
|
||||||
|
[PkgVersion]
|
||||||
|
|
||||||
|
[CheckChangeLog]
|
||||||
|
[CompileTests]
|
||||||
|
[DistManifestTests]
|
||||||
|
[HasVersionTests]
|
||||||
|
[MetaTests]
|
||||||
|
[ReadmeFromPod]
|
||||||
|
[PodCoverageTests]
|
||||||
|
[Manifest]
|
||||||
|
|
||||||
|
[NextRelease]
|
||||||
|
format = %-7v %{MMMM d, yyyy}d
|
||||||
|
|
||||||
+184
-59
@@ -2,14 +2,16 @@ package MojoX::Renderer::TT;
|
|||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use base 'Mojo::Base';
|
use base 'Mojo::Base';
|
||||||
|
|
||||||
|
use File::Spec ();
|
||||||
|
use Mojo::ByteStream 'b';
|
||||||
use Template ();
|
use Template ();
|
||||||
use Carp ();
|
|
||||||
|
|
||||||
__PACKAGE__->attr('tt', chained => 1,);
|
__PACKAGE__->attr('tt');
|
||||||
|
|
||||||
sub new {
|
sub build {
|
||||||
my $self = shift->SUPER::new(@_);
|
my $self = shift->SUPER::new(@_);
|
||||||
$self->_init(@_);
|
$self->_init(@_);
|
||||||
return sub { $self->_render(@_) }
|
return sub { $self->_render(@_) }
|
||||||
@@ -19,16 +21,19 @@ sub _init {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my %args = @_;
|
my %args = @_;
|
||||||
|
|
||||||
my $mojo = delete $args{mojo};
|
#$Template::Parser::DEBUG = 1;
|
||||||
|
|
||||||
my $dir = $mojo && $mojo->home->rel_dir('tmp/ctpl');
|
my $app = delete $args{mojo} || delete $args{app};
|
||||||
|
|
||||||
|
my $dir = $app && $app->home->rel_dir('tmp/ctpl');
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# take and process options :-)
|
# take and process options :-)
|
||||||
|
|
||||||
my %config = (
|
my %config = (
|
||||||
|
($app ? (INCLUDE_PATH => $app->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,
|
||||||
@@ -37,78 +42,205 @@ sub _init {
|
|||||||
%{$args{template_options} || {}},
|
%{$args{template_options} || {}},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$config{LOAD_TEMPLATES} =
|
||||||
|
[MojoX::Renderer::TT::Provider->new(%config, renderer => $app->renderer)]
|
||||||
|
unless $config{LOAD_TEMPLATES};
|
||||||
|
|
||||||
$self->tt(Template->new(\%config))
|
$self->tt(Template->new(\%config))
|
||||||
or Carp::croak "Could not initialize Template object: $Template::ERROR";
|
or Carp::croak "Could not initialize Template object: $Template::ERROR";
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
sub _render {
|
sub _render {
|
||||||
my ($self, $mojo, $tx, $path, $args) = @_;
|
my ($self, $renderer, $c, $output, $options) = @_;
|
||||||
|
|
||||||
$args ||= {};
|
# Inline
|
||||||
|
my $inline = $options->{inline};
|
||||||
|
|
||||||
#use Data::Dump qw(dump);
|
# Template
|
||||||
#warn dump(\$args);
|
my $t = $renderer->template_name($options);
|
||||||
|
$t = 'inline' if defined $inline;
|
||||||
|
return unless $t;
|
||||||
|
|
||||||
my $output;
|
# Path
|
||||||
unless ($self->tt->process($path, {%$args, tx => $tx}, \$output, {binmode => ":utf8"})) {
|
my $path = $renderer->template_path($options);
|
||||||
Carp::carp $self->tt->error . "\n";
|
$path = b($inline)->md5_sum->to_string if defined $inline;
|
||||||
return $self->tt->error;
|
return unless $path;
|
||||||
}
|
|
||||||
else {
|
my $helper = MojoX::Renderer::TT::Helper->new(ctx => $c);
|
||||||
return $output;
|
|
||||||
|
my @params = ({%{$c->stash}, c => $c, h => $helper}, $output, {binmode => ':utf8'});
|
||||||
|
$self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->ctx($c);
|
||||||
|
|
||||||
|
my $ok = $self->tt->process(defined $inline ? \$inline : $path, @params);
|
||||||
|
|
||||||
|
# Error
|
||||||
|
unless ($ok) {
|
||||||
|
|
||||||
|
my $e = Mojo::Exception->new(
|
||||||
|
$self->tt->error.'',
|
||||||
|
$self->tt->service->process(defined $inline ? \$inline : $path));
|
||||||
|
$$output = '';
|
||||||
|
$c->app->log->error(qq/Template error in "$t": $e/);
|
||||||
|
$c->render_exception($e);
|
||||||
|
$self->tt->error('');
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1; # End of MojoX::Renderer::TT
|
||||||
|
|
||||||
|
package
|
||||||
|
MojoX::Renderer::TT::Helper;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'Mojo::Base';
|
||||||
|
|
||||||
|
our $AUTOLOAD;
|
||||||
|
|
||||||
|
__PACKAGE__->attr('ctx');
|
||||||
|
|
||||||
|
sub AUTOLOAD {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $method = $AUTOLOAD;
|
||||||
|
|
||||||
|
return if $method =~ /^[A-Z]+?$/;
|
||||||
|
return if $method =~ /^_/;
|
||||||
|
return if $method =~ /(?:\:*?)DESTROY$/;
|
||||||
|
|
||||||
|
$method = (split '::' => $method)[-1];
|
||||||
|
|
||||||
|
die qq/Unknown helper: $method/ unless $self->ctx->app->renderer->helpers->{$method};
|
||||||
|
|
||||||
|
return $self->ctx->$method(@_);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
package
|
||||||
|
MojoX::Renderer::TT::Provider;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'Template::Provider';
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my $class = shift;
|
||||||
|
my %params = @_;
|
||||||
|
|
||||||
|
my $renderer = delete $params{renderer};
|
||||||
|
|
||||||
|
my $self = $class->SUPER::new(%params);
|
||||||
|
$self->renderer($renderer);
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub renderer { @_ > 1 ? $_[0]->{renderer} = $_[1] : $_[0]->{renderer} }
|
||||||
|
sub ctx { @_ > 1 ? $_[0]->{ctx} = $_[1] : $_[0]->{ctx} }
|
||||||
|
|
||||||
|
sub _template_modified {1}
|
||||||
|
|
||||||
|
sub _template_content {
|
||||||
|
my $self = shift;
|
||||||
|
my ($path) = @_;
|
||||||
|
|
||||||
|
my ($t) = ($path =~ m{templates\/(.*)$});
|
||||||
|
|
||||||
|
if (-r $path) {
|
||||||
|
return $self->SUPER::_template_content(@_);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try DATA section
|
||||||
|
elsif (my $d = $self->renderer->get_inline_template($self->ctx, $t)) {
|
||||||
|
return wantarray ? ($d, '', time) : $d;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $data = '';
|
||||||
|
my $error = "$path: not found";
|
||||||
|
my $mod_date = time;
|
||||||
|
return wantarray ? ($data, $error, $mod_date) : $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__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:
|
||||||
|
|
||||||
use MojoX::Renderer::TT;
|
|
||||||
|
|
||||||
sub startup {
|
sub startup {
|
||||||
...
|
...
|
||||||
|
|
||||||
my $tt = MojoX::Renderer::TT->new(
|
# Via mojolicious plugin
|
||||||
|
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
|
||||||
|
|
||||||
|
# Or manually
|
||||||
|
use MojoX::Renderer::TT;
|
||||||
|
|
||||||
|
my $tt = MojoX::Renderer::TT->build(
|
||||||
mojo => $self,
|
mojo => $self,
|
||||||
template_options =>
|
template_options => {
|
||||||
{ PROCESS => 'tpl/wrapper',
|
PROCESS => 'tpl/wrapper',
|
||||||
FILTERS => [ foo => [ \&filter_factory, 1]
|
FILTERS => [ ... ],
|
||||||
}
|
UNICODE => 1,
|
||||||
);
|
ENCODING => 'UTF-8',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->renderer->add_handler( html => $tt );
|
$self->renderer->add_handler( tt => $tt );
|
||||||
}
|
}
|
||||||
|
|
||||||
And then in the handler call render which will call the
|
Template parameter are taken from C< $c->stash >.
|
||||||
MojoX::Renderer::TT renderer.
|
|
||||||
|
|
||||||
$c->render(foo => 123, bar => [qw(giz mo)]);
|
=head1 RENDERING
|
||||||
|
|
||||||
|
The template file for C<"example/welcome"> would be C<"templates/welcome.html.tt">.
|
||||||
|
|
||||||
|
When template file is not available rendering from C<__DATA__> is attempted.
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
|
||||||
|
@@ welcome.html.tt
|
||||||
|
Welcome, [% user.name %]!
|
||||||
|
|
||||||
|
Inline template is also supported:
|
||||||
|
|
||||||
|
$self->render(inline => '[% 1 + 1 %]', handler => 'tt');
|
||||||
|
|
||||||
|
=head1 HELPERS
|
||||||
|
|
||||||
|
Helpers are exported automatically under C<h> namespace.
|
||||||
|
|
||||||
|
[% h.url_for('index') %]
|
||||||
|
|
||||||
=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 Mojolicious renderer.
|
||||||
|
|
||||||
Supported parameters are
|
Supported parameters are
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
=item mojo
|
=item mojo
|
||||||
C<new> currently requires a C<mojo> parameter pointing to the base class (Mojo).
|
C<build> currently uses a C<mojo> parameter pointing to the base class (Mojo).
|
||||||
object.
|
object. When used the INCLUDE_PATH will be set to
|
||||||
|
|
||||||
=item template_options
|
=item template_options
|
||||||
|
|
||||||
@@ -116,29 +248,24 @@ A hash reference of options that are passed to Template->new().
|
|||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
Ask Bjørn Hansen, C<< <ask at develooper.com> >>
|
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
|
|
||||||
* 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?
|
||||||
|
|
||||||
=head1 BUGS
|
=head1 BUGS
|
||||||
|
|
||||||
Please report any bugs or feature requests to C<bug-mojox-renderer-tt at rt.cpan.org>, or through
|
Please report any bugs or feature requests to C<bug-mojox-renderer-tt at rt.cpan.org>,
|
||||||
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MojoX-Renderer-TT>. I will be notified, and then you'll
|
or through the web interface at
|
||||||
automatically be notified of progress on your bug as I make changes.
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MojoX-Renderer-TT>. I will be
|
||||||
|
notified, and then you'll automatically be notified of progress on your bug as I
|
||||||
|
make changes.
|
||||||
|
|
||||||
|
|
||||||
=head1 SUPPORT
|
=head1 SUPPORT
|
||||||
|
|
||||||
@@ -146,19 +273,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>
|
||||||
@@ -169,18 +298,14 @@ L<http://search.cpan.org/dist/MojoX-Renderer-TT/>
|
|||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
||||||
=head1 ACKNOWLEDGEMENTS
|
=head1 ACKNOWLEDGEMENTS
|
||||||
|
|
||||||
|
|
||||||
=head1 COPYRIGHT & LICENSE
|
=head1 COPYRIGHT & LICENSE
|
||||||
|
|
||||||
Copyright 2008 Ask Bjørn Hansen, all rights reserved.
|
Copyright 2008-2010 Ask Bjørn Hansen, all rights reserved.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
||||||
under the same terms as Perl itself.
|
under the same terms as Perl itself.
|
||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
1; # End of MojoX::Renderer::TT
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package Mojolicious::Plugin::TtRenderer;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
our $VERSION = '0.01';
|
||||||
|
|
||||||
|
use base 'Mojolicious::Plugin';
|
||||||
|
|
||||||
|
use MojoX::Renderer::TT;
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($self, $app, $args) = @_;
|
||||||
|
|
||||||
|
$args ||= {};
|
||||||
|
|
||||||
|
my $tt = MojoX::Renderer::TT->build(%$args, app => $app);
|
||||||
|
|
||||||
|
# Add "tt" handler
|
||||||
|
$app->renderer->add_handler(tt => $tt);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Mojolicious::Plugin::TtRenderer - Template Renderer Plugin
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
# Mojolicious
|
||||||
|
$self->plugin('tt_renderer');
|
||||||
|
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
|
||||||
|
|
||||||
|
# Mojolicious::Lite
|
||||||
|
plugin 'tt_renderer';
|
||||||
|
plugin tt_renderer => {template_options => {FILTERS => [ ... ]}};
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
L<Mojolicous::Plugin::TtRenderer> is a simple loader for L<MojoX::Renderer::TT>.
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
L<Mojolicious::Plugin::TtRenderer> inherits all methods from
|
||||||
|
L<Mojolicious::Plugin> and implements the following new ones.
|
||||||
|
|
||||||
|
=head2 C<register>
|
||||||
|
|
||||||
|
$plugin->register;
|
||||||
|
|
||||||
|
Register renderer in L<Mojolicious> application.
|
||||||
|
|
||||||
|
=head1 SEE ALSO
|
||||||
|
|
||||||
|
L<MojoX::Renderer::TT>, L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
|
||||||
|
|
||||||
|
=cut
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#!perl -T
|
#!perl
|
||||||
|
|
||||||
use Test::More tests => 1;
|
use Test::More tests => 1;
|
||||||
|
|
||||||
|
|||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
use Test::More tests => 25;
|
||||||
|
|
||||||
|
use Mojolicious::Lite;
|
||||||
|
use Mojo::ByteStream 'b';
|
||||||
|
use Test::Mojo;
|
||||||
|
|
||||||
|
# Silence
|
||||||
|
app->log->level('fatal');
|
||||||
|
|
||||||
|
use_ok('MojoX::Renderer::TT');
|
||||||
|
|
||||||
|
plugin 'tt_renderer' => {template_options => {PRE_CHOMP => 1, POST_CHOMP => 1, TRIM => 1}};
|
||||||
|
|
||||||
|
get '/exception' => 'error';
|
||||||
|
|
||||||
|
get '/with_include' => 'include';
|
||||||
|
|
||||||
|
get '/with_wrapper' => 'wrapper';
|
||||||
|
|
||||||
|
#get '/with_auto_wrapper' => sub { shift->render(auto_wrapper => layout => 'layout') };
|
||||||
|
|
||||||
|
get '/unicode' => 'unicode';
|
||||||
|
|
||||||
|
get '/helpers' => 'helpers';
|
||||||
|
|
||||||
|
get '/unknown_helper' => 'unknown_helper';
|
||||||
|
|
||||||
|
get '/on-disk' => 'foo';
|
||||||
|
|
||||||
|
get '/bar/:message' => 'bar';
|
||||||
|
|
||||||
|
get '/inline' => sub { shift->render(inline => '[% 1 + 1 %]', handler => 'tt') };
|
||||||
|
|
||||||
|
my $t = Test::Mojo->new;
|
||||||
|
|
||||||
|
# Exception
|
||||||
|
$t->get_ok('/exception')->status_is(500)->content_like(qr/error/i);
|
||||||
|
|
||||||
|
# Normal rendering
|
||||||
|
$t->get_ok('/bar/hello')->content_is("hello");
|
||||||
|
|
||||||
|
# With include
|
||||||
|
$t->get_ok('/with_include')->content_is("HelloInclude!Hallo");
|
||||||
|
|
||||||
|
# With wrapper
|
||||||
|
$t->get_ok('/with_wrapper')->content_is("wrapped");
|
||||||
|
|
||||||
|
# With auto wrapper
|
||||||
|
#$t->get_ok('/with_auto_wrapper')->content_is("wrapped");
|
||||||
|
|
||||||
|
# Unicode
|
||||||
|
$t->get_ok('/unicode')->content_is("привет");
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
$t->get_ok('/helpers')->content_is("/helpers");
|
||||||
|
|
||||||
|
# Unknown helper
|
||||||
|
$t->get_ok('/unknown_helper')->status_is(500)->content_like(qr//);
|
||||||
|
|
||||||
|
# On Disk
|
||||||
|
$t->get_ok('/on-disk')->content_is("4");
|
||||||
|
|
||||||
|
# Not found
|
||||||
|
$t->get_ok('/not_found')->status_is(404)->content_like(qr/not found/i);
|
||||||
|
|
||||||
|
# Inline
|
||||||
|
$t->get_ok('/inline')->status_is(200)->content_is('2');
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
|
||||||
|
@@ bar.html.tt
|
||||||
|
[% message %]
|
||||||
|
|
||||||
|
@@ error.html.tt
|
||||||
|
[% 1 + % %]
|
||||||
|
|
||||||
|
@@ include.inc
|
||||||
|
Hello
|
||||||
|
|
||||||
|
@@ includes/include.inc
|
||||||
|
Hallo
|
||||||
|
|
||||||
|
@@ include.html.tt
|
||||||
|
[%- INCLUDE 'include.inc' -%]
|
||||||
|
Include!
|
||||||
|
[% INCLUDE 'includes/include.inc' -%]
|
||||||
|
|
||||||
|
@@ layouts/layout.html.tt
|
||||||
|
w[%- content -%]d
|
||||||
|
|
||||||
|
@@ wrapper.html.tt
|
||||||
|
[%- WRAPPER 'layouts/layout.html.tt' -%]
|
||||||
|
rappe
|
||||||
|
[%- END -%]
|
||||||
|
|
||||||
|
@@ auto_wrapper.html.tt
|
||||||
|
rappe
|
||||||
|
|
||||||
|
@@ unicode.html.tt
|
||||||
|
привет
|
||||||
|
|
||||||
|
@@ helpers.html.tt
|
||||||
|
[% h.url_for('helpers') %]
|
||||||
|
|
||||||
|
@@ unknown_helper.html.tt
|
||||||
|
[% h.unknown_helper('foo') %]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[% 2 + 2 %]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
test123[% 456 %]
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
# Copyright (C) 2008-2010, Sebastian Riedel.
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use File::Temp;
|
||||||
|
use Mojo::IOLoop;
|
||||||
|
use Test::More;
|
||||||
|
|
||||||
|
# Use a clean temporary directory
|
||||||
|
BEGIN { $ENV{MOJO_TMPDIR} ||= File::Temp::tempdir }
|
||||||
|
|
||||||
|
# Make sure sockets are working
|
||||||
|
plan skip_all => 'working sockets required for this test!'
|
||||||
|
unless Mojo::IOLoop->new->generate_port;
|
||||||
|
plan tests => 3;
|
||||||
|
|
||||||
|
# Leela: OK, this has gotta stop. I'm going to remind Fry of his humanity the way only a woman can.
|
||||||
|
# Farnsworth: You're going to do his laundry?
|
||||||
|
|
||||||
|
use Mojolicious::Lite;
|
||||||
|
use Test::Mojo;
|
||||||
|
|
||||||
|
# POD renderer plugin
|
||||||
|
plugin 'tt_renderer';
|
||||||
|
|
||||||
|
# Silence
|
||||||
|
app->log->level('error');
|
||||||
|
|
||||||
|
# GET /
|
||||||
|
get '/' => 'index';
|
||||||
|
|
||||||
|
my $t = Test::Mojo->new;
|
||||||
|
|
||||||
|
# Simple TT template
|
||||||
|
$t->get_ok('/')->status_is(200)
|
||||||
|
->content_like(qr/test123456/);
|
||||||
Reference in New Issue
Block a user