Compare commits

...
Author SHA1 Message Date
Ask Bjørn Hansen 392b97e81a Ignore .ttc files from tests 2011-02-05 12:22:44 -08:00
Ask Bjørn Hansen a5e276f633 Update Changes 2011-02-05 12:20:42 -08:00
Ask Bjørn Hansen fc453fe4fb Try fixing tests on Strawberry Perl (RT#65282)
(thanks Christiaan Kras)
2011-02-05 12:12:47 -08:00
Ask Bjørn Hansen 32c83d6109 Fix bugtracker URL in META.yml 2011-02-05 12:11:05 -08:00
Maxim VuetsandAsk Bjørn Hansen 5e5c23d786 Make Mojolicious 'layout'/'extends' working 2011-02-05 10:02:09 -08:00
Ask Bjørn Hansen fa30565b6b 1.0 released 2011-01-22 17:14:48 -08:00
Ask Bjørn Hansen a0d8b522ff Update Changes 2011-01-22 17:13:27 -08:00
Ask Bjørn Hansen 388422491f Require Mojolicious 1.0+ 2011-01-22 10:47:00 -08:00
Ask Bjørn Hansen 1e7dc3044b Merge remote branch 'marcusramberg/master' 2011-01-22 10:33:09 -08:00
Marcus Ramberg 01b8f94a2b Fix inline rendering and test failures 2011-01-22 17:50:08 +01:00
Marcus Ramberg 26d555938f Fix unicode test 2011-01-22 14:42:42 +01:00
Marcus Ramberg 0d419c9ecd Support new mojolicious error template 2011-01-22 14:42:15 +01:00
Ask Bjørn Hansen 0708cfd051 Set repository and bug tracker URLs for the META.yml file 2011-01-17 10:19:11 -08:00
Ask Bjørn Hansen 3495571029 Update Changes 2010-12-27 14:53:35 -08:00
Árpád Szász d51eea608b Fixed helper compatibility with Mojolicious 1.0 2010-12-28 00:28:50 +02:00
Marcus RambergandAsk Bjørn Hansen c3e8c9ff73 Tests for plugin 2010-10-10 06:02:54 +08:00
Maxim VuetsandAsk Bjørn Hansen 0588884a9f Fix POD synopsis 2010-10-09 14:50:25 -07:00
spleenjackandAsk Bjørn Hansen 084c79825f Replaced deprecated Mojo dependence with Mojolicious 2010-10-09 14:43:52 -07:00
Ask Bjørn Hansen 3bddf34485 'inline' argument is in stash, not in options for _render() 2010-10-05 00:38:44 -07:00
vti 201774941a Added inline template support 2010-10-05 09:02:39 +02:00
Ask Bjørn Hansen be2d2ed0ec Add release date to Changes 2010-08-02 02:10:00 -07:00
8 changed files with 131 additions and 30 deletions
+18 -3
View File
@@ -1,6 +1,21 @@
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
@@ -22,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
+6 -3
View File
@@ -6,7 +6,7 @@ copyright_holder = Ask Bjørn Hansen
# copyright_year = 2009
[Prereqs]
Mojo = 0.999926
Mojolicious = 1.01
Template = 2.18
[Prereqs / TestRequires ]
@@ -21,8 +21,11 @@ bundle = @Basic
remove = Readme
remove = Manifest
[Repository]
[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]
+30 -15
View File
@@ -5,8 +5,9 @@ use strict;
use base 'Mojo::Base';
use Template ();
use File::Spec ();
use Mojo::ByteStream 'b';
use Template ();
__PACKAGE__->attr('tt');
@@ -51,29 +52,39 @@ sub _init {
return $self;
}
use Data::Dumper;
sub _render {
my ($self, $renderer, $c, $output, $options) = @_;
# Inline
my $inline = $options->{inline};
# Template
return unless my $t = $renderer->template_name($options);
return unless my $path = $renderer->template_path($options);
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($path, @params);
my $ok = $self->tt->process(defined $inline ? \$inline : $path, @params);
# Error
unless ($ok) {
my $e = $self->tt->error;
if ($e =~ m/not found/) {
$c->app->log->error(qq/Template "$t" missing or not readable./);
$c->render_not_found;
return;
}
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);
@@ -109,9 +120,9 @@ sub AUTOLOAD {
$method = (split '::' => $method)[-1];
die qq/Unknown helper: $method/ unless $self->ctx->app->renderer->helper->{$method};
die qq/Unknown helper: $method/ unless $self->ctx->app->renderer->helpers->{$method};
return $self->ctx->helper($method => @_);
return $self->ctx->$method(@_);
}
1;
@@ -144,7 +155,7 @@ sub _template_content {
my $self = shift;
my ($path) = @_;
my ($t) = ($path =~ m{templates\/(.*)$});
my ($t) = ($path =~ m{templates[\/|\\](.*)$});
if (-r $path) {
return $self->SUPER::_template_content(@_);
@@ -179,7 +190,7 @@ Add the handler:
...
# Via mojolicious plugin
$self->plugin(tt_renderer => {FILTERS => [ ... ]});
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
# Or manually
use MojoX::Renderer::TT;
@@ -210,6 +221,10 @@ When template file is not available rendering from C<__DATA__> is attempted.
@@ 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.
+2 -2
View File
@@ -31,11 +31,11 @@ Mojolicious::Plugin::TtRenderer - Template Renderer Plugin
# Mojolicious
$self->plugin('tt_renderer');
$self->plugin(tt_renderer => {FILTERS => [ ... ]});
$self->plugin(tt_renderer => {template_options => {FILTERS => [ ... ]}});
# Mojolicious::Lite
plugin 'tt_renderer';
plugin tt_renderer => {FILTERS => [ ... ]};
plugin tt_renderer => {template_options => {FILTERS => [ ... ]}};
=head1 DESCRIPTION
+2
View File
@@ -0,0 +1,2 @@
/tmp/
*.ttc
+33 -7
View File
@@ -5,7 +5,7 @@ use warnings;
use utf8;
use Test::More tests => 22;
use Test::More tests => 31;
use Mojolicious::Lite;
use Mojo::ByteStream 'b';
@@ -24,7 +24,11 @@ get '/with_include' => 'include';
get '/with_wrapper' => 'wrapper';
#get '/with_auto_wrapper' => sub { shift->render(auto_wrapper => layout => 'layout') };
get '/with_auto_wrapper' => 'auto_wrapper';
get '/inheritance_base' => 'inheritance_base';
get '/inheritance_derived' => 'inheritance_derived';
get '/unicode' => 'unicode';
@@ -34,7 +38,9 @@ get '/unknown_helper' => 'unknown_helper';
get '/on-disk' => 'foo';
get '/foo/:message' => 'index';
get '/bar/:message' => 'bar';
get '/inline' => sub { shift->render(inline => '[% 1 + 1 %]', handler => 'tt') };
my $t = Test::Mojo->new;
@@ -42,7 +48,7 @@ my $t = Test::Mojo->new;
$t->get_ok('/exception')->status_is(500)->content_like(qr/error/i);
# Normal rendering
$t->get_ok('/foo/hello')->content_is("hello");
$t->get_ok('/bar/hello')->content_is("hello");
# With include
$t->get_ok('/with_include')->content_is("HelloInclude!Hallo");
@@ -51,10 +57,14 @@ $t->get_ok('/with_include')->content_is("HelloInclude!Hallo");
$t->get_ok('/with_wrapper')->content_is("wrapped");
# With auto wrapper
#$t->get_ok('/with_auto_wrapper')->content_is("wrapped");
$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(b("привет")->encode('UTF-8')->to_string);
$t->get_ok('/unicode')->content_is("привет");
# Helpers
$t->get_ok('/helpers')->content_is("/helpers");
@@ -68,9 +78,12 @@ $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__
@@ index.html.tt
@@ bar.html.tt
[% message %]
@@ error.html.tt
@@ -95,9 +108,22 @@ w[%- content -%]d
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
привет
+1
View File
@@ -0,0 +1 @@
test123[% 456 %]
+39
View 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/);