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

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


Author: jesse
Date: Fri Apr  6 10:04:34 2007
New Revision: 3101

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

Log:
 r54523 at dhcp207:  jesse | 2007-04-06 23:04:19 +0900
 * Patch from gugod++ to perform detection of duplicate html id elements


Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Fri Apr  6 10:04:34 2007
@@ -201,6 +201,7 @@
 sub show {
     my $class = shift;
     my $template = shift;
+    local %Template::Declare::Tags::ELEMENT_ID_CACHE = () ;
     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 10:04:34 2007
@@ -12,9 +12,9 @@
 push @EXPORT, qw(Tr td );    # these two warns the user to use row/cell instead
 
 our %ATTRIBUTES = ();
+our %ELEMENT_ID_CACHE = ();
 our $DEPTH      = 0;
 
-
 =head1 NAME
 
 Template::Declare::Tags
@@ -236,11 +236,19 @@
 
 =cut
 
+
 sub with (@) {
     %ATTRIBUTES = ();
     while ( my ( $key, $val ) = splice( @_, 0, 2 ) ) {
         no warnings 'uninitialized';
         $ATTRIBUTES{$key} = $val;
+
+        if ( lc($key) eq 'id' ) {
+            if ( $ELEMENT_ID_CACHE{$val}++) {
+            	warn "HTML appears to contain illegal duplicate element id: $val";
+	    }
+        }
+
     }
     wantarray ? () : '';
 }
@@ -391,52 +399,59 @@
 
 C<show> displays templates. 
 
-Do not call templates with arguments. That's not supported. 
-XXX TODO: This makes jesse cry. Audrey/cl: sanity check?
+Do not call templates with arguments. That's not supported.
 
+XXX TODO: This makes jesse cry. Audrey/cl: sanity check?
 
-C<show> can either be called with a template name or a package/object and 
-a template.  (It's both functional and OO.)
-
+C<show> can either be called with a template name or a package/object
+and a template.  (It's both functional and OO.)
 
 If called from within a Template::Declare subclass, then private
 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.
+From the outside world, users can either call
+C<Template::Declare->show()> or C<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 $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 {
+    }
+    else {
         Template::Declare->new_buffer_frame;
     }
-    _show_template($template, $INSIDE_TEMPLATE);
+    _show_template( $template, $INSIDE_TEMPLATE );
     my $data = Template::Declare->buffer->data;
-    unless ($INSIDE_TEMPLATE) { Template::Declare->end_buffer_frame }
+    unless ($INSIDE_TEMPLATE) {
+        Template::Declare->end_buffer_frame;
+        %ELEMENT_ID_CACHE = ();
+    }
     return $data;
+
 }
 
 sub show_page {
     my $template = shift;
     my $INSIDE_TEMPLATE = 0;
+
     # if we're inside a template, we should show private templates
-        Template::Declare->new_buffer_frame;
-    _show_template($template, 0);
+    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);
+    Template::Declare->end_buffer_frame;
+    Template::Declare->buffer->append($data); 
+    %ELEMENT_ID_CACHE = (); # We're done. we can clear the cache
     return $data;
-
 }
 
 sub _show_template {

Modified: Template-Declare/t/closures.t
==============================================================================
--- Template-Declare/t/closures.t	(original)
+++ Template-Declare/t/closures.t	Fri Apr  6 10:04:34 2007
@@ -93,7 +93,7 @@
 for (qw(closure_1 closure_2 closure_3)) {
 Template::Declare->buffer->clear;
 my $simple = Template::Declare->show($_);
-diag ($simple);
+#diag ($simple);
 ok($simple =~ /<i>\s*<b>\s*Bolded\s*<\/b>\s*<\/i>/ms);
 ok_lint($simple);
 }
@@ -103,7 +103,7 @@
 Template::Declare->buffer->clear;
 my $simple = Template::Declare->show($_);
 ok($simple =~ /<i>My\s*<b>Bolded\s*<\/b>\s*<\/i>/ms);
-diag ($simple);
+#diag ($simple);
 ok_lint(Template::Declare->buffer->data());
 
 }

Modified: Template-Declare/t/private.t
==============================================================================
--- Template-Declare/t/private.t	(original)
+++ Template-Declare/t/private.t	Fri Apr  6 10:04:34 2007
@@ -40,7 +40,7 @@
 use Template::Declare::Tags;
 Template::Declare->init(roots => ['Wifty::UI']);
 
-use Test::More tests => 15;
+use Test::More tests => 14;
 use Test::Warn;
 require "t/utils.pl";
 
@@ -53,7 +53,7 @@
 {
     my $simple;
     warning_like
-      { $simple = ( show('does_not_exist') ); }
+      { $simple = ( show('does_not_exist') )||''; }
       qr/could not be found.*private/,
       "got warning";
     unlike( $simple , qr'This is my content' );
@@ -71,7 +71,7 @@
 {
     my $simple;
     warning_like
-      { $simple = ( show('private-content') ); }
+      { $simple = ( show('private-content') ||''); }
       qr/could not be found.*private/,
       "got warning";
     unlike( $simple , qr'This is my content', "Can't call private templates" );
@@ -85,7 +85,6 @@
       { $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);
 }
 

Modified: Template-Declare/t/subclassing.t
==============================================================================
--- Template-Declare/t/subclassing.t	(original)
+++ Template-Declare/t/subclassing.t	Fri Apr  6 10:04:34 2007
@@ -85,7 +85,7 @@
 {
     my $simple;
     warning_like
-      { $simple = ( show('private-content') ); }
+      { $simple = ( show('private-content')||'' ); }
       qr/could not be found.*private/,
       "got warning";
     unlike( $simple , qr'This is my content', "Can't call private templates" );


More information about the Jifty-commit mailing list