Added default extension configuration option.
Marcus Ramberg [Tue, 1 Nov 2005 14:41:41 +0000 (14:41 +0000)]
Changes
lib/Catalyst/View/TT.pm

diff --git a/Changes b/Changes
index 6f8cb0a..3494bf7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Catalyst::View::TT.
 
+0.15  - TBR
+        - Fix docs
+        - Added TEMPLATE_EXTENSION config variable 
+
 0.14  - Fri Oct 21 10:20:00 2005
         - Turn timer off by default, even for debug.
        - removed superflous 'templates' inside 'root'
index 0938f62..87f7cc0 100644 (file)
@@ -202,52 +202,12 @@ These can be accessed from the template in the usual way:
     The base is [% base %]
     The name is [% name %]
 
-If you prefer, you can set the C<CATALYST_VAR> configuration item to
-define the name of a template variable through which the context can
-be referenced.
-
-    MyApp->config({
-        name     => 'MyApp',
-        root     => $ROOT,
-        'V::TT' => {
-            CATALYST_VAR => 'Catalyst',
-        },
-    });
-
-F<message.tt2>:
-
-    The base is [% Catalyst.req.base %]
-    The name is [% Catalyst.config.name %]
 
 The output generated by the template is stored in
 C<$c-E<gt>response-E<gt>output>.
 
 =head2 TEMPLATE PROFILING
 
-If you have configured Catalyst for debug output,
-C<Catalyst::View::TT> will enable profiling of template processing
-(using L<Template::Timer>). This will embed HTML comments in the
-output from your templates, such as:
-
-    <!-- TIMER START: process mainmenu/mainmenu.ttml -->
-    <!-- TIMER START: include mainmenu/cssindex.tt -->
-    <!-- TIMER START: process mainmenu/cssindex.tt -->
-    <!-- TIMER END: process mainmenu/cssindex.tt (0.017279 seconds) -->
-    <!-- TIMER END: include mainmenu/cssindex.tt (0.017401 seconds) -->
-
-    ....
-
-    <!-- TIMER END: process mainmenu/footer.tt (0.003016 seconds) -->
-
-You can suppress template profiling by setting the C<TIMER> configuration
-item to a false value.
-
-    MyApp->config({
-        'V::TT' => {
-            TIMER => 0,
-        },
-    });
-
 =head2 METHODS
 
 =over 4
@@ -266,6 +226,7 @@ sub new {
 
     my $config = {
         EVAL_PERL    => 0,
+        TEMPLATE_EXTENSION => '',
         INCLUDE_PATH => [ $root, "$root/base" ],
         %{ $class->config },
         %{$arguments}
@@ -320,7 +281,7 @@ 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;
+    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;
@@ -362,8 +323,61 @@ sub process {
 =item config
 
 This method allows your view subclass to pass additional settings to
-the TT configuration hash, or to set the C<CATALYST_VAR> and C<TIMER>
-options.
+the TT configuration hash, or to set the options as below:
+
+=over 2
+
+=item C<CATALYST_VAR> 
+
+Allows you to change the name of the Catalyst context object. If set, it will also
+remove the base and name aliases, so you will have access them through <context>.
+
+For example:
+
+    MyApp->config({
+        name     => 'MyApp',
+        root     => $ROOT,
+        'V::TT' => {
+            CATALYST_VAR => 'Catalyst',
+        },
+    });
+
+F<message.tt2>:
+
+    The base is [% Catalyst.req.base %]
+    The name is [% Catalyst.config.name %]
+
+=item C<TIMER>
+
+If you have configured Catalyst for debug output, and turned on the TIMER setting,
+C<Catalyst::View::TT> will enable profiling of template processing
+(using L<Template::Timer>). This will embed HTML comments in the
+output from your templates, such as:
+
+    <!-- TIMER START: process mainmenu/mainmenu.ttml -->
+    <!-- TIMER START: include mainmenu/cssindex.tt -->
+    <!-- TIMER START: process mainmenu/cssindex.tt -->
+    <!-- TIMER END: process mainmenu/cssindex.tt (0.017279 seconds) -->
+    <!-- TIMER END: include mainmenu/cssindex.tt (0.017401 seconds) -->
+
+    ....
+
+    <!-- TIMER END: process mainmenu/footer.tt (0.003016 seconds) -->
+
+
+=item C<TEMPLATE_EXTENSION>
+
+an extension to add when looking for templates bases on the C<match> method in L<Catalyst::Request>.
+
+For example:
+
+  package MyApp::C::Test;
+  sub test : Local { .. } 
+
+Would by default look for a template in <root>/test/test. If you set TEMPLATE_EXTENSION to '.tt', it will look for
+<root>/test/test.tt.
+
+=back
 
 =back