X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FView%2FTT.pm;h=d1353e4def360c619ed683a9e2d9bf0064337bfe;hb=bec996dce4ec70ea8376fbc60b7ca82e530a8af7;hp=0938f628e903c0c0873041f56867f03266174b74;hpb=7d6076711bcd17f008b159d46b0df1103d43590f;p=catagits%2FCatalyst-View-TT.git diff --git a/lib/Catalyst/View/TT.pm b/lib/Catalyst/View/TT.pm index 0938f62..d1353e4 100644 --- a/lib/Catalyst/View/TT.pm +++ b/lib/Catalyst/View/TT.pm @@ -1,14 +1,15 @@ package Catalyst::View::TT; use strict; -use base qw/Catalyst::Base/; +use base qw/Catalyst::View/; use Template; use Template::Timer; use NEXT; -our $VERSION = '0.14'; +our $VERSION = '0.20'; __PACKAGE__->mk_accessors('template'); +__PACKAGE__->mk_accessors('include_path'); =head1 NAME @@ -21,19 +22,18 @@ Catalyst::View::TT - Template View Class # configure in lib/MyApp.pm - our $ROOT = '/home/dent/catalyst/MyApp'; - MyApp->config({ name => 'MyApp', - root => $ROOT, + root => MyApp->path_to('root');, 'V::TT' => { # any TT configurations items go here INCLUDE_PATH => [ - "$ROOT/templates/src", - "$ROOT/templates/lib" + MyApp->path_to( 'root', 'src' ), + MyApp->path_to( 'root', 'lib' ), ], - PRE_PROCESS => 'config/main', - WRAPPER => 'site/wrapper', + PRE_PROCESS => 'config/main', + WRAPPER => 'site/wrapper', + TEMPLATE_EXTENSION => '.tt', # two optional config items CATALYST_VAR => 'Catalyst', @@ -109,10 +109,11 @@ happens when the module is first loaded. use strict; use base 'Catalyst::View::TT'; - our $ROOT = '/home/dent/catalyst/MyApp'; - MyApp::V::TT->config({ - INCLUDE_PATH => ["$ROOT/templates/src", "$ROOT/templates/lib"], + INCLUDE_PATH => [ + MyApp->path_to( 'root', 'templates', 'lib' ), + MyApp->path_to( 'root', 'templates', 'src' ), + ], PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', }); @@ -126,7 +127,10 @@ performing any configuration. sub new { my $self = shift; $self->config({ - INCLUDE_PATH => ["$ROOT/templates/src", "$ROOT/templates/lib"], + INCLUDE_PATH => [ + MyApp->path_to( 'root', 'templates', 'lib' ), + MyApp->path_to( 'root', 'templates', 'src' ), + ], PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', }); @@ -146,13 +150,14 @@ subclass). use strict; use Catalyst; - our $ROOT = '/home/dent/catalyst/MyApp'; - MyApp->config({ name => 'MyApp', - root => $ROOT, + root => MyApp->path_to('root'), 'V::TT' => { - INCLUDE_PATH => ["$ROOT/templates/src", "$ROOT/templates/lib"], + INCLUDE_PATH => [ + MyApp->path_to( 'root', 'templates', 'lib' ), + MyApp->path_to( 'root', 'templates', 'src' ), + ], PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', }, @@ -162,6 +167,15 @@ Note that any configuration items defined by one of the earlier methods will be overwritten by items of the same name provided by the latter methods. +=head2 DYNAMIC INCLUDE_PATH + +It is sometimes needed to dynamically add additional paths to the +INCLUDE_PATH variable of the template object. This can be done by setting +'additional_include_paths' on stash to a referrence to an array with +additional paths: + + $c->stash->{additional_template_paths} = [$c->config->{root} . '/test_include_path']; + =head2 RENDERING VIEWS The view plugin renders the template specified in the C