[Jifty-commit] r3876 - in Template-Declare: lib/Template

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Aug 13 11:23:37 EDT 2007


Author: sartak
Date: Mon Aug 13 11:23:36 2007
New Revision: 3876

Modified:
   Template-Declare/   (props changed)
   Template-Declare/Changes
   Template-Declare/lib/Template/Declare.pm

Log:
 r37342 at gorgoroth:  sartak | 2007-08-13 11:23:23 -0400
 Add an example of using postprocessing


Modified: Template-Declare/Changes
==============================================================================
--- Template-Declare/Changes	(original)
+++ Template-Declare/Changes	Mon Aug 13 11:23:36 2007
@@ -1,5 +1,5 @@
 0.26 - 2007-08-13
-* Refactored Template::Decalre::Tags to make the tag sets configurable.
+* Refactored Template::Declare::Tags to make the tag sets configurable.
 * Added Template::Declare::TagSet::HTML and Template::Declare::TagSet::XUL,
   respectively, as well as their common base class, Template::Declare::TagSet.
   Added Template::Declare::TagSet::HTML and Template::Declare::TagSet::XUL,
@@ -13,6 +13,7 @@
   generated on-the-fly, which is necessary for secondary symbol exporting
   in Jifty::View::Declare::Helpers.
 * Implemented C< use Template::Declare::Tags HTML => { from => 'My::HTML::TagSet' } >.
+* Allow content post-proceessing with a callback.
 
 ----------------------------------------------------------------------
 r57045 (orig r3286):  jesse | 2007-05-22 15:58:58 -0400

Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Mon Aug 13 11:23:36 2007
@@ -203,6 +203,50 @@
 For more options (especially the "native" XML namespace
 support and more samples, see L<Template::Declare::Tags>.
 
+=head2 Postprocessing
+
+Sometimes you just want simple syntax for inline elements. The following shows
+how to use a postprocessor to emphasize text _like this_.
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+                        
+ template before => sub {
+     h1 {
+         outs "Welcome to ";
+         em { "my"};
+         outs " site. It's ";
+         em { "great"};
+         outs "!";
+     };
+ };
+
+ template after => sub {
+     h1 { "Welcome to _my_ site. It's _great_!"};
+     h2 { outs_raw "This is _not_ emphasized."};
+ };
+
+ package main;
+ use Template::Declare;
+ Template::Declare->init( roots => ['MyApp::Templates'], postprocessor => \&emphasize);
+ print Template::Declare->show( 'before');
+ print Template::Declare->show( 'after');
+               
+ sub emphasize {
+     my $text = shift;
+     $text =~ s{_(.+?)_}{<em>$1</em>}g;
+     return $text;
+ }
+
+ # Output:
+ #
+ # <h1>Welcome to 
+ #  <em>my</em> site. It&#39;s 
+ #  <em>great</em>!</h1>
+ # <h1>Welcome to <em>my</em> site. It&#39;s <em>great</em>!</h1>
+ # <h2>This is _not_ emphasized.</h2>
+
 =head2 Multiple template roots (search paths)
 
 =head2 Inheritance


More information about the Jifty-commit mailing list