View::TT, added tests from dwc
[catagits/Catalyst-View-TT.git] / lib / Catalyst / View / TT.pm
index 87f7cc0..6b7a828 100644 (file)
@@ -1,12 +1,12 @@
 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');
 
@@ -21,19 +21,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 +108,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 +126,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 +149,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',
         },
@@ -225,9 +229,9 @@ sub new {
     my $root = $c->config->{root};
 
     my $config = {
-        EVAL_PERL    => 0,
+        EVAL_PERL          => 0,
         TEMPLATE_EXTENSION => '',
-        INCLUDE_PATH => [ $root, "$root/base" ],
+        INCLUDE_PATH       => [ $root, "$root/base" ],
         %{ $class->config },
         %{$arguments}
     };
@@ -251,7 +255,7 @@ sub new {
         $c->log->debug( "TT Config: ", Dumper($config) );
     }
 
-    return $class->NEXT::new(
+    my $self = $class->NEXT::new(
         $c,
         {
             template => Template->new($config) || do {
@@ -259,9 +263,13 @@ sub new {
                 $c->log->error($error);
                 $c->error($error);
                 return undef;
-              }
-        }
+              },
+        %{$config},
+        },
     );
+    $self->config($config);
+
+    return $self;
 }
 
 =item process
@@ -281,7 +289,8 @@ Output is stored in C<$c-E<gt>response-E<gt>output>.
 sub process {
     my ( $self, $c ) = @_;
 
-    my $template = $c->stash->{template} || $c->request->match . $self->config->{TEMPLATE_EXTENSION};
+    my $template = $c->stash->{template}
+      || $c->request->match . $self->config->{TEMPLATE_EXTENSION};
 
     unless ($template) {
         $c->log->debug('No template specified for rendering') if $c->debug;
@@ -336,7 +345,7 @@ For example:
 
     MyApp->config({
         name     => 'MyApp',
-        root     => $ROOT,
+        root     => MyApp->path_to('root'),
         'V::TT' => {
             CATALYST_VAR => 'Catalyst',
         },
@@ -367,7 +376,7 @@ output from your templates, such as:
 
 =item C<TEMPLATE_EXTENSION>
 
-an extension to add when looking for templates bases on the C<match> method in L<Catalyst::Request>.
+a sufix to add when looking for templates bases on the C<match> method in L<Catalyst::Request>.
 
 For example: