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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Dec 16 17:22:21 EST 2006


Author: jesse
Date: Sat Dec 16 17:22:21 2006
New Revision: 2389

Added:
   Template-Declare/t/indexhtml.t
Modified:
   Template-Declare/   (props changed)
   Template-Declare/lib/Template/Declare.pm
   Template-Declare/lib/Template/Declare/Tags.pm

Log:
 r46212 at 66:  jesse | 2006-12-16 12:41:51 -0800
 * working templates with dots and dashes in their names. (Jifty apps now work again)


Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Sat Dec 16 17:22:21 2006
@@ -29,32 +29,39 @@
 =cut
 
 sub has_template {
-    my $pkg = shift;
+    my $pkg           = shift;
     my $template_name = shift;
-    my $show_private = 0 || shift;
+    my $show_private  = 0 || shift;
     $template_name =~ s{/}{::}g;
 
-    $pkg = ref($pkg)||$pkg;
 
+    $pkg = ref($pkg) || $pkg;
 
-    if ($template_name =~ /(.*)::(.*)/) {
+    if ( $template_name =~ /(.*)::(.*)/ ) {
         # Qualified name - Need to search for ISA chain
-        my $class ="$pkg\::$1";
-        my $rv = (Template::Declare::_resolve_template($class,$2, $show_private));
-        if( $rv) {
-        return ($class, $rv) 
+        my $class = "$pkg\::$1";
+        my $rv    = (
+            Template::Declare::_resolve_template( $class, $2, $show_private )
+        );
+        if ($rv) {
+            return ( $class, $rv );
         }
         no strict 'refs';
-        foreach my $parent (@{"$pkg\::ISA"}) {
+        foreach my $parent ( @{"$pkg\::ISA"} ) {
             $parent->can('has_template') or next;
             my $template_pkg;
-            ($template_pkg, $rv) = $parent->has_template($template_name, $show_private);
-            return ( $template_pkg,$rv) if $rv;
+            ( $template_pkg, $rv ) = $parent->has_template( $template_name, $show_private );
+            return ( $template_pkg, $rv ) if $rv;
         }
-    }
-    else {
+    } else {
+
         # Unqualified name
-        return ($pkg,Template::Declare::_resolve_template($pkg,$template_name, $show_private));
+        return (
+            $pkg,
+            Template::Declare::_resolve_template(
+                $pkg, $template_name, $show_private
+            )
+        );
     }
     return undef;
 }
@@ -65,36 +72,24 @@
     my $template_name = shift;
     my $show_private  = shift;
 
-
-    my $method = _template_name_to_sub($template_name);
-    my $private_method;
-
-    if ( $self->can($method) ) {
-        return $method;
+    if ( my $coderef = $self->can( _template_name_to_sub($template_name) ) ) {
+        return $coderef;
     }
 
-    elsif (
-        $show_private
-        && ( $private_method
-            = _template_name_to_private_sub($template_name) )
-        && $self->can($private_method)
-        )
-    {
-        return $private_method;
+    elsif ($show_private) {
+        return $self->can( _template_name_to_private_sub($template_name) );
     }
 
 }
 
 sub _template_name_to_sub {
     my $template_name =shift;
-        $template_name =~ s/-/_/g;
     return "_jifty_template_".$template_name;
 
 }
 
 sub _template_name_to_private_sub {
     my $template_name =shift;
-        $template_name =~ s/-/_/g;
     return "_jifty_private_template_".$template_name;
 }
 

Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Sat Dec 16 17:22:21 2006
@@ -280,16 +280,11 @@
 
         # may want to just use the return value of has_template eventually
         
-        if ($callable 
-            
-            and 
-
-            # XXX TODO: die if there's no such template?
-            $pkg->can($callable)) {
+        if ($callable ){
 
             no strict 'refs';
-            $pkg->$callable(  @_ );
-        } 
+                        &$callable($pkg, @_ );
+        }
 
         $buf = $BUFFER;
     }

Added: Template-Declare/t/indexhtml.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/indexhtml.t	Sat Dec 16 17:22:21 2006
@@ -0,0 +1,72 @@
+use warnings;
+use strict;
+
+
+package Wifty::UI;
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+use Test::More;
+
+template 'index.html' => sub {
+    html {
+        head {};
+        body {
+            show 'my/content';
+            }
+        }
+
+};
+
+template 'dash-test' => sub {
+    html {
+        head {};
+        body {
+            show 'my/content';
+            }
+        }
+
+};
+
+
+template 'my/content' => sub {
+        div { attr { id => 'body' }
+            outs('This is my content')
+        }
+
+};
+
+package Template::Declare::Tags;
+
+use Test::More qw/no_plan/;
+use HTML::Lint;
+
+our $self;
+local $self = {};
+bless $self, 'Wifty::UI';
+
+for('index.html', 'dash-test'){ 
+{
+local $Template::Declare::Tags::BUFFER;
+my $simple =(show($_));
+ok($simple =~ 'This is my content');
+#diag ($simple);
+ok_lint($simple);
+}
+}
+
+
+sub ok_lint {
+    my $html = shift;
+
+    my $lint = HTML::Lint->new;
+
+    $lint->parse($html);
+    is( $lint->errors, 0, "Lint checked clean" );
+    foreach my $error ( $lint->errors ) {
+        diag( $error->as_string );
+    }
+
+}
+
+
+1;


More information about the Jifty-commit mailing list