Compare commits

..
Author SHA1 Message Date
Ask Bjørn Hansen 944fa2ecae Update Changes for v1.21 2012-06-05 16:25:52 -07:00
Ask Bjørn Hansen 3364b8a05a Remove Test::DistManifest Dist::Zilla plugin 2012-06-05 16:23:42 -07:00
Ask Bjørn Hansen 6047db4ef2 Add MYMETA.* to MANIFEST.SKIP 2012-06-05 16:21:43 -07:00
Ask Bjørn Hansen b37a7639d3 Update dist.ini to use new names for some plugins 2012-06-05 16:12:58 -07:00
Ask Bjørn Hansen 511ee4463b Let Dist::Zilla set VERSION
Closes #17
2012-06-05 16:04:07 -07:00
Ask Bjørn Hansen bdc9f56452 Use app->renderer->paths to find template directories
Closes #20
2012-06-05 15:53:08 -07:00
Ask Bjørn Hansen 618adbd774 "Manually" install dependencies 2012-06-05 15:19:58 -07:00
Ask Bjørn Hansen c0b649d55f Add travis-ci configuration 2012-06-05 15:15:21 -07:00
Ask Bjørn Hansen 1e1a9ab835 Merge pull request #23 from mbethke/master
Fix error handling problem

(closes #22)
2012-06-05 15:08:42 -07:00
Matthias Bethke 96d31d45a0 Added template for render error test 2012-05-18 00:41:21 -06:00
Matthias Bethke bbfab8db4e Checking HTTP status code for TT render error test 2012-05-18 00:40:50 -06:00
Matthias Bethke 92bb64406b Checking HTTP status code in TT render error test 2012-05-18 00:37:18 -06:00
Matthias Bethke 989ea57cf9 Fixed double TT rendering on error
If a template produced a rendering error in process() but did not produce one
when called without stash variables, the Mojo::Exception would be built
incorrectly, leading to an exception that masked the original error.
2012-05-17 14:00:17 -06:00
Ask Bjørn Hansen b3c64c75d4 Require Mojolicious 2.51 to avoid memory leak
Closes #19
2012-02-22 08:09:40 -08:00
Ask Bjørn Hansen a89a9a4344 Merge pull request #21 from marcusramberg/move_cache
Cache templates in tmpdir by default
2012-02-01 01:17:52 -08:00
Marcus Ramberg 78c9d24bc7 Cache templates in tmpdir by default 2012-01-25 15:11:11 +01:00
Ask Bjørn Hansen 859ec53953 Note fixes from Magnus Holm in Changes 2011-10-08 21:05:18 -07:00
Ask Bjørn Hansen 0b0acd510e Document the 'c' stash variable (RT#70866, Matthias Bethke) 2011-10-08 21:04:17 -07:00
Ask Bjørn Hansen 0527eee24a Merge pull request #18 from judofyr/cycles
Fix memory leaks
2011-09-07 09:51:25 -07:00
Magnus Holm bd48aa5066 Fix cycles 2011-09-07 11:05:55 +02:00
Magnus Holm 77b9531fae Add test case for cycles 2011-09-07 11:04:25 +02:00
Ask Bjørn Hansen 248f13717a Mark 1.20 in Changes 2011-08-01 09:37:07 -07:00
8 changed files with 68 additions and 20 deletions
+8
View File
@@ -0,0 +1,8 @@
language: perl
install:
- cpanm Mojolicious Template
script: HARNESS_IS_VERBOSE=1 prove -v -Ilib t
perl:
- "5.14"
- "5.12"
- "5.10"
+8 -2
View File
@@ -1,8 +1,14 @@
Revision history for MojoX-Renderer-TT
Revision history for Mojolicious::Plugin::TtRenderer
{{$NEXT}}
- Fixed double TT rendering on error (Matthias Bethke (GH#21))
- Cache templates in tmpdir by default (Marcus Ramberg)
- Require Mojolicious 2.51 to avoid memory leaks (GH#19)
- Document the 'c' stash variable (RT#70866, Matthias Bethke)
- Fix memory leaks, add tests for them (GH#18, Magnus Holm)
- Use app->renderer->paths to find template directories (GH#17)
1.14 August 1, 2011
1.20 August 1, 2011
- Drop use of MojoX namespace for Mojolicious::Plugin::TtRenderer::
(GH#12, Cosimo Streppone)
+1 -3
View File
@@ -9,6 +9,7 @@
# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMYMETA.*
\bMakefile$
\bblib/
\bMakeMaker-\d
@@ -41,6 +42,3 @@ t/tmp/ctpl
\.t\.log$
\.prove$
# XS shit
\.(?:bs|c|o)$
+2 -3
View File
@@ -6,7 +6,7 @@ copyright_holder = Ask Bjørn Hansen
# copyright_year = 2009
[Prereqs]
Mojolicious = 1.3
Mojolicious = 2.51
Template = 2.18
[Prereqs / TestRequires ]
@@ -35,8 +35,7 @@ version_regexp = ^release/(.*)
[PkgVersion]
[CheckChangeLog]
[CompileTests]
[DistManifestTests]
[Test::Compile]
[HasVersionTests]
[MetaTests]
[ReadmeFromPod]
+8 -2
View File
@@ -3,8 +3,6 @@ package Mojolicious::Plugin::TtRenderer;
use strict;
use warnings;
our $VERSION = '0.01';
use base 'Mojolicious::Plugin';
use Mojolicious::Plugin::TtRenderer::Engine;
@@ -20,6 +18,8 @@ sub register {
$app->renderer->add_handler(tt => $tt);
}
local ($Mojolicious::Plugin::TtRenderer::VERSION) = ('devel') unless defined $Mojolicious::Plugin::TtRenderer::VERSION;
1;
__END__
@@ -52,6 +52,12 @@ L<Mojolicious::Plugin> and implements the following new ones.
Register renderer in L<Mojolicious> application.
=head1 EXTRA STASH VARIABLES
The current controller instance can be accessed as C<c>.
[% c.req.headers.host %]
=head1 SEE ALSO
L<Mojolicious::Plugin::TtRenderer::Engine>, L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
+21 -7
View File
@@ -10,11 +10,13 @@ use File::Spec ();
use Mojo::ByteStream 'b';
use Template ();
use Cwd qw/abs_path/;
use Scalar::Util 'weaken';
__PACKAGE__->attr('tt');
sub build {
my $self = shift->SUPER::new(@_);
weaken($self->{app});
$self->_init(@_);
return sub { $self->_render(@_) }
}
@@ -25,15 +27,23 @@ sub _init {
#$Template::Parser::DEBUG = 1;
my $dir;
my $app = delete $args{mojo} || delete $args{app};
my $dir = $app && $app->home->rel_dir('tmp/ctpl');
if($dir=$args{cache_dir}) {
if($app && substr($dir,0,1) ne '/') {
$dir=$app->home->rel_dir('tmp/ctpl');
}
}
# TODO
# take and process options :-)
my %config = (
($app ? (INCLUDE_PATH => abs_path($app->home->rel_dir('templates'))) : ()),
( $app
? (INCLUDE_PATH => (join ":", map { abs_path($_) } @{$app->renderer->paths}))
: ()
),
COMPILE_EXT => '.ttc',
COMPILE_DIR => ($dir || abs_path(File::Spec->tmpdir)),
UNICODE => 1,
@@ -78,9 +88,7 @@ sub _render {
# Error
unless ($ok) {
my $e = Mojo::Exception->new(
$self->tt->error.'',
$self->tt->service->process(defined $inline ? \$inline : $t));
my $e = Mojo::Exception->new($self->tt->error.'');
$$output = '';
$c->app->log->error(qq/Template error in "$t": $e/);
$c->render_exception($e);
@@ -130,6 +138,7 @@ use strict;
use warnings;
use base 'Template::Provider';
use Scalar::Util 'weaken';
sub new {
my $class = shift;
@@ -139,6 +148,7 @@ sub new {
my $self = $class->SUPER::new(%params);
$self->renderer($renderer);
weaken($self->{renderer});
return $self;
}
@@ -247,6 +257,11 @@ object. When used the INCLUDE_PATH will be set to
A hash reference of options that are passed to Template->new().
=item cache_dir
Absolute or relative dir to your app home, to cache processed versions of your
templates. Will default to a temp-dir if not set.
=back
=head1 AUTHOR
@@ -256,7 +271,6 @@ Ask Bjørn Hansen, C<< <ask at develooper.com> >>
=head1 TODO
* Better support non-Mojolicious frameworks
* Move the default template cache directory?
* Better way to pass parameters to the templates? (stash)
* More sophisticated default search path?
@@ -0,0 +1,4 @@
foo
[% PROCESS doesnotexist.tt IF do_process %]
bar
+16 -3
View File
@@ -15,7 +15,7 @@ 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;
plan tests => 6;
# 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?
@@ -30,10 +30,23 @@ plugin 'tt_renderer';
app->log->level('error');
# GET /
get '/' => 'index';
get '/' => 'index';
get '/blow' => sub {
shift->render(template => 'conditional-exception', do_process => 1);
};
my $t = Test::Mojo->new;
# Simple TT template
$t->get_ok('/')->status_is(200)
->content_like(qr/test123456/);
->content_like(qr/test123456/);
$t->get_ok('/blow')->status_is(500)->content_like(qr/file error - doesnotexist.tt: No such file or directory/);
eval "
use Devel::Cycle 'find_cycle';
find_cycle(app, sub {
ok(0, 'Cycle found');
});
";