default <:= ... :> tags to html formatting
authorTony Cook <tony@develop-help.com>
Mon, 25 Feb 2013 09:55:46 +0000 (20:55 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 25 Feb 2013 09:55:46 +0000 (20:55 +1100)
this can be overriden with [html].tagformat

site/cgi-bin/modules/BSE/Template.pm
site/cgi-bin/modules/Squirrel/Template.pm
site/cgi-bin/modules/Squirrel/Template/Parser.pm
site/docs/config.pod
site/templates/admin/imageclean/final.tmpl
site/templates/admin/imageclean/preview.tmpl
site/templates/admin/import/start.tmpl
site/templates/admin/logon.tmpl
site/templates/admin/menu.tmpl
site/templates/preload.tmpl
t/050-local/050-dyncat.t

index 44b08c2f621cb65c08a4d8005d4c0a8cb354c518..67467edf2af27fc2df2eda608f5acf2528136fa2 100644 (file)
@@ -4,7 +4,24 @@ use Squirrel::Template;
 use Carp qw(confess cluck);
 use Config ();
 
-our $VERSION = "1.009";
+our $VERSION = "1.010";
+
+my %formats =
+  (
+   html => sub {
+     require BSE::Util::HTML;
+     return BSE::Util::HTML::escape_html($_[0]);
+   },
+   uri => sub {
+     require BSE::Util::HTML;
+     return BSE::Util::HTML::escape_uri($_[0]);
+   },
+   raw => sub {
+     return $_[0];
+   },
+  );
+$formats{h} = $formats{html};
+$formats{u} = $formats{uri};
 
 sub templater {
   my ($class, $cfg, $rsets) = @_;
@@ -26,17 +43,8 @@ sub templater {
      template_dir => \@dirs,
      utf8 => $cfg->utf8,
      charset => $cfg->charset,
-     formats =>
-     {
-      html => sub {
-       require BSE::Util::HTML;
-       return BSE::Util::HTML::escape_html($_[0]);
-      },
-      uri => sub {
-       require BSE::Util::HTML;
-       return BSE::Util::HTML::escape_uri($_[0]);
-      },
-     },
+     formats => \%formats,
+     def_format => $cfg->entry("html", "tagformat", "html"),
      trace_noimpl => scalar($cfg->entry("debug", "trace_noimpl", 0)),
     );
   if ($cfg->entry("basic", "cache_templates")) {
index caa976a7ed1b23e895d42662de66e98b76eff574..2c0d75b6cf7b3593c9ab5af320700e75ba0c5387 100644 (file)
@@ -20,7 +20,7 @@ BEGIN {
 
 use constant DEBUG_GET_PARMS => 0;
 
-our $VERSION = "1.024";
+our $VERSION = "1.025";
 
 my %compile_cache;
 
@@ -34,6 +34,7 @@ sub new {
   $opts{param} = [];
   $opts{wraps} = [];
   $opts{errors} = [];
+  $opts{def_format} ||= "";
 
   return bless \%opts, $class;
 }
@@ -644,6 +645,15 @@ by template files.  Defaults to C<"utf-8">.
 A BSE::Cache object to use for caching compiled templates.  Note that
 templates are currently only cached by filename.
 
+=item formats
+
+A hashref of content formatters used for formatting C<< E<lt>=
+... E<gt> >> tags.
+
+=item def_format
+
+The default format for C<< E<lt>= ... E<gt> >> tags.
+
 =back
 
 =item show_page()
index 2daa185c11a9c007f35696f3d65ba0a90269a4ea..7e53baa5db1530aa0d2113f4c8c5f747468ffc84 100644 (file)
@@ -2,7 +2,7 @@ package Squirrel::Template::Parser;
 use strict;
 use Squirrel::Template::Constants qw(:token :node);
 
-our $VERSION = "1.013";
+our $VERSION = "1.014";
 
 use constant TOK => 0;
 use constant TMPLT => 1;
@@ -131,6 +131,7 @@ sub _parse_expr {
   my $parsed;
   if (eval { $parsed = $parser->parse($expr->[TOKEN_EXPR_EXPR]); 1 }) {
     $expr->[NODE_EXPR_EXPR] = $parsed;
+    $expr->[NODE_EXPR_FORMAT] ||= $self->[TMPLT]{def_format};
     return $expr;
   }
   elsif (ref $@) {
index f6a8d7416070fe9bb573c3b863d5e0fcb65d939b..031e31446b1b0ee8c0b7e1ffb4e84369f6e7af61 100644 (file)
@@ -239,6 +239,11 @@ If non-zero then any HTML output is validated with HTML::Tidy.
 Validation errors and warnings are sent to the audit log.  See [html
 tidy].
 
+=item tagformat
+
+The default tag formatting to use for C<< <:= ... :> >> tags.
+Default: C<html>.
+
 =back
 
 =head2 [basic]
index e27d31dc06811815f2640ad109c7d9493904eff9..1bfbdf38e0cdeb1bf745de606989e5c3118b5aeb 100644 (file)
@@ -9,15 +9,15 @@
 <:iterator begin messages:>
 <:-.set msgbase = [ state, "msg:bse/admin/imageclean/", "NOMSGID" ][1] -:>
 <:- .if state.type eq "stage" -:>
-  <h1><:= request.htmlmsg(msgbase _ "stage/" _ state.stage) -:></h1>
+  <h1><:= request.htmlmsg(msgbase _ "stage/" _ state.stage) |raw -:></h1>
 <: .elsif state.type eq "substage" -:>
-  <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) -:></h2>
+  <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) |raw -:></h2>
 <: .elsif state.type eq "orphanimage" :>
-  <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "image", [ state.image.id, state.image.image ]) :></div>
+  <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "image", [ state.image.id, state.image.image ]) |raw :></div>
 <: .elsif state.type eq "orphanfile" :>
-  <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "file", [ state.file ]) :></div>
+  <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "file", [ state.file ]) |raw :></div>
 <: .elsif state.type eq "error" :>
