[Jifty-commit] r2968 - in jifty/trunk:
t/TestApp-Plugin-PasswordAuth/t t/TestApp/lib/TestApp
t/TestApp/share/web/templates/path_test
t/TestApp/share/web/templates/path_test/foo t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Mar 15 07:28:20 EDT 2007
Author: evdb
Date: Thu Mar 15 07:28:19 2007
New Revision: 2968
Added:
jifty/trunk/t/TestApp/share/web/templates/path_test/
jifty/trunk/t/TestApp/share/web/templates/path_test/foo/
jifty/trunk/t/TestApp/share/web/templates/path_test/foo/index.html (contents, props changed)
jifty/trunk/t/TestApp/share/web/templates/path_test/in_both
jifty/trunk/t/TestApp/share/web/templates/path_test/mason_only
jifty/trunk/t/TestApp/t/14-template-paths.t (contents, props changed)
Removed:
jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/mailbox
Modified:
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/ (props changed)
jifty/trunk/t/TestApp/lib/TestApp/View.pm
Log:
Changes to the dispatching to templates:
* only add '/index.html' to the path given if there is no template that can handle the given path.
* template_exists now checks for Template::Declare templates too
* tests that check that T::D templates are preferred over Mason templates.
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Thu Mar 15 07:28:19 2007
@@ -766,8 +766,10 @@
# a relative path, prepend the working directory
$path = "$self->{cwd}/$path" unless $path =~ m{^/};
- # When we're requesting a directory, go looking for the index.html
- if ( $self->template_exists( $path . "/index.html" ) ) {
+ # When we're requesting a directory, go looking for the index.html if the
+ # path given does not exist
+ if ( ! $self->template_exists( $path )
+ && $self->template_exists( $path . "/index.html" ) ) {
$path .= "/index.html";
}
@@ -1115,7 +1117,8 @@
=head2 template_exists PATH
-Returns true if PATH is a valid template inside your template root.
+Returns true if PATH is a valid template inside your template root. This checks
+for both Template::Declare and HTML::Mason Templates.
=cut
@@ -1123,13 +1126,16 @@
my $self = shift;
my $template = shift;
- return Jifty->handler->mason->interp->comp_exists( $template);
+ return Jifty->handler->declare_handler->template_exists($template)
+ || Jifty->handler->mason->interp->comp_exists( $template);
}
=head2 render_template PATH
-Use our templating system to render a template. If there's an error, do the right thing.
+Use our templating system to render a template. If there's an error, do the
+right thing. If the same 'PATH' is found in both Template::Declare and
+HTML::Mason templates then the T::D template is used.
=cut
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 Thu Mar 15 07:28:19 2007
@@ -4,17 +4,35 @@
use Jifty::View::Declare -base;
-template 'concrete2.html' => sub {
- html {
- body {
- h1 { _( 'I have %1 concrete mixers', 2) };
- }
- }
+template 'concrete2.html' => sub {
+ html {
+ body {
+ h1 { _( 'I have %1 concrete mixers', 2 ) };
+ };
+ };
};
-
template 'die.html' => sub {
die "this is an error";
};
+# The following templates are used to test the precedence of T::D over Mason and
+# also that '/index.html' is only added to the path if the given path does not
+# match.
+template '/path_test/foo' => sub {
+ outs('/path_test/foo - T::D');
+};
+
+template '/path_test/bar/index.html' => sub {
+ outs('/path_test/bar/index.html - T::D');
+};
+
+template '/path_test/in_both' => sub {
+ outs('/path_test/in_both - T::D');
+};
+
+template '/path_test/td_only' => sub {
+ outs('/path_test/td_only - T::D');
+};
+
1;
Added: jifty/trunk/t/TestApp/share/web/templates/path_test/foo/index.html
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/share/web/templates/path_test/foo/index.html Thu Mar 15 07:28:19 2007
@@ -0,0 +1 @@
+/path_test/foo/index.html - Mason
Added: jifty/trunk/t/TestApp/share/web/templates/path_test/in_both
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/share/web/templates/path_test/in_both Thu Mar 15 07:28:19 2007
@@ -0,0 +1 @@
+/path_test/in_both - Mason
Added: jifty/trunk/t/TestApp/share/web/templates/path_test/mason_only
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/share/web/templates/path_test/mason_only Thu Mar 15 07:28:19 2007
@@ -0,0 +1 @@
+/path_test/mason_only - Mason
\ No newline at end of file
Added: jifty/trunk/t/TestApp/t/14-template-paths.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/14-template-paths.t Thu Mar 15 07:28:19 2007
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use lib 't/lib';
+use Jifty::SubTest;
+
+use Jifty::Test;
+use Jifty::Test::WWW::Mechanize;
+
+my @tests = (
+ {
+ url => "/path_test/foo",
+ text => '/path_test/foo - T::D',
+ },
+ {
+ url => "/path_test/foo/",
+ text => '/path_test/foo - T::D',
+ },
+ {
+ url => "/path_test/foo/index.html",
+ text => '/path_test/foo/index.html - Mason',
+ },
+ {
+ url => "/path_test/bar",
+ text => '/path_test/bar/index.html - T::D',
+ },
+ {
+ url => "/path_test/bar/index.html",
+ text => '/path_test/bar/index.html - T::D',
+ },
+ {
+ url => "/path_test/in_both",
+ text => '/path_test/in_both - T::D',
+ },
+ {
+ url => "/path_test/mason_only",
+ text => '/path_test/mason_only - Mason',
+ },
+ {
+ url => "/path_test/td_only",
+ text => '/path_test/td_only - T::D',
+ },
+);
+
+plan tests => 2 + scalar(@tests) * 2;
+
+my $server = Jifty::Test->make_server;
+isa_ok( $server, 'Jifty::Server' );
+my $URL = $server->started_ok;
+
+my $mech = Jifty::Test::WWW::Mechanize->new;
+foreach my $test (@tests) {
+ $mech->get_ok( $URL . $test->{url}, "get '$URL$test->{url}'" );
+ $mech->content_contains( $test->{text}, "found content '$test->{text}'" );
+}
More information about the Jifty-commit
mailing list