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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Sep 7 05:08:31 EDT 2007


Author: agentz
Date: Fri Sep  7 05:08:11 2007
New Revision: 4049

Added:
   Template-Declare/lib/Template/Declare/TagSet/RDF.pm
   Template-Declare/t/tagset_rdf.t
Modified:
   Template-Declare/MANIFEST
   Template-Declare/lib/Template/Declare.pm
   Template-Declare/lib/Template/Declare/TagSet/HTML.pm
   Template-Declare/lib/Template/Declare/TagSet/XUL.pm
   Template-Declare/lib/Template/Declare/Tags.pm

Log:
TD - added support for the RDF tag set (T::D::TagSet::RDF) and t/tagset_rdf.t

Modified: Template-Declare/MANIFEST
==============================================================================
--- Template-Declare/MANIFEST	(original)
+++ Template-Declare/MANIFEST	Fri Sep  7 05:08:11 2007
@@ -12,6 +12,7 @@
 lib/Template/Declare/Tags.pm
 lib/Template/Declare/TagSet.pm
 lib/Template/Declare/TagSet/HTML.pm
+lib/Template/Declare/TagSet/RDF.pm
 lib/Template/Declare/TagSet/XUL.pm
 Makefile.PL
 MANIFEST			This list of files
@@ -41,12 +42,14 @@
 t/private.t
 t/relative-pathing.t
 t/self.t
+t/siblings.t
 t/smart_tag_wrapper.t
 t/subclassing.t
 t/subtemplates.t
 t/tag_sub_list.t
 t/tagset_html.t
 t/tagset_mix.t
+t/tagset_rdf.t
 t/tagset_xul.t
 t/trivial.t
 t/utf8.t

Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Fri Sep  7 05:08:11 2007
@@ -641,6 +641,11 @@
 
 The C<;> after C< p { ... } > is required here, or Perl will complain about syntax errors.
 
+Another example is
+
+    h1 { 'heading' };  # this trailing semicolon is mandatory
+    show 'tag_tag'
+
 =item *
 
 Literal strings that have tag siblings won't be captured. So the following template

