[Jifty-commit] r6348 - in jifty/trunk: lib/Jifty lib/Jifty/View/Declare lib/Jifty/View/Mason

Jifty commits jifty-commit at lists.jifty.org
Wed Feb 18 14:56:17 EST 2009


Author: alexmv
Date: Wed Feb 18 14:56:15 2009
New Revision: 6348

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/View/Declare/Handler.pm
   jifty/trunk/lib/Jifty/View/Mason/Handler.pm

Log:
 r42161 at kohr-ah:  chmrr | 2009-02-18 14:53:32 -0500
  * Move /index.html handling down into the template handler, so
    the search ordering for a /foo request is:
      - T::D on '/foo'
      - T::D on '/foo/index.html'
      - Mason on '/foo'
      - Mason on '/foo/index.html'
      - Mason on '/foo/dhandler' and '/dhandler'
    Instead of:
      - T::D on '/foo'
      - Mason on '/foo'
      - Mason on '/foo/dhandler' and '/dhandler'
      - T::D on '/foo/index.html'
      - Mason on '/foo/index.html'
      - Mason on '/foo/dhandler' and '/dhandler'
    This fixes the recently TODO'd tests.
 


Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Wed Feb 18 14:56:15 2009
@@ -803,10 +803,8 @@
     # path given does not exist.  Cache the handler and path.
     if ( not exists $TEMPLATE_CACHE{$path} or Jifty->config->framework('DevelMode')) {
         my $handler;
-        if ( $handler = $self->template_exists( $path ) ) {
+        if ( $handler = $self->template_exists( \$path ) ) {
             $TEMPLATE_CACHE{$path} = [ $path, $handler ];
-        } elsif ( $handler = $self->template_exists( $path . "/index.html" ) ) {
-            $TEMPLATE_CACHE{$path} = [ $path . "/index.html", $handler ];
         } else {
             $TEMPLATE_CACHE{$path} = [];
         }
@@ -1201,14 +1199,21 @@
 Templates.  Specifically, returns a reference to the handler which can
 process the template.
 
+If PATH is a I<reference> to the path, it will update the path to
+append C</index.html> if the path in question doesn't exist, bit the
+index does.
+
 =cut
 
 sub template_exists {
     my $self     = shift;
     my $template = shift;
 
+    my $value = ref $template ? $$template : $template;
+
     foreach my $handler ( Jifty->handler->view_handlers) {
-        if ( Jifty->handler->view($handler)->template_exists($template) ) {
+        if ( my $path = Jifty->handler->view($handler)->template_exists($value) ) {
+            $$template = $path if ref $template;
             return Jifty->handler->view($handler);
         }
     }
@@ -1243,7 +1248,7 @@
             my @handlers = map {Jifty->handler->view($_)} Jifty->handler->view_handlers;
             push @handlers, Jifty->handler->fallback_view_handler;
             foreach my $handler_class ( @handlers  ) {
-                next unless $handler_class->template_exists($template);
+                next unless $handler_class->template_exists(\$template);
                 $handler_class->show($template);
                 $showed = 1;
                 last;

Modified: jifty/trunk/lib/Jifty/View/Declare/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Declare/Handler.pm	Wed Feb 18 14:56:15 2009
@@ -85,14 +85,19 @@
 
 =head2 template_exists TEMPLATENAME
 
-Given a template name, returns true if the template is in any of our
-Template::Declare template libraries. Otherwise returns false.
+Given a template name, returns a valid template path (either
+C<TEMPLATENAME> or C<TEMPLATENAME/index.html>) if the template is in
+any of our Template::Declare template libraries. Otherwise returns
+false.
 
 =cut
 
 sub template_exists {
-    my $pkg =shift;
-    return Template::Declare->resolve_template(@_);
+    my $pkg = shift;
+    my $template = shift;
+    return $template if Template::Declare->resolve_template($template);
+    return "$template/index.html" if Template::Declare->resolve_template("$template/index.html");
+    return undef;
 }
 
 package HTML::Mason::Exception;

Modified: jifty/trunk/lib/Jifty/View/Mason/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Mason/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Mason/Handler.pm	Wed Feb 18 14:56:15 2009
@@ -162,8 +162,15 @@
 
 =head2 template_exists COMPONENT
 
-A convenience method for $self->interp->comp_exists().  
-(Jifty uses this method as part of its standard Templating system API).
+Checks if the C<COMPONENT> exists, or if C<COMPONENT/index.html>
+exists, and returns which one did.  If neither did, it seaches for
+C<dhandler> components which could match, returning C<COMPONENT> if it
+finds one.  Finally, if it finds no possible component matches,
+returns undef.
+
+Note that this algorithm does not actually decisively return if Mason
+I<will> handle a given component; the I<dhandler>s could defer
+handling, for instance.
 
 =cut
 
@@ -171,13 +178,14 @@
     my $self = shift;
     my ($component) = @_;
     $component =~ s{^/*}{/};
-    return 1 if $self->interp->comp_exists($component);
+    return $component if $self->interp->comp_exists($component);
+    return "$component/index.html" if $self->interp->comp_exists("$component/index.html");
 
     my $dhandler = $self->interp->dhandler_name;
     $dhandler = "dhandler" unless defined $dhandler;
     return if defined $dhandler and not length $dhandler;
-    return 1 if $self->interp->find_comp_upwards($component, $dhandler);
-    return 0;
+    return $component if $self->interp->find_comp_upwards($component, $dhandler);
+    return undef;
 }
 
 


More information about the Jifty-commit mailing list