[Catalyst-commits] r11359 - in Catalyst-View-TT/trunk: . lib/Catalyst/View t

marcus at dev.catalyst.perl.org marcus at dev.catalyst.perl.org
Sat Sep 12 21:47:18 GMT 2009


Author: marcus
Date: 2009-09-12 21:47:18 +0000 (Sat, 12 Sep 2009)
New Revision: 11359

Modified:
   Catalyst-View-TT/trunk/Changes
   Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm
   Catalyst-View-TT/trunk/t/11norequest.t
Log:
Add support for running render without a context

Modified: Catalyst-View-TT/trunk/Changes
===================================================================
--- Catalyst-View-TT/trunk/Changes	2009-09-12 20:57:04 UTC (rev 11358)
+++ Catalyst-View-TT/trunk/Changes	2009-09-12 21:47:18 UTC (rev 11359)
@@ -11,6 +11,7 @@
         - Expand TTSite documentation (RT #33838)
         - Added a test for direct rendering of a template from a view object,
           without a request.
+        - Added support for running render with a undef context.
 
 0.29    2009-02-20 14:43:00
         - Remove extra unwanted .gitignore from manifest

Modified: Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm
===================================================================
--- Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm	2009-09-12 20:57:04 UTC (rev 11358)
+++ Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm	2009-09-12 21:47:18 UTC (rev 11359)
@@ -228,7 +228,7 @@
 sub render {
     my ($self, $c, $template, $args) = @_;
 
-    $c->log->debug(qq/Rendering template "$template"/) if $c->debug;
+    $c->log->debug(qq/Rendering template "$template"/) if $c && $c->debug;
 
     my $output;
     my $vars = {
@@ -250,6 +250,7 @@
 sub template_vars {
     my ( $self, $c ) = @_;
 
+    return  () unless $c;
     my $cvar = $self->config->{CATALYST_VAR};
 
     defined $cvar
@@ -500,6 +501,9 @@
 process, including the name of a template file or a reference to a test string.
 See L<Template::process|Template/process> for a full list of supported formats.
 
+To use the render method outside of your Catalyst app, just pass a undef context. 
+This can be useful for tests, for instance.
+
 =head2 template_vars
 
 Returns a list of keys/values to be used as the catalyst variables in the

Modified: Catalyst-View-TT/trunk/t/11norequest.t
===================================================================
--- Catalyst-View-TT/trunk/t/11norequest.t	2009-09-12 20:57:04 UTC (rev 11358)
+++ Catalyst-View-TT/trunk/t/11norequest.t	2009-09-12 21:47:18 UTC (rev 11359)
@@ -1,13 +1,12 @@
 use strict;
 use warnings;
-use Test::More tests => 4;
+use Test::More tests => 3;
 
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
 BEGIN { use_ok 'TestApp' or die }
 
-ok my $c  = TestApp->new, 'Instantiate app object';
-ok my $tt = $c->view('TT'), 'Get TT view object';
-is $tt->render($c, 'test.tt', { message => 'hello' }), 'hello',
+ok my $tt = TestApp->view('TT'), 'Get TT view object';
+is $tt->render(undef, 'test.tt', { message => 'hello' }), 'hello',
     'render() should return the template output';




More information about the Catalyst-commits mailing list