Modified: Template-Declare/lib/Template/Declare/TagSet/HTML.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/TagSet/HTML.pm	(original)
+++ Template-Declare/lib/Template/Declare/TagSet/HTML.pm	Fri Sep  7 05:08:11 2007
@@ -19,7 +19,7 @@
 }
 
 sub get_tag_list {
-    my @tags = map {@{$_||[]}}
+    my @tags = map { lc($_) } map { @{$_||[]} }
         @CGI::EXPORT_TAGS{
                 qw/:html2 :html3 :html4 :netscape :form/
         };
@@ -41,6 +41,19 @@
 
 =head1 SYNOPSIS
 
+    # normal use on the user side:
+    use base 'Template::Declare';
+    use Template::Declare::Tags 'HTML';
+
+    template foo => sub {
+        html {
+            body {
+            }
+        }
+    };
+
+    # in Template::Declare::Tags:
+
     use Template::Declare::TagSet::HTML;
     my $tagset = Template::Declare::TagSet::HTML->new(
         { package => 'html', namespace => 'html' }
@@ -57,13 +70,6 @@
         print "<img src='blah.gif' />";
     }
 
-    # normal use
-    package MyApp::Templates;
-    use Template::Declare::Tags 'HTML';
-    use base 'Template::Declare';
-    # ...
-
-
 =head1 INHERITANCE
 
     Template::Declare::TagSet::HTML
@@ -108,5 +114,5 @@
 
 =head1 SEE ALSO
 
-L<Template::Declare::TagSet>, L<Template::Declare::TagSet::XUL>, L<Template::Declare::Tags>, L<Template::Declare>.
+L<Template::Declare::TagSet>, L<Template::Declare::TagSet::XUL>, L<Template::Declare::TagSet::RDF>, L<Template::Declare::Tags>, L<Template::Declare>.
 

Added: Template-Declare/lib/Template/Declare/TagSet/RDF.pm
==============================================================================
--- (empty file)
+++ Template-Declare/lib/Template/Declare/TagSet/RDF.pm	Fri Sep  7 05:08:11 2007
@@ -0,0 +1,106 @@
+package Template::Declare::TagSet::RDF;
+
+use strict;
+use warnings;
+use base 'Template::Declare::TagSet';
+#use Smart::Comments;
+
+our %AlternateSpelling = (
+    template => 'xul_tempalte',
+);
+
+sub get_alternate_spelling {
+    my ($self, $tag) = @_;
+    $AlternateSpelling{$tag};
+}
+
+
+sub get_tag_list {
+    return [ qw{
+        Alt    Bag    Description
+        List    Property    RDF
+        Seq    Statement    XMLLiteral
+        about   li
+        first    nil    object
+        predicate    resource    rest
+        subject    type    value
+    }, (map { "_$_" } 1..10) ];
+}
+
+=begin comment
+
+Tag set for RDF Schema:
+
+    Class    Container    ContainerMembershipProperty
+    Datatype    Literal    Resource
+    comment    domain    isDefinedBy
+    label    member    range
+    seeAlso    subClassOf    subPropertyOf
+
+=cut
+
+1;
+__END__
+
+=head1 NAME
+
+Template::Declare::TagSet::RDF - Tag set for RDF
+
+=head1 SYNOPSIS
+
+    # normal use on the user side:
+    use base 'Template::Declare';
+    use Template::Declare::Tags
+         RDF => { namespace => 'rdf' };
+
+    template foo => sub {
+        rdf::RDF {
+            attr { 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#" }
+            rdf::Description {
+                attr { about => "Matilda" }
+                #...
+            }
+        }
+    };
+
+=head1 INHERITANCE
+
+    Template::Declare::TagSet::RDF
+        isa Template::Declare::TagSet
+
+=head1 METHODS
+
+=over
+
+=item C<< $obj = Template::Declare::TagSet::RDF->new({ namespace => $XML_namespace, package => $Perl_package }) >>
+
+Constructor inherited from L<Template::Declare::TagSet>.
+
+=item C<< $list = $obj->get_tag_list() >>
+
+Returns an array ref for the tag names.
+
+Currently the following tags are supported:
+
+        Alt    Bag    Description
+        List    Property    RDF
+        Seq    Statement    XMLLiteral
+        about   li
+        first    nil    object
+        predicate    resource    rest
+        subject    type    value
+        _1 _2 _3 _4 _5 _6 _7 _8 _9 _10
+
+This list may be not exhaustive; if you find some
+important missing ones, please let us know :)
+
+=back
+
+=head1 AUTHOR
+
+Agent Zhang E<lt>agentzh at gmail.comE<gt>
+
+=head1 SEE ALSO
+
+L<Template::Declare::TagSet>, L<Template::Declare::TagSet::HTML>, L<Template::Declare::TagSet::XUL>, L<Template::Declare::Tags>, L<Template::Declare>.
+

Modified: Template-Declare/lib/Template/Declare/TagSet/XUL.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/TagSet/XUL.pm	(original)
+++ Template-Declare/lib/Template/Declare/TagSet/XUL.pm	Fri Sep  7 05:08:11 2007
@@ -5,8 +5,6 @@
 #use Smart::Comments;
 use base 'Template::Declare::TagSet';
 
-use CGI ();
-
 our %AlternateSpelling = (
     template => 'xul_tempalte',
 );

Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Fri Sep  7 05:08:11 2007
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 #use Smart::Comments;
-#use Smart::Comments '#####';
+#use Smart::Comments '####';
 
 package Template::Declare::Tags;
 
@@ -153,8 +153,8 @@
 
     use Template::Declare::Tags 'HTML';
 
-Currently L<Template::Declare> bundles L<Template::Declare::TagSet::HTML>
-for HTML tags and L<Template::Declare::TagSet::XUL> for XUL tags. You can
+Currently L<Template::Declare> bundles the following tag sets:
+L<Template::Declare::TagSet::HTML>, L<Template::Declare::TagSet::XUL>, and L<Template::Declare::TagSet::RDF>. You can
 certainly specify your own tag set classes, as long
 as they subclass L<Template::Declare::TagSet> and implement
 the corresponding methods (e.g. C<get_tag_list>).
@@ -412,7 +412,7 @@
 =cut
 
 sub install_tag {
-    my $tag  = lc( $_[0] );
+    my $tag  = $_[0]; # we should not do lc($tag) here :)
     my $name = $tag;
     my $tagset = $_[1];
 
@@ -441,7 +441,7 @@
 
     no strict 'refs';
     no warnings 'redefine';
-    #warn "Installing tag $name..." if $name eq 'base';
+    #### Installing tag: $name
     # XXX TODO: use sub _install to insert subs into the caller's package so as to support XML packages
     my $code  = sub (&;$) {
         local *__ANON__ = $tag;

Added: Template-Declare/t/tagset_rdf.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/tagset_rdf.t	Fri Sep  7 05:08:11 2007
@@ -0,0 +1,95 @@
+use strict;
+use warnings;
+
+package MyApp::Templates;
+
+use base 'Template::Declare';
+use Template::Declare::Tags
+        RDF => { namespace => 'rdf' }, 'RDF';
+
+template with_ns => sub {
+    rdf::RDF {
+        attr { 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#" }
+        rdf::Description {
+            attr { about => "Matilda" }
+            rdf::type {}
+            #...
+        }
+        rdf::Bag {
+            rdf::li {}
+            rdf::_1 {}
+        }
+        rdf::Seq {
+            rdf::_2 {}
+            rdf::_9 {}
+            rdf::_10 {}
+        }
+        rdf::Alt {}
+    }
+};
+
+template without_ns => sub {
+    RDF {
+        attr { 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#" }
+        Description {
+            attr { about => "Matilda" }
+            type {}
+            #...
+        }
+        Bag {
+            li {}
+            _1 {}
+        }
+        Seq {
+            _2 {}
+            _9 {}
+            _10 {}
+        }
+        Alt {}
+    }
+};
+
+package main;
+use Test::More tests => 2;
+
+Template::Declare->init( roots => ['MyApp::Templates']);
+my $out = Template::Declare->show('with_ns') . "\n";
+is $out, <<_EOC_;
+
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description about="Matilda">
+  <rdf:type />
+ </rdf:Description>
+ <rdf:Bag>
+  <rdf:li />
+  <rdf:_1 />
+ </rdf:Bag>
+ <rdf:Seq>
+  <rdf:_2 />
+  <rdf:_9 />
+  <rdf:_10 />
+ </rdf:Seq>
+ <rdf:Alt />
+</rdf:RDF>
+_EOC_
+
+$out = Template::Declare->show('without_ns') . "\n";
+is $out, <<_EOC_;
+
+<RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <Description about="Matilda">
+  <type />
+ </Description>
+ <Bag>
+  <li />
+  <_1 />
+ </Bag>
+ <Seq>
+  <_2 />
+  <_9 />
+  <_10 />
+ </Seq>
+ <Alt />
+</RDF>
+_EOC_
+


More information about the Jifty-commit mailing list