[Jifty-commit] r4524 - in Template-Declare: lib/Template t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Nov 21 15:26:22 EST 2007
Author: sartak
Date: Wed Nov 21 15:26:21 2007
New Revision: 4524
Added:
Template-Declare/t/relative-aliasing.t
Modified:
Template-Declare/ (props changed)
Template-Declare/MANIFEST
Template-Declare/lib/Template/Declare.pm
Log:
r45500 at onn: sartak | 2007-11-21 15:26:03 -0500
Fix a bug where relative aliases weren't working properly. With tests!
Modified: Template-Declare/MANIFEST
==============================================================================
--- Template-Declare/MANIFEST (original)
+++ Template-Declare/MANIFEST Wed Nov 21 15:26:21 2007
@@ -41,9 +41,11 @@
t/pitfalls.t
t/postprocessor.t
t/private.t
+t/relative-aliasing.t
t/relative-pathing.t
t/self.t
t/siblings.t
+t/similar-aliases.t
t/smart_tag_wrapper.t
t/subclassing.t
t/subtemplates.t
Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm (original)
+++ Template-Declare/lib/Template/Declare.pm Wed Nov 21 15:26:21 2007
@@ -451,6 +451,12 @@
my $alias_class = $alias_info->{class};
my $package_vars = $alias_info->{package_vars};
+ $alias_prefix = "/$alias_prefix" unless $alias_prefix =~ m{^/};
+
+ # handle the case where we alias something under '/'. the regex appends
+ # a '/' so we need to prevent matching against m{^//};
+ $alias_prefix = '' if $alias_prefix eq '/';
+
if ( $template_name =~ m{^$alias_prefix/(.*)$} ) {
my $dispatch_to_template = $1;
if (my $coderef = $alias_class->resolve_template( $dispatch_to_template, $show_private)) {
Added: Template-Declare/t/relative-aliasing.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/relative-aliasing.t Wed Nov 21 15:26:21 2007
@@ -0,0 +1,85 @@
+use warnings;
+use strict;
+
+
+package SearchPlugin::View;
+
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template 'search' => sub {
+ h1 {'SearchPlugin::View::search'};
+};
+
+package ListPlugin::View;
+
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template 'listing' => sub {
+ h1 {'ListPlugin::View::listing'};
+};
+
+alias SearchPlugin::View under '/';
+
+
+package MyApp::View;
+
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template 'toplevel' => sub {h1{'Toplevel'}};
+
+alias ListPlugin::View under 'plugin/';
+
+package main;
+Template::Declare->init( roots => ['MyApp::View'] );
+
+use Test::More tests => 12;
+use Test::Warn;
+require "t/utils.pl";
+
+ok( MyApp::View->has_template('toplevel') );
+ok( !MyApp::View->has_template('listing') , "the listing template isn't imported to the top level");
+ok( !MyApp::View->has_template('search'), "The search template isn't imported to the top level" );
+ok( MyApp::View->has_template('/plugin/listing'), 'has listing template' );
+ok( MyApp::View->has_template('/plugin/search'), 'has search template' );
+
+
+
+
+
+{
+ my $simple = ( Template::Declare->show('toplevel'));
+ like( $simple, qr'Toplevel' );
+}
+{
+ warning_like {
+ my $simple = ( Template::Declare->show('listing') ||'');
+ unlike( $simple, qr'listing',
+ 'can not call a toplevel "listing" template' );
+ }
+ qr/The template 'listing' could not be found/,
+ "listing is private"
+
+}
+warning_like {
+ my $simple = ( Template::Declare->show('search')||'');
+ unlike( $simple, qr'search', "Can not call a toplevel /search" );
+} qr/The template 'search' could not be found/, "Search could not be found";
+
+
+
+{
+
+ my $simple = ( Template::Declare->show('/plugin/listing'));
+ like( $simple, qr'listing', "Can call /plugin/listing" );
+}
+{
+ my $simple = ( Template::Declare->show('/plugin/search'));
+ like( $simple, qr'search' , "Can call /plugin/search");
+}
+
+
+1;
+
More information about the Jifty-commit
mailing list