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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Aug 12 00:03:22 EDT 2007


Author: sartak
Date: Sun Aug 12 00:03:17 2007
New Revision: 3855

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

Log:
 r37274 at gorgoroth:  sartak | 2007-08-12 00:00:01 -0400
 Add content postprocessing (so one can use Text::Markdown for easy inline tags)
 It's used whenever _escape_html used to be called (now called _postprocess)


Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Sun Aug 12 00:03:17 2007
@@ -11,6 +11,7 @@
 
 use base 'Class::Data::Inheritable';
 __PACKAGE__->mk_classdata('roots');
+__PACKAGE__->mk_classdata('postprocessor');
 __PACKAGE__->mk_classdata('aliases');
 __PACKAGE__->mk_classdata('alias_metadata');
 __PACKAGE__->mk_classdata('templates');
@@ -19,6 +20,7 @@
 __PACKAGE__->mk_classdata('imported_into');
 
 __PACKAGE__->roots( [] );
+__PACKAGE__->postprocessor( sub { return wantarray ? @_ : $_[0] } );
 __PACKAGE__->aliases(           {} );
 __PACKAGE__->alias_metadata(    {} );
 __PACKAGE__->templates(         {} );
@@ -168,6 +170,8 @@
 
 =item roots
 
+=item postprocessor
+
 =back
 
 =cut 
@@ -180,6 +184,10 @@
         $class->roots( $args{'roots'} );
     }
 
+    if ( $args{'postprocessor'} ) {
+        $class->postprocessor( $args{'postprocessor'} );
+    }
+
 }
 
 sub new_buffer_frame {

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 00:03:17 2007
@@ -227,7 +227,7 @@
 
 =cut
 
-#sub outs { outs_raw( map { _escape_html($_); } grep {defined} @_ ); }
+#sub outs { outs_raw( map { _postprocess($_); } grep {defined} @_ ); }
 
 =head2 outs_raw STUFF
 
@@ -252,7 +252,7 @@
         my $returned =
             ref($item) eq 'CODE'
             ? $item->()
-            : ( $raw ? $item : _escape_html($item) ) || '';
+            : ( $raw ? $item : _postprocess($item) ) || '';
         my $content = Template::Declare->buffer->data || '';
         Template::Declare->end_buffer_frame;
         Template::Declare->buffer->append( $content . $returned );
@@ -419,7 +419,7 @@
     Template::Declare->new_buffer_frame;
 
     my $last = join '',    #
-        map { ref($_) ? $_ : _escape_html($_) }    #
+        map { ref($_) ? $_ : _postprocess($_) }    #
         $coderef->(%ATTRIBUTES);
 
     %ATTRIBUTES = ();                              # prevent leakage
@@ -487,14 +487,14 @@
             my $field = shift;
             my $val   = shift;
 
-            $buf .= ' ' . $field . q{="} . _escape_html($val) . q{"};
+            $buf .= ' ' . $field . q{="} . _postprocess($val) . q{"};
             wantarray ? () : '';
         };
 
         local $TAG_NEST_DEPTH = $TAG_NEST_DEPTH + 1;
         %ATTRIBUTES = ();
         Template::Declare->new_buffer_frame;
-        my $last = join '', map { ref($_) ? $_ : _escape_html($_) } $code->();
+        my $last = join '', map { ref($_) ? $_ : _postprocess($_) } $code->();
 
         if ( length( Template::Declare->buffer->data ) ) {
 
@@ -652,7 +652,7 @@
     Template::Declare->buffer->append($content);
 }
 
-sub _escape_html {
+sub _postprocess {
     my $val = shift;
     no warnings 'uninitialized';
     $val =~ s/&/&/g;
@@ -662,6 +662,7 @@
     $val =~ s/\)/)/g;
     $val =~ s/"/"/g;
     $val =~ s/'/'/g;
+    $val = Template::Declare->postprocessor->($val);
     return $val;
 }
 


More information about the Jifty-commit mailing list