[Jifty-commit] r3865 - in Template-Declare: lib/Template/Declare t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Aug 12 22:11:08 EDT 2007


Author: agentz
Date: Sun Aug 12 22:11:08 2007
New Revision: 3865

Added:
   Template-Declare/t/99-pod-coverage.t
Modified:
   Template-Declare/MANIFEST
   Template-Declare/lib/Template/Declare/Buffer.pm
   Template-Declare/lib/Template/Declare/Tags.pm

Log:
[TD]
* added t/99-pod-coverage.t.
* updated MANIFEST.
* added basic docs to Template::Declare::Buffer.
* added docs for XML namespace support to Template::Declare::Tags.

Modified: Template-Declare/MANIFEST
==============================================================================
--- Template-Declare/MANIFEST	(original)
+++ Template-Declare/MANIFEST	Sun Aug 12 22:11:08 2007
@@ -19,6 +19,7 @@
 META.yml
 README
 SIGNATURE
+t/99-pod-coverage.t
 t/99-pod.t
 t/aliasing.t
 t/alternative.t
@@ -34,6 +35,7 @@
 t/indexhtml.t
 t/MyTagSet.pm
 t/namespace.t
+t/postprocessor.t
 t/private.t
 t/relative-pathing.t
 t/self.t

Modified: Template-Declare/lib/Template/Declare/Buffer.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Buffer.pm	(original)
+++ Template-Declare/lib/Template/Declare/Buffer.pm	Sun Aug 12 22:11:08 2007
@@ -20,3 +20,17 @@
 }
 
 1;
+__END__
+
+=head1 NAME
+
+Template::Declare::Buffer
+
+=head1 DESCRIPTION
+
+We use this class to manage the output buffer used by L<Template::Declare>.
+
+=head1 SEE ALSO
+
+L<Template::Declare>.
+

Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Sun Aug 12 22:11:08 2007
@@ -18,6 +18,8 @@
           get_current_attr xml_decl
           smart_tag_wrapper current_template );
 
+our $VERSION = '0.25';
+
 # XXX TODO: Put @TagSubs into POD
 # record all the subs for XML tags generated on-the-fly
 our @TagSubs;
@@ -82,12 +84,55 @@
 =head1 SYNOPSIS
 
     package MyApp::Templates;
+
     use base 'Template::Declare';
-    use Template::Declare::Tags qw/ HTML XUL /;
+    use Template::Declare::Tags 'HTML';
+
+    template main => sub {
+        link {}
+        table {
+            row {
+                cell { "Hello, world!" }
+            }
+        }
+        img { attr { src => 'cat.gif' } }
+    };
+
+    # Produces:
+    # <link />
+    # <table>
+    #  <tr>
+    #   <td>Hello, world!</td>
+    #  </tr>
+    # </table>
+    # <img src="cat.gif" />
+
+    package MyApp::Templates;
+
+    use base 'Template::Declare';
+    use Template::Declare::Tags
+        'XUL', HTML => { namespace => 'html' };
+
+    template main => sub {
+        groupbox {
+            caption { attr { label => 'Colors' } }
+            html::div { html::p { 'howdy!' } }
+            html::br {}
+        }
+    };
+
+    # Produces:
+    #   <groupbox>
+    #    <caption label="Colors" />
+    #    <html:div>
+    #     <html:p>howdy!</html:p>
+    #    </html:div>
+    #    <html:br></html:br>
+    #   </groupbox>
 
 =head1 DESCRIPTION
 
-C<Template::Declare::Tags> is used to generate and export
+C<Template::Declare::Tags> is used to generate and install
 subroutines for tags into the user's namespace.
 
 You can specify the tag sets used by providing a list of
@@ -109,7 +154,64 @@
 as they subclass L<Template::Declare::TagSet> and implement
 the corresponding methods (e.g. C<get_tag_list>).
 
-=head1 METHODS
+XML namespaces are emulated by Perl packages. For
+example, you can embed HTML tags within XUL using the C<html> namespace:
+
+    package MyApp::Templates;
+
+    use base 'Template::Declare';
+    use Template::Declare::Tags
+        'XUL', HTML => { namespace => 'html' };
+
+    template main => sub {
+        groupbox {
+            caption { attr { label => 'Colors' } }
+            html::div { html::p { 'howdy!' } }
+            html::br {}
+        }
+    };
+
+This will give you
+
+       <groupbox>
+        <caption label="Colors" />
+        <html:div>
+         <html:p>howdy!</html:p>
+        </html:div>
+        <html:br></html:br>
+       </groupbox>
+
+Behind the scene, C<Template::Declare::Tags>  will generate a Perl package named C<html> and install HTML tag subroutines into that package. On the other hand, XUL tag subroutines are installed into the current package, namely, C<MyApp::Templates> in the previous example.
+
+There are cases when you want to specify a different Perl package for a perticular XML namespace name. For instance, the C<html> Perl package has already been used for other purposes in your application and you don't want to install subs there and mess things up, then the C<package> option can come to rescue:
+
+    package MyApp::Templates;
+    use base 'Template::Declare';
+    use Template::Declare::Tags
+        'XUL', HTML => {
+            namespace => 'htm',
+            package => 'MyHtml'
+        };
+
+    template main => sub {
+        groupbox {
+            caption { attr { label => 'Colors' } }
+            MyHtml::div { MyHtml::p { 'howdy!' } }
+            MyHtml::br {}
+        }
+    };
+
+This code snippet will still generate something like the following:
+
+    <groupbox>
+     <caption label="Colors" />
+     <htm:div>
+      <htm:p>howdy!</htm:p>
+     </htm:div>
+     <htm:br></htm:br>
+    </groupbox>
+
+=head1 METHODS AND SUBROUTINES
 
 =head2 template TEMPLATENAME => sub { 'Implementation' };
 

Added: Template-Declare/t/99-pod-coverage.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/99-pod-coverage.t	Sun Aug 12 22:11:08 2007
@@ -0,0 +1,9 @@
+use Test::More;
+
+# XXX we need more POD...
+my $skip_all = 1;
+eval "use Test::Pod::Coverage";
+plan skip_all => "We know we don't have enough POD :(" if $skip_all;
+plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@;
+all_pod_coverage_ok();
+


More information about the Jifty-commit mailing list