Compare commits
32 Commits
release/0.
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
392b97e81a | ||
|
|
a5e276f633 | ||
|
|
fc453fe4fb | ||
|
|
32c83d6109 | ||
|
|
5e5c23d786 | ||
|
|
fa30565b6b | ||
|
|
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 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ MojoX-Renderer-TT-*
|
||||
cover_db
|
||||
*~
|
||||
*.bak
|
||||
.build
|
||||
|
||||
26
Changes
26
Changes
@@ -1,5 +1,25 @@
|
||||
Revision history for MojoX-Renderer-TT
|
||||
|
||||
{{$NEXT}}
|
||||
- Support Mojolicious 'layout'/'extends' (Maxim Vuets, Marcus
|
||||
Ramberg)
|
||||
- Fix Strawberry Perl tests (RT#65282, Christiaan Kras, Ask)
|
||||
- Update bugtracker URL in META.yml
|
||||
|
||||
1.0 January 22, 2011
|
||||
- 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)
|
||||
@@ -17,15 +37,15 @@ Revision history for MojoX-Renderer-TT
|
||||
- Updates to work with Mojo 0.9
|
||||
- Add default INCLUDE_PATH
|
||||
- Made default compile dir not Unix specific (Viacheslav
|
||||
Tikhanovskii)
|
||||
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 Tikhanovskii)
|
||||
- Add real tests (Viacheslav Tykhanovskyi)
|
||||
- Update to work with new error handling in Mojo
|
||||
(Viacheslav Tikhanovskii)
|
||||
(Viacheslav Tykhanovskyi)
|
||||
|
||||
0.02 November 10, 2008
|
||||
- Add template_options parameter
|
||||
|
||||
15
MANIFEST
15
MANIFEST
@@ -1,15 +0,0 @@
|
||||
.gitignore
|
||||
.perltidyrc
|
||||
Changes
|
||||
lib/MojoX/Renderer/TT.pm
|
||||
Makefile.PL
|
||||
MANIFEST
|
||||
MANIFEST.SKIP
|
||||
README
|
||||
t/00-load.t
|
||||
t/pod-coverage.t
|
||||
t/pod.t
|
||||
t/render.t
|
||||
t/render/template-error.tt2
|
||||
t/render/template.html.tt2
|
||||
t/render/template.tt2
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
### DEFAULT MANIFEST.SKIP ENDS HERE ####
|
||||
|
||||
t/tmp/ctpl
|
||||
|
||||
\.DS_Store$
|
||||
\.sw.$
|
||||
(\w+-)*(\w+)-\d\.\d+(?:\.tar\.gz)?$
|
||||
|
||||
21
Makefile.PL
21
Makefile.PL
@@ -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.991251,
|
||||
'Template' => 2.18,
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'MojoX-Renderer-TT-*' },
|
||||
);
|
||||
44
README
44
README
@@ -1,44 +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:
|
||||
|
||||
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
|
||||
|
||||
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-2009 Ask Bjørn Hansen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the same terms as Perl itself.
|
||||
|
||||
48
dist.ini
Normal file
48
dist.ini
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
|
||||
[MetaResources]
|
||||
bugtracker.web = https://github.com/abh/mojox-renderer-tt/issues
|
||||
repository.web = http://github.com/abh/mojox-renderer-tt
|
||||
repository.url = git://github.com/abh/mojox-renderer-tt.git
|
||||
repository.type = git
|
||||
|
||||
[Homepage]
|
||||
|
||||
[BumpVersionFromGit]
|
||||
version_regexp = ^release/(.*)
|
||||
|
||||
[PkgVersion]
|
||||
|
||||
[CheckChangeLog]
|
||||
[CompileTests]
|
||||
[DistManifestTests]
|
||||
[HasVersionTests]
|
||||
[MetaTests]
|
||||
[ReadmeFromPod]
|
||||
[PodCoverageTests]
|
||||
[Manifest]
|
||||
|
||||
[NextRelease]
|
||||
format = %-7v %{MMMM d, yyyy}d
|
||||
|
||||
@@ -2,13 +2,12 @@ package MojoX::Renderer::TT;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use base 'Mojo::Base';
|
||||
|
||||
use Template ();
|
||||
use Carp ();
|
||||
use File::Spec ();
|
||||
|
||||
our $VERSION = '0.31';
|
||||
use Mojo::ByteStream 'b';
|
||||
use Template ();
|
||||
|
||||
__PACKAGE__->attr('tt');
|
||||
|
||||
@@ -22,15 +21,17 @@ sub _init {
|
||||
my $self = shift;
|
||||
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
|
||||
# take and process options :-)
|
||||
|
||||
my %config = (
|
||||
( $mojo ? (INCLUDE_PATH => $mojo->home->rel_dir('templates') ) : () ),
|
||||
($app ? (INCLUDE_PATH => $app->home->rel_dir('templates')) : ()),
|
||||
COMPILE_EXT => '.ttc',
|
||||
COMPILE_DIR => ($dir || File::Spec->tmpdir),
|
||||
UNICODE => 1,
|
||||
@@ -41,38 +42,138 @@ sub _init {
|
||||
%{$args{template_options} || {}},
|
||||
);
|
||||
|
||||
$config{LOAD_TEMPLATES} =
|
||||
[MojoX::Renderer::TT::Provider->new(%config, renderer => $app->renderer)]
|
||||
unless $config{LOAD_TEMPLATES};
|
||||
|
||||
$self->tt(Template->new(\%config))
|
||||
or Carp::croak "Could not initialize Template object: $Template::ERROR";
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
use Data::Dumper;
|
||||
sub _render {
|
||||
my ($self, $renderer, $c, $output, $options) = @_;
|
||||
|
||||
my $template_path;
|
||||
unless($template_path = $c->stash->{'template_path'}) {
|
||||
$template_path = $renderer->template_path($options);
|
||||
}
|
||||
# Inline
|
||||
my $inline = $options->{inline};
|
||||
|
||||
unless (
|
||||
$self->tt->process(
|
||||
$template_path, {%{$c->stash}, c => $c},
|
||||
$output, {binmode => ":utf8"}
|
||||
)
|
||||
)
|
||||
{
|
||||
Carp::carp $self->tt->error . "\n";
|
||||
# Template
|
||||
my $t = $renderer->template_name($options);
|
||||
$t = 'inline' if defined $inline;
|
||||
return unless $t;
|
||||
|
||||
# Path
|
||||
my $path = $renderer->template_path($options);
|
||||
$path = b($inline)->md5_sum->to_string if defined $inline;
|
||||
return unless $path;
|
||||
|
||||
my $helper = MojoX::Renderer::TT::Helper->new(ctx => $c);
|
||||
|
||||
# Purge previous result
|
||||
$$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;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -85,28 +186,50 @@ MojoX::Renderer::TT - Template Toolkit renderer for Mojo
|
||||
|
||||
Add the handler:
|
||||
|
||||
use MojoX::Renderer::TT;
|
||||
|
||||
sub startup {
|
||||
...
|
||||
...
|
||||
|
||||
my $tt = MojoX::Renderer::TT->build(
|
||||
# Via mojolicious plugin
|
||||
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
|
||||
|
||||
# Or manually
|
||||
use MojoX::Renderer::TT;
|
||||
|
||||
my $tt = MojoX::Renderer::TT->build(
|
||||
mojo => $self,
|
||||
template_options =>
|
||||
{ PROCESS => 'tpl/wrapper',
|
||||
FILTERS => [ foo => [ \&filter_factory, 1]
|
||||
}
|
||||
);
|
||||
template_options => {
|
||||
PROCESS => 'tpl/wrapper',
|
||||
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
|
||||
MojoX::Renderer::TT renderer.
|
||||
Template parameter are taken from C< $c->stash >.
|
||||
|
||||
$c->render(templatename, format => 'tex', handler => 'tt2');
|
||||
=head1 RENDERING
|
||||
|
||||
Template parameter are taken from $c->stash
|
||||
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
|
||||
|
||||
@@ -124,11 +247,10 @@ object. When used the INCLUDE_PATH will be set to
|
||||
|
||||
=item template_options
|
||||
|
||||
A hash reference of options that are passed to Template->new().
|
||||
A hash reference of options that are passed to Template->new().
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Ask Bjørn Hansen, C<< <ask at develooper.com> >>
|
||||
@@ -142,12 +264,11 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
Please report any bugs or feature requests to C<bug-mojox-renderer-tt at rt.cpan.org>, or through
|
||||
the web interface at 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.
|
||||
|
||||
|
||||
|
||||
Please report any bugs or feature requests to C<bug-mojox-renderer-tt at rt.cpan.org>,
|
||||
or through the web interface at
|
||||
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
|
||||
|
||||
@@ -180,16 +301,14 @@ L<http://search.cpan.org/dist/MojoX-Renderer-TT/>
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head1 ACKNOWLEDGEMENTS
|
||||
|
||||
|
||||
=head1 COPYRIGHT & LICENSE
|
||||
|
||||
Copyright 2008-2009 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
|
||||
under the same terms as Perl itself.
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
59
lib/Mojolicious/Plugin/TtRenderer.pm
Normal file
59
lib/Mojolicious/Plugin/TtRenderer.pm
Normal file
@@ -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
|
||||
2
t/.gitignore
vendored
Normal file
2
t/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/tmp/
|
||||
*.ttc
|
||||
134
t/lite_app.t
Normal file
134
t/lite_app.t
Normal file
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
|
||||
use Test::More tests => 31;
|
||||
|
||||
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' => 'auto_wrapper';
|
||||
|
||||
get '/inheritance_base' => 'inheritance_base';
|
||||
|
||||
get '/inheritance_derived' => 'inheritance_derived';
|
||||
|
||||
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");
|
||||
|
||||
# Inheritance
|
||||
$t->get_ok('/inheritance_base')->content_is("untouched");
|
||||
$t->get_ok('/inheritance_derived')->content_is("edited");
|
||||
|
||||
# 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 -%]
|
||||
|
||||
@@ layouts/auto_layout.html.tt
|
||||
w[%- h.content -%]d
|
||||
|
||||
@@ auto_wrapper.html.tt
|
||||
[% CALL h.layout('auto_layout') %]
|
||||
rappe
|
||||
|
||||
@@ inheritance_base.html.tt
|
||||
[% verb = BLOCK %]untouch[% END %]
|
||||
[% h.content('verb', verb) %]ed
|
||||
|
||||
@@ inheritance_derived.html.tt
|
||||
[% CALL h.extends('inheritance_base') %]
|
||||
[% verb = BLOCK %]edit[% END %]
|
||||
[% h.content('verb', verb) %]
|
||||
|
||||
@@ unicode.html.tt
|
||||
привет
|
||||
|
||||
@@ helpers.html.tt
|
||||
[% h.url_for('helpers') %]
|
||||
|
||||
@@ unknown_helper.html.tt
|
||||
[% h.unknown_helper('foo') %]
|
||||
39
t/render.t
39
t/render.t
@@ -1,39 +0,0 @@
|
||||
#!perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More tests => 6;
|
||||
|
||||
use Mojolicious;
|
||||
use Mojolicious::Controller;
|
||||
use MojoX::Renderer;
|
||||
|
||||
use_ok('MojoX::Renderer::TT');
|
||||
|
||||
my $c = Mojolicious::Controller->new(app => Mojolicious->new);
|
||||
$c->app->log->path(undef);
|
||||
$c->app->log->level('fatal');
|
||||
|
||||
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);
|
||||
|
||||
delete $c->stash->{template_path};
|
||||
|
||||
$c->app->renderer->root('./')->add_handler(tt2 => $mt);
|
||||
|
||||
is($c->render('t/render/template','partial' => 1,handler => 'tt2'),"4\n");
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
[% = 2 %]
|
||||
@@ -1 +0,0 @@
|
||||
[% 2 + 2 %]
|
||||
1
t/templates/index.html.tt
Normal file
1
t/templates/index.html.tt
Normal file
@@ -0,0 +1 @@
|
||||
test123[% 456 %]
|
||||
39
t/tt_plugin_lite_app.t
Normal file
39
t/tt_plugin_lite_app.t
Normal file
@@ -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