[Jifty-commit] r3852 - in Template-Declare: lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sat Aug 11 08:41:16 EDT 2007
Author: agentz
Date: Sat Aug 11 08:41:16 2007
New Revision: 3852
Added:
Template-Declare/t/MyTagSet.pm
Modified:
Template-Declare/MANIFEST
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/namespace.t
Log:
TD - implemented use T::D::Tags HTML => { namespace => 'html', from => 'My::HTML::TagSet' }; and also fixed a bug in the 'package' option handling.
Modified: Template-Declare/MANIFEST
==============================================================================
--- Template-Declare/MANIFEST (original)
+++ Template-Declare/MANIFEST Sat Aug 11 08:41:16 2007
@@ -32,6 +32,7 @@
t/forms.t
t/importing.t
t/indexhtml.t
+t/MyTagSet.pm
t/namespace.t
t/private.t
t/relative-pathing.t
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Sat Aug 11 08:41:16 2007
@@ -38,13 +38,15 @@
@TagSubs = ();
while (@_) {
my $lang = shift;
- my $opts = { package => scalar(caller) };
+ my $opts;
if (ref $_[0] and ref $_[0] eq 'HASH') {
$opts = shift;
$opts->{package} ||= $opts->{namespace};
### XXX TODO: carp if the derived package already exists?
}
- my $module = "Template::Declare::TagSet::$lang";
+ $opts->{package} ||= scalar(caller);
+ my $module = $opts->{from} ||
+ "Template::Declare::TagSet::$lang";
eval "use $module";
if ($@) {
Added: Template-Declare/t/MyTagSet.pm
==============================================================================
--- (empty file)
+++ Template-Declare/t/MyTagSet.pm Sat Aug 11 08:41:16 2007
@@ -0,0 +1,11 @@
+package t::MyTagSet;
+
+use strict;
+use warnings;
+use base 'Template::Declare::TagSet';
+
+sub get_tag_list {
+ [qw/ foo bar baz boz /];
+}
+
+1;
Modified: Template-Declare/t/namespace.t
==============================================================================
--- Template-Declare/t/namespace.t (original)
+++ Template-Declare/t/namespace.t Sat Aug 11 08:41:16 2007
@@ -1,6 +1,8 @@
use strict;
use warnings;
-use Test::More tests => 4;
+use Test::More tests => 5;
+
+### TEST 1:
package MyApp::Templates;
@@ -16,6 +18,23 @@
}
};
+package main;
+Template::Declare->init( roots => ['MyApp::Templates']);
+my $out = Template::Declare->show('main') . "\n";
+is $out, <<_EOC_;
+
+<groupbox>
+ <caption label="Colors" />
+ <html:div>
+ <html:p>howdy!</html:p>
+ </html:div>
+ <html:br></html:br>
+</groupbox>
+_EOC_
+
+
+### TEST 2:
+
package MyApp::Templates2;
use base 'Template::Declare';
@@ -30,6 +49,7 @@
caption { attr { label => 'Colors' } }
MyHtml::div { MyHtml::p { 'howdy!' } }
MyHtml::br {}
+ html::label {}
}
};
@@ -39,18 +59,6 @@
package main;
Template::Declare->init( roots => ['MyApp::Templates']);
-my $out = Template::Declare->show('main') . "\n";
-is $out, <<_EOC_;
-
-<groupbox>
- <caption label="Colors" />
- <html:div>
- <html:p>howdy!</html:p>
- </html:div>
- <html:br></html:br>
-</groupbox>
-_EOC_
-
Template::Declare->init( roots => ['MyApp::Templates2']);
$out = Template::Declare->show('main') . "\n";
is $out, <<_EOC_;
@@ -61,6 +69,34 @@
<htm:p>howdy!</htm:p>
</htm:div>
<htm:br></htm:br>
+ <html:label></html:label>
</groupbox>
_EOC_
+### TEST 3:
+
+package MyApp::Templates;
+
+use base 'Template::Declare';
+use Template::Declare::Tags
+ HTML => { namespace => 'blah', from => 't::MyTagSet' },
+ Blah => { namespace => undef, from => 't::MyTagSet' };
+
+template main => sub {
+ foo {
+ blah::bar { attr { label => 'Colors' } }
+ blah::baz { 'howdy!' }
+ }
+};
+
+package main;
+Template::Declare->init( roots => ['MyApp::Templates']);
+$out = Template::Declare->show('main') . "\n";
+is $out, <<_EOC_;
+
+<foo>
+ <blah:bar label="Colors" />
+ <blah:baz>howdy!</blah:baz>
+</foo>
+_EOC_
+
More information about the Jifty-commit
mailing list