[Jifty-commit] r7479 - in Template-Declare/trunk: lib/Template

Jifty commits jifty-commit at lists.jifty.org
Thu Sep 3 18:47:46 EDT 2009


Author: theory
Date: Thu Sep  3 18:47:46 2009
New Revision: 7479

Modified:
   Template-Declare/trunk/lib/Template/Declare.pm
   Template-Declare/trunk/t/importing.t

Log:
Docuemnted `import_templates`. I'm still not clear on why the module has both
this interface and `alias.` A discussion of the differences would be most
useful.



Modified: Template-Declare/trunk/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare.pm	(original)
+++ Template-Declare/trunk/lib/Template/Declare.pm	Thu Sep  3 18:47:46 2009
@@ -569,9 +569,16 @@
 
 =head2 import_templates
 
+ import_templates MyApp::Templates under '/something';
 
- import_templates Wifty::UI::something under '/something';
-
+Import the templates defined in a template class into a subpath via the
+C<import_templates> function. In this example, the templates defined in
+MyApp::Templates will be imported into the "/something" path. Thus, a template
+deined in MyApp::Templates named "foo" will also be accessible via
+"something/foo". This is not unlike mixing in templates with C<alias>, but is
+lighter-weight and package variables cannot be assigned. This is because it is
+really like a hard link to the template, whereas an alias is a copy with the
+variable information attached to it.
 
 =cut
 

Modified: Template-Declare/trunk/t/importing.t
==============================================================================
--- Template-Declare/trunk/t/importing.t	(original)
+++ Template-Declare/trunk/t/importing.t	Thu Sep  3 18:47:46 2009
@@ -23,13 +23,13 @@
     html {
         head {};
         body { show 'private-content'; };
-        }
+    }
 
 };
 
 private template 'private-content' => sub {
     my $self = shift;
-    with( id => 'body' ), div {
+    with ( id => 'body' ), div {
         outs( 'This is my content from' . $self );
     };
 };
@@ -41,28 +41,36 @@
 use Template::Declare::Tags;
 Template::Declare->init( roots => ['Wifty::UI'] );
 
-use Test::More tests => 12;
+use Test::More tests => 14;
 require "t/utils.pl";
 
-ok( Wifty::UI::imported_pkg->has_template('imported') );
-ok( Wifty::UI::imported_subclass_pkg->has_template('imported') );
-
-ok( Template::Declare->has_template('imported_pkg/imported') );
-ok( Template::Declare->has_template('imported_subclass_pkg/imported'), "When you subclass and then import, the superclass's imports are there" );
-
-is( Wifty::UI::imported_subclass_pkg->path_for('imported'), '/imported_subclass_pkg/imported' );
-is( Wifty::UI->path_for('simple'), '/simple' );
+ok( Wifty::UI::imported_pkg->has_template('imported'),
+    'Original template should be visible' );
+ok( Wifty::UI::imported_subclass_pkg->has_template('imported'),
+    'And be visible in a subclass');
+
+ok( Template::Declare->has_template('imported_pkg/imported'),
+    'Template should have been imported' );
+ok( Template::Declare->has_template('imported_subclass_pkg/imported'),
+    'Superclass imports should be visible to subclasses');
+
+is(
+    Wifty::UI::imported_subclass_pkg->path_for('imported'),
+    '/imported_subclass_pkg/imported',
+    'The path for the imported template should be correct'
+);
+is( Wifty::UI->path_for('simple'), '/simple', 'Simple template shoudl be unimported' );
 
 {
-    my $simple = ( show('imported_pkg/imported') );
-    like( $simple, qr'This is imported' );
-    like( $simple, qr'Wifty::UI',
-        '$self is correct in template block' );
+    ok my $simple = ( show('imported_pkg/imported') ), 'Should get output for imported template';
+    like( $simple, qr'This is imported', 'Its output should be correct' );
+    like( $simple, qr'Wifty::UI', '$self is correct in template block' );
     ok_lint($simple);
 }
 
 {
-    my $simple = ( show('imported_subclass_pkg/imported') );
+    ok my $simple = ( show('imported_subclass_pkg/imported') ),
+        'Should get output from imported template from subclass';
     like(
         $simple,
         qr'This is imported',


More information about the Jifty-commit mailing list