[Jifty-commit] r3100 - in Template-Declare: lib/Template lib/Template/Declare t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Apr 6 06:36:36 EDT 2007


Author: jesse
Date: Fri Apr  6 06:36:26 2007
New Revision: 3100

Modified:
   Template-Declare/   (props changed)
   Template-Declare/lib/Template/Declare.pm
   Template-Declare/lib/Template/Declare/Tags.pm
   Template-Declare/t/private.t
   Template-Declare/t/subclassing.t
   Template-Declare/t/trivial.t

Log:
 r54517 at dhcp207:  jesse | 2007-04-06 19:36:06 +0900
 * Better handling of 'private' templates for gugod


Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Fri Apr  6 06:36:26 2007
@@ -201,7 +201,7 @@
 sub show {
     my $class = shift;
     my $template = shift;
-    return Template::Declare::Tags::show($template);
+    return Template::Declare::Tags::show_page($template);
 }
 
 

Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Fri Apr  6 06:36:26 2007
@@ -403,40 +403,66 @@
 templates are accessible and visible. If called from something that
 isn't a Template::Declare, only public templates wil be visible.
 
+From the outside world, users can either call "Template::Declare->show()" or Template::Declare::tags::show()" to render a publicly visible template.
+
+"private" templates may only be called from within the C<Template::Declare>
+package.
+
+
 =cut
 
 sub show {
     my $template = shift;
-
     my $INSIDE_TEMPLATE = 0;
+    # if we're inside a template, we should show private templates
+    if ( caller->isa('Template::Declare') ) {
+        $INSIDE_TEMPLATE = 1;
+    } else {
+        Template::Declare->new_buffer_frame;
+    }
+    _show_template($template, $INSIDE_TEMPLATE);
+    my $data = Template::Declare->buffer->data;
+    unless ($INSIDE_TEMPLATE) { Template::Declare->end_buffer_frame }
+    return $data;
+}
 
+sub show_page {
+    my $template = shift;
+    my $INSIDE_TEMPLATE = 0;
     # if we're inside a template, we should show private templates
-    if ( caller()->isa('Template::Declare') ) { $INSIDE_TEMPLATE = 1; }
-    else { Template::Declare->new_buffer_frame }
+        Template::Declare->new_buffer_frame;
+    _show_template($template, 0);
+    my $data = Template::Declare->buffer->data;
+     Template::Declare->end_buffer_frame;
+    Template::Declare->buffer->append($data);
+    return $data;
+
+}
+
+sub _show_template {
+	my $template = shift;
+  	my $INSIDE_TEMPLATE = shift;
 
     my $callable =
-        (ref($template) && $template->isa('Template::Declare::Tag'))
+        ( ref($template) && $template->isa('Template::Declare::Tag') )
         ? $template
         : Template::Declare->has_template( $template, $INSIDE_TEMPLATE );
 
     # If the template was not found let the user know.
-    unless ( $callable ) {        
+    unless ($callable) {
         my $msg = "The template '$template' could not be found";
         $msg .= " (it might be private)" if !$INSIDE_TEMPLATE;
         carp $msg;
         return '';
     }
 
-        Template::Declare->new_buffer_frame;
-        &$callable($self);
-        my $content = Template::Declare->buffer->data;
-        Template::Declare->end_buffer_frame;
-        Template::Declare->buffer->append( $content);
-    my $data =  Template::Declare->buffer->data;
-    unless ($INSIDE_TEMPLATE) {  Template::Declare->end_buffer_frame  }
-    return $data;
-}
+    Template::Declare->new_buffer_frame;
+    &$callable($self);
+    my $content = Template::Declare->buffer->data;
+    Template::Declare->end_buffer_frame;
+    Template::Declare->buffer->append($content);
 
+}
 sub _escape_utf8 {
     my $val = shift;
     use bytes;

Modified: Template-Declare/t/private.t
==============================================================================
--- Template-Declare/t/private.t	(original)
+++ Template-Declare/t/private.t	Fri Apr  6 06:36:26 2007
@@ -40,7 +40,7 @@
 use Template::Declare::Tags;
 Template::Declare->init(roots => ['Wifty::UI']);
 
-use Test::More tests => 12;
+use Test::More tests => 15;
 use Test::Warn;
 require "t/utils.pl";
 
@@ -78,5 +78,16 @@
     ok_lint($simple);
 }
 
+{
+    my $simple;
+      $simple = ( Template::Declare->show('private-content') ); 
+    warning_like
+      { $simple = ( Template::Declare->show('private-content') ); }
+      qr/could not be found.*private/,
+      "got warning";
+    unlike( $simple , qr'This is my content', "Can't call private templates" );
+    is($simple, undef);
+}
+
 
 1;

Modified: Template-Declare/t/subclassing.t
==============================================================================
--- Template-Declare/t/subclassing.t	(original)
+++ Template-Declare/t/subclassing.t	Fri Apr  6 06:36:26 2007
@@ -79,7 +79,7 @@
       qr/could not be found.*private/,
       "got warning";
     unlike( $simple , qr'This is my content' );
-    ok_lint($simple);
+    is ($simple, undef);
 }
 
 {

Modified: Template-Declare/t/trivial.t
==============================================================================
--- Template-Declare/t/trivial.t	(original)
+++ Template-Declare/t/trivial.t	Fri Apr  6 06:36:26 2007
@@ -159,7 +159,9 @@
 }
 {
 Template::Declare->buffer->clear;
-Template::Declare->show('simple');
+my $ret = Template::Declare->show('simple');
+#diag $ret;
+#diag (Template::Declare->buffer->data());
 ok(Template::Declare->buffer->data() =~ 'This is my content', "show simple filled the buffer");
 #diag ($simple);
 ok_lint(Template::Declare->buffer->data());


More information about the Jifty-commit mailing list