[Jifty-commit] r6209 - Template-Declare/trunk/lib/Template/Declare

Jifty commits jifty-commit at lists.jifty.org
Thu Jan 8 18:11:32 EST 2009


Author: ruz
Date: Thu Jan  8 18:11:32 2009
New Revision: 6209

Modified:
   Template-Declare/trunk/lib/Template/Declare/Tags.pm

Log:
* fix relative pathing, tests have been added earlier

Modified: Template-Declare/trunk/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/trunk/lib/Template/Declare/Tags.pm	Thu Jan  8 18:11:32 2009
@@ -757,30 +757,30 @@
     return Template::Declare->end_buffer_frame->data;
 }
 
-sub _resolve_relative_template_path {
+sub _resolve_template_path {
     my $template = shift;
 
-    return $template if ( $template =~ '^\/' );
-    my $parent = current_template();
-
-    my @parent   = split( '/', $parent );
-    my @template = split( '/', $template );
-
-    @template = grep { $_ !~ /^\.$/} @template; # Get rid of "." entries
-
-    # Let's find out how many levels they want to pop up
-    my @uplevels = grep { /^\.\.$/ } @template;
-    @template = grep { $_ !~ /^\.\.$/ } @template;
-
-
+    my @parts;
+    if ( substr($template, 0, 1) ne '/' ) {
+        # relative
+        @parts = split '/', current_template();
+        # Get rid of the parent's template name
+        pop @parts;
+    }
 
-    pop @parent;            # Get rid of the parent's template name
-    pop @parent for @uplevels;
-    return (join( '/', @parent, @template ) );
+    foreach ( split '/', $template ) {
+        if ( $_ eq '..' ) {
+            pop @parts;
+        }
+        # Get rid of "." and empty entries by the way
+        elsif ( $_ ne '.' && $_ ne '' ) {
+            push @parts, $_;
+        }
+    }
 
+    return join '/', @parts;
 }
 
-
 =head2 current_template
 
 Returns the absolute path of the current template
@@ -797,7 +797,7 @@
     my $inside_template = shift;
     my $args = shift;
     local @TEMPLATE_STACK  = @TEMPLATE_STACK;
-    $template = _resolve_relative_template_path($template);
+    $template = _resolve_template_path($template);
     push @TEMPLATE_STACK, $template;
 
     my $callable =


More information about the Jifty-commit mailing list