[Jifty-commit] r3342 - in jifty/trunk: lib/Jifty t/TestApp/lib/TestApp t/TestApp/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Jun 3 19:59:59 EDT 2007


Author: jesse
Date: Sun Jun  3 19:59:59 2007
New Revision: 3342

Added:
   jifty/trunk/t/TestApp/t/17-template-region-internal-redirect.t
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Web.pm
   jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
   jifty/trunk/t/TestApp/lib/TestApp/View.pm

Log:
 r57920 at pinglin:  jesse | 2007-06-03 19:57:26 -0400
 * Added support for "redirects" on fragment calls (which really just do an internal replace)


Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Sun Jun  3 19:59:59 2007
@@ -673,6 +673,15 @@
     my $self = shift;
     my ($page) = @_;
 
+
+    if ($self->current_region) { 
+        # If we're within a region stack, we don't really want to redirect. We want to redispatch.
+        $self->replace_current_region($page);        
+
+        Jifty::Dispatcher::_abort;
+        return;
+    }
+
     # $page can't lead with // or it assumes it's a URI scheme.
     $page =~ s{^/+}{/};
 
@@ -1264,6 +1273,22 @@
     $region->render;
 }
 
+
+=head3 replace_current_region PATH
+
+Replaces the current region with a new region and renders it Returns undef if there's no current region
+
+=cut
+
+sub replace_current_region {
+    my $self = shift;
+    my $path = shift;
+    return undef unless (my $region = $self->current_region);
+    $region->path($path);
+    $region->render;
+}
+
+
 =head3 current_region
 
 Returns the name of the current L<Jifty::Web::PageRegion>, or undef if

Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm	Sun Jun  3 19:59:59 2007
@@ -63,4 +63,11 @@
 on '/on_stage_show' => run { show '/index.html'; };
 after '/after_stage_show' => run { show '/index.html'; };
 
+
+
+before 'pre-redir-region' => run {
+    redirect('/post-redir-region');
+
+};
+
 1;

Modified: jifty/trunk/t/TestApp/lib/TestApp/View.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/View.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/View.pm	Sun Jun  3 19:59:59 2007
@@ -77,4 +77,30 @@
     span { $args->{id} }
 };
 
+
+template 'region-with-internal-redirect' => page {
+    
+    h1 { 'outer page'};
+
+    render_region('internal', path => '/pre-redir-region');
+    render_region('internal2', path => '/nonredir-region');
+    
+
+    h2 { 'still going'} ;
+};
+
+
+template 'nonredir-region' => sub {
+    h1 { 'other region'};
+};
+
+template 'pre-redir-region' => sub {
+    h1 { 'sorry. no.'};
+};
+
+
+template 'post-redir-region' => sub {
+
+    h1 { 'redirected ok'};
+};
 1;

Added: jifty/trunk/t/TestApp/t/17-template-region-internal-redirect.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/17-template-region-internal-redirect.t	Sun Jun  3 19:59:59 2007
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use lib 't/lib';
+use Jifty::SubTest;
+
+use Jifty::Test;
+use Jifty::Test::WWW::Mechanize;
+
+plan tests => 7;
+
+
+my $server = Jifty::Test->make_server;
+isa_ok( $server, 'Jifty::Server' );
+my $URL = $server->started_ok;
+
+
+my $mech = Jifty::Test::WWW::Mechanize->new;
+
+$mech->get_ok( $URL."/region-with-internal-redirect");
+$mech->content_like(qr'redirected ok');
+$mech->content_like(qr'other region');
+$mech->content_like(qr'still going');
+$mech->content_unlike(qr'sorry');
+
+
+1;


More information about the Jifty-commit mailing list