fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-09-22 08:19 am

[dw-free] Template Toolkit Plugin needs a js filter

[commit: http://hg.dwscoalition.org/dw-free/rev/4bfe60fcdd15]

http://bugs.dwscoalition.org/show_bug.cgi?id=3075

Add a js filter for use in .tt files.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/Template/Filters.pm
  • cgi-bin/DW/Template/Plugin.pm
--------------------------------------------------------------------------------
diff -r e77ea2e7ad94 -r 4bfe60fcdd15 cgi-bin/DW/Template/Filters.pm
--- a/cgi-bin/DW/Template/Filters.pm	Wed Sep 22 16:12:01 2010 +0800
+++ b/cgi-bin/DW/Template/Filters.pm	Wed Sep 22 16:19:10 2010 +0800
@@ -52,6 +52,17 @@ sub ml {
     };
 }
 
+=head2 js
+
+Escape any JS output
+
+=cut
+sub js {
+    return sub {
+        return LJ::ejs_string( $_[0] );
+    }
+}
+
 sub decide_language {
     my $r = DW::Request->get;
     return $r->note( 'ml_lang' ) if $r->note( 'ml_lang' );
diff -r e77ea2e7ad94 -r 4bfe60fcdd15 cgi-bin/DW/Template/Plugin.pm
--- a/cgi-bin/DW/Template/Plugin.pm	Wed Sep 22 16:12:01 2010 +0800
+++ b/cgi-bin/DW/Template/Plugin.pm	Wed Sep 22 16:19:10 2010 +0800
@@ -39,6 +39,7 @@ sub new {
     }, $class;
 
     $context->define_filter( 'ml', [ \&DW::Template::Filters::ml, 1 ] );
+    $context->define_filter( 'js', [ \&DW::Template::Filters::js, 1 ] );
 
     return $self;
 }
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
No Subject Icon Selected
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org