-<div class="message error"><:= state.error | html :></div>
+<div class="message error"><:= state.error :></div>
 <: .end if -:>
 <:iterator end messages:>
 </div>
index d9c1d7aaaf157948ed5cbf6c202807dfed647621..879387b62fa0b4303b230685792d21ec3189d9a4 100644 (file)
 <:- .if state.type eq "stage" -:>
   <h1><:= request.catmsg(msgbase _ "stage/" _ state.stage) -:></h1>
 <: .elsif state.type eq "substage" -:>
-  <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) -:></h2>
+  <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) |raw :></h2>
 <: .elsif state.type eq "orphanimage" :>
   <div><input type="checkbox" name="image" value="<:= state.image.id :>" checked="checked" />
-  <:= request.htmlmsg(msgbase _ "preview/image", [ state.image.id, state.image.image ]) :></div>
+  <:= request.htmlmsg(msgbase _ "preview/image", [ state.image.id, state.image.image ]) |raw :></div>
 <: .elsif state.type eq "orphanfile" :>
   <div><input type="checkbox" name="file" value="<:= state.file :>" checked="checked" />
-  <:= request.htmlmsg(msgbase _ "preview/file", [ state.file ]) :></div>
+  <:= request.htmlmsg(msgbase _ "preview/file", [ state.file ]) |raw:></div>
 <: .elsif state.type eq "error" :>
 <div class="message error"><:= state.error | html :></div>
 <: .end if -:>
index 470a37a05115032e968168ae4f5e9bb755be3d2e..04186f38dc2123f06cfdcb2a03b8cc91b2e1331e 100644 (file)
@@ -4,7 +4,7 @@
 
 <:.if request.messages.size != 0:>
 <:-.for m in request.messages -:>
-<div class="message <:= m.class:>"><:= m.html :></div>
+<div class="message <:= m.class:>"><:= m.html |raw:></div>
 <:.end for-:>
 <:.end if:>
 
index 3c2525beee82d41d10170c1f0afcb440313d4461..b7ea8987ae98d0e7759a5ca80a509f0de1b3a21b 100644 (file)
@@ -2,7 +2,7 @@
 <h1>Logon</h1>
 <:.if request.messages.size != 0:>
 <:-.for m in request.messages -:>
-<div class="message <:= m.class:>"><:= m.html :></div>
+<div class="message <:= m.class:>"><:= m.html |raw:></div>
 <:.end for-:>
 <:.end if:>
 <form method="post" action="<:adminbase:><:script:>">
index 5c75f9c133dd59a15b7d5913c9c036f0bb673cec..a04e8cfdf27be531194d377b85264bda2da75bec 100644 (file)
@@ -69,7 +69,7 @@ and base pages</a> (<a
 href="<:= cfg.admin_url("generate", { "id": "extras", "progress":1 }) | html :>">verbose</a>)</li></ul>
 <:or:><:eif:>
 
-<p><a href="<:= cfg.admin_url("makeIndex") | html :>">Regenerate search index</a> (<a href="<:= cfg.admin_url("makeIndex", { "progress":1 }) | html :>">verbose</a>)</p>
+<p><a href="<:= cfg.admin_url("makeIndex") | html :>">Regenerate search index</a> (<a href="<:= cfg.admin_url("makeIndex", { "verbose":1 }) | html :>">verbose</a>)</p>
 
 <p><a href="<:= cfg.admin_url("backmon") | html :>">Background processing</a></p>
 
index d9ba0987eff90737018a954c3382953b0db3829a..282a0ae3c368387249f93083027330fc9bf9f2aa 100644 (file)
@@ -85,7 +85,7 @@ Page <:= pages.page :> of <:= pages.pagecount :>
 <:.define error_img -:>
 <:# parameters: field -:>
 <:# this implementation should probably change -:>
-<:= ("error_img " _ field).evaltag -:>
+<:= ("error_img " _ field).evaltag |raw -:>
 <:.end define -:>
 
 <:.define input -:>
@@ -158,7 +158,7 @@ Page <:= pages.page :> of <:= pages.pagecount :>
 <:  .if request.messages.size -:>
 <div class="messages">
 <:     .for m in request.messages -:>
-  <div class="<:= m.class :>"><:= m.html :></div>
+  <div class="<:= m.class :>"><:= m.html |raw :></div>
 <:     .end for -:> 
 </div>
 <:  .end if -:>
index 6d7b8d481a7ce29499be05f03b7c758682824d22..49d0a35a6139e6b272f6da2d04186149743fbb91 100644 (file)
@@ -43,7 +43,7 @@ sub dyn_template_test($$$$);
 my $parent = bse_make_catalog
   (
    cfg => $cfg,
-   title => "test catalog",
+   title => "test catalog",
    body => "Test catalog for catalog tests",
    force_dynamic => 1,
   );
@@ -509,8 +509,8 @@ Top Title: [<:= top.title |html :>]
 Embedded: [<:= embedded | html :>]
 Dynamic: [<:= dynamic | html :>]
 TEMPLATE
-Article Title: [test catalog]
-Top Title: [test catalog]
+Article Title: [test &amp; catalog]
+Top Title: [test &amp; catalog]
 Embedded: [0]
 Dynamic: [1]
 EXPECTED