Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 14 files changed
  • 0 comments
  • 1 contributor
32 site/cgi-bin/modules/BSE/Template.pm
@@ -4,7 +4,24 @@ use Squirrel::Template;
4 4 use Carp qw(confess cluck);
5 5 use Config ();
6 6
7   -our $VERSION = "1.009";
  7 +our $VERSION = "1.010";
  8 +
  9 +my %formats =
  10 + (
  11 + html => sub {
  12 + require BSE::Util::HTML;
  13 + return BSE::Util::HTML::escape_html($_[0]);
  14 + },
  15 + uri => sub {
  16 + require BSE::Util::HTML;
  17 + return BSE::Util::HTML::escape_uri($_[0]);
  18 + },
  19 + raw => sub {
  20 + return $_[0];
  21 + },
  22 + );
  23 +$formats{h} = $formats{html};
  24 +$formats{u} = $formats{uri};
8 25
9 26 sub templater {
10 27 my ($class, $cfg, $rsets) = @_;
@@ -26,17 +43,8 @@ sub templater {
26 43 template_dir => \@dirs,
27 44 utf8 => $cfg->utf8,
28 45 charset => $cfg->charset,
29   - formats =>
30   - {
31   - html => sub {
32   - require BSE::Util::HTML;
33   - return BSE::Util::HTML::escape_html($_[0]);
34   - },
35   - uri => sub {
36   - require BSE::Util::HTML;
37   - return BSE::Util::HTML::escape_uri($_[0]);
38   - },
39   - },
  46 + formats => \%formats,
  47 + def_format => $cfg->entry("html", "tagformat", "html"),
40 48 trace_noimpl => scalar($cfg->entry("debug", "trace_noimpl", 0)),
41 49 );
42 50 if ($cfg->entry("basic", "cache_templates")) {
46 site/cgi-bin/modules/Generate.pm
@@ -13,7 +13,7 @@ use BSE::Variables;
13 13 use base 'BSE::ThumbLow';
14 14 use base 'BSE::TagFormats';
15 15
16   -our $VERSION = "1.014";
  16 +our $VERSION = "1.015";
17 17
18 18 my $excerptSize = 300;
19 19
@@ -41,6 +41,22 @@ sub cfg {
41 41 $_[0]{cfg};
42 42 }
43 43
  44 +sub url {
  45 + my ($self, $article, $force_abs) = @_;
  46 +
  47 + my $url = $self->{admin_links} ? $article->admin : $article->link;
  48 + if (!$self->{admin} && $self->{admin_links}) {
  49 + $url .= $url =~ /\?/ ? "&" : "?";
  50 + $url .= "admin=0&admin_links=1";
  51 + }
  52 +
  53 + if (($force_abs || $self->abs_urls) && $url !~ /^\w+:/) {
  54 + $url = $self->cfg->entryErr("site", "url") . $url;
  55 + }
  56 +
  57 + return $url;
  58 +}
  59 +
44 60 sub site {
45 61 my $self = shift;
46 62 $self->{site} ||= BSE::TB::Site->new;
@@ -818,6 +834,9 @@ sub baseActs {
818 834 my $art_it = BSE::Util::Iterate::Article->new(cfg => $cfg,
819 835 admin => $self->{admin},
820 836 top => $self->{top});
  837 + my $weak_self = $self;
  838 + Scalar::Util::weaken($weak_self);
  839 + $self->set_variable(url => sub { $weak_self->url(@_) });
821 840 return
822 841 (
823 842 %extras,
@@ -1496,6 +1515,31 @@ Conditional tag, true if the current article is being embedded.
1496 1515
1497 1516 =back
1498 1517
  1518 +=head1 VARIABLES
  1519 +
  1520 +Template variables:
  1521 +
  1522 +=over
  1523 +
  1524 +=item *
  1525 +
  1526 +url(article)
  1527 +
  1528 +=item *
  1529 +
  1530 +url(article, 1)
  1531 +
  1532 +Return a URL for the given article, depending on admin_links mode. If
  1533 +the page is being generated with absolute URLs or a second true
  1534 +parameter is supplied, the URL is convrted to an absolute URL if
  1535 +necessary.
  1536 +
  1537 +=item *
  1538 +
  1539 +articles - the articles class.
  1540 +
  1541 +=back
  1542 +
1499 1543 =head1 BUGS
1500 1544
1501 1545 Needs more documentation.
12 site/cgi-bin/modules/Squirrel/Template.pm
@@ -20,7 +20,7 @@ BEGIN {
20 20
21 21 use constant DEBUG_GET_PARMS => 0;
22 22
23   -our $VERSION = "1.024";
  23 +our $VERSION = "1.025";
24 24
25 25 my %compile_cache;
26 26
@@ -34,6 +34,7 @@ sub new {
34 34 $opts{param} = [];
35 35 $opts{wraps} = [];
36 36 $opts{errors} = [];
  37 + $opts{def_format} ||= "";
37 38
38 39 return bless \%opts, $class;
39 40 }
@@ -644,6 +645,15 @@ by template files. Defaults to C<"utf-8">.
644 645 A BSE::Cache object to use for caching compiled templates. Note that
645 646 templates are currently only cached by filename.
646 647
  648 +=item formats
  649 +
  650 +A hashref of content formatters used for formatting C<< E<lt>=
  651 +... E<gt> >> tags.
  652 +
  653 +=item def_format
  654 +
  655 +The default format for C<< E<lt>= ... E<gt> >> tags.
  656 +
647 657 =back
648 658
649 659 =item show_page()
3  site/cgi-bin/modules/Squirrel/Template/Parser.pm
@@ -2,7 +2,7 @@ package Squirrel::Template::Parser;
2 2 use strict;
3 3 use Squirrel::Template::Constants qw(:token :node);
4 4
5   -our $VERSION = "1.013";
  5 +our $VERSION = "1.014";
6 6
7 7 use constant TOK => 0;
8 8 use constant TMPLT => 1;
@@ -131,6 +131,7 @@ sub _parse_expr {
131 131 my $parsed;
132 132 if (eval { $parsed = $parser->parse($expr->[TOKEN_EXPR_EXPR]); 1 }) {
133 133 $expr->[NODE_EXPR_EXPR] = $parsed;
  134 + $expr->[NODE_EXPR_FORMAT] ||= $self->[TMPLT]{def_format};
134 135 return $expr;
135 136 }
136 137 elsif (ref $@) {
5 site/docs/config.pod
Source Rendered
@@ -239,6 +239,11 @@ If non-zero then any HTML output is validated with HTML::Tidy.
239 239 Validation errors and warnings are sent to the audit log. See [html
240 240 tidy].
241 241
  242 +=item tagformat
  243 +
  244 +The default tag formatting to use for C<< <:= ... :> >> tags.
  245 +Default: C<html>.
  246 +
242 247 =back
243 248
244 249 =head2 [basic]
2  site/templates/admin/generate.tmpl
... ... @@ -1,4 +1,4 @@
1   -<:wrap admin/base.tmpl title => "Regenarate site":>
  1 +<:wrap admin/base.tmpl title => "Regenerate site":>
2 2
3 3 <h1>Regenerating</h1>
4 4
10 site/templates/admin/imageclean/final.tmpl
@@ -9,15 +9,15 @@
9 9 <:iterator begin messages:>
10 10 <:-.set msgbase = [ state, "msg:bse/admin/imageclean/", "NOMSGID" ][1] -:>
11 11 <:- .if state.type eq "stage" -:>
12   - <h1><:= request.htmlmsg(msgbase _ "stage/" _ state.stage) -:></h1>
  12 + <h1><:= request.htmlmsg(msgbase _ "stage/" _ state.stage) |raw -:></h1>
13 13 <: .elsif state.type eq "substage" -:>
14   - <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) -:></h2>
  14 + <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) |raw -:></h2>
15 15 <: .elsif state.type eq "orphanimage" :>
16   - <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "image", [ state.image.id, state.image.image ]) :></div>
  16 + <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "image", [ state.image.id, state.image.image ]) |raw :></div>
17 17 <: .elsif state.type eq "orphanfile" :>
18   - <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "file", [ state.file ]) :></div>
  18 + <div><:= request.htmlmsg(msgbase _ "process/" _ ( acted ? "remove" : "skip" ) _ "file", [ state.file ]) |raw :></div>
19 19 <: .elsif state.type eq "error" :>
20   -<div class="message error"><:= state.error | html :></div>
  20 +<div class="message error"><:= state.error :></div>
21 21 <: .end if -:>
22 22 <:iterator end messages:>
23 23 </div>
6 site/templates/admin/imageclean/preview.tmpl
@@ -12,13 +12,13 @@
12 12 <:- .if state.type eq "stage" -:>
13 13 <h1><:= request.catmsg(msgbase _ "stage/" _ state.stage) -:></h1>
14 14 <: .elsif state.type eq "substage" -:>
15   - <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) -:></h2>
  15 + <h2><:= request.htmlmsg(msgbase _ "substage/" _ state.stage _ "/" _ state.substage) |raw :></h2>
16 16 <: .elsif state.type eq "orphanimage" :>
17 17 <div><input type="checkbox" name="image" value="<:= state.image.id :>" checked="checked" />
18   - <:= request.htmlmsg(msgbase _ "preview/image", [ state.image.id, state.image.image ]) :></div>
  18 + <:= request.htmlmsg(msgbase _ "preview/image", [ state.image.id, state.image.image ]) |raw :></div>
19 19 <: .elsif state.type eq "orphanfile" :>
20 20 <div><input type="checkbox" name="file" value="<:= state.file :>" checked="checked" />
21   - <:= request.htmlmsg(msgbase _ "preview/file", [ state.file ]) :></div>
  21 + <:= request.htmlmsg(msgbase _ "preview/file", [ state.file ]) |raw:></div>
22 22 <: .elsif state.type eq "error" :>
23 23 <div class="message error"><:= state.error | html :></div>
24 24 <: .end if -:>
2  site/templates/admin/import/start.tmpl
@@ -4,7 +4,7 @@
4 4
5 5 <:.if request.messages.size != 0:>
6 6 <:-.for m in request.messages -:>
7   -<div class="message <:= m.class:>"><:= m.html :></div>
  7 +<div class="message <:= m.class:>"><:= m.html |raw:></div>
8 8 <:.end for-:>
9 9 <:.end if:>
10 10
2  site/templates/admin/logon.tmpl
@@ -2,7 +2,7 @@
2 2 <h1>Logon</h1>
3 3 <:.if request.messages.size != 0:>
4 4 <:-.for m in request.messages -:>
5   -<div class="message <:= m.class:>"><:= m.html :></div>
  5 +<div class="message <:= m.class:>"><:= m.html |raw:></div>
6 6 <:.end for-:>
7 7 <:.end if:>
8 8 <form method="post" action="<:adminbase:><:script:>">
2  site/templates/admin/menu.tmpl
@@ -69,7 +69,7 @@ and base pages</a> (<a
69 69 href="<:= cfg.admin_url("generate", { "id": "extras", "progress":1 }) | html :>">verbose</a>)</li></ul>
70 70 <:or:><:eif:>
71 71
72   -<p><a href="<:= cfg.admin_url("makeIndex") | html :>">Regenerate search index</a> (<a href="<:= cfg.admin_url("makeIndex", { "progress":1 }) | html :>">verbose</a>)</p>
  72 +<p><a href="<:= cfg.admin_url("makeIndex") | html :>">Regenerate search index</a> (<a href="<:= cfg.admin_url("makeIndex", { "verbose":1 }) | html :>">verbose</a>)</p>
73 73
74 74 <p><a href="<:= cfg.admin_url("backmon") | html :>">Background processing</a></p>
75 75
32 site/templates/base.tmpl
... ... @@ -1,10 +1,32 @@
1 1 <html>
2 2 <head>
3   -<title><:switch:><:case ifEq [param title] "FORMTITLE":><:formcfg title:><:case article pageTitle:><:article pageTitle:><:case default:><:article title:><:endswitch:> - <:siteName:></title>
4   -<meta name="ROBOTS" content="ALL">
5   -<meta http-equiv="Content-Type" content="text/html; charset=<:cfg html charset "iso-8859-1":>">
6   -<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT">
7   -<link rel="stylesheet" type="text/css" href="/css/style-main.css">
  3 +<title>
  4 +<:-.if params.title -:>
  5 + <:-.if params.title eq "FORMTITLE" -:>
  6 + <:formcfg title:>
  7 + <:-.else -:>
  8 + <:= params.title :>
  9 + <:-.end if -:>
  10 +<:-.else -:>
  11 + <:= article.pageTitle or article.title :>
  12 +<:-.end if-:>
  13 +<:= " - " _ cfg.entry("site", "name") :></title>
  14 + <meta name="ROBOTS" content="ALL">
  15 + <meta http-equiv="Content-Type" content="text/html; charset=<:cfg html charset "iso-8859-1":>">
  16 + <meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT">
  17 +<:- .if article.author:>
  18 + <meta name="author" content="<:= article.author :>" />
  19 +<:- .end if:>
  20 +<:- .if article.metaKeywords :>
  21 + <meta name="keywords" content="<:= article.metaKeywords:>" />
  22 +<:- .end if:>
  23 +<:- .if article.metaDescription :>
  24 + <meta name="description" content="<:= article.metaDescription:>" />
  25 +<:- .end if:>
  26 +<:- .if article.linkAlias or article.id == 1:>
  27 + <link rel="stylesheet" type="text/css" href="/css/style-main.css">
  28 + <link rel="canonical" href="<:= url(article, 1) :>" />
  29 +<:- .end if:>
8 30 <:ajax includes:>
9 31 <script type="text/javascript" src="/js/bse.js"></script>
10 32 <:ifCfg "flv" "flowenable":><script type="text/javascript" src="/js/bse_flowplayer.js"></script><:or:><:eif:>
4 site/templates/preload.tmpl
@@ -85,7 +85,7 @@ Page <:= pages.page :> of <:= pages.pagecount :>
85 85 <:.define error_img -:>
86 86 <:# parameters: field -:>
87 87 <:# this implementation should probably change -:>
88   -<:= ("error_img " _ field).evaltag -:>
  88 +<:= ("error_img " _ field).evaltag |raw -:>
89 89 <:.end define -:>
90 90
91 91 <:.define input -:>
@@ -158,7 +158,7 @@ Page <:= pages.page :> of <:= pages.pagecount :>
158 158 <: .if request.messages.size -:>
159 159 <div class="messages">
160 160 <: .for m in request.messages -:>
161   - <div class="<:= m.class :>"><:= m.html :></div>
  161 + <div class="<:= m.class :>"><:= m.html |raw :></div>
162 162 <: .end for -:>
163 163 </div>
164 164 <: .end if -:>
6 t/050-local/050-dyncat.t
@@ -43,7 +43,7 @@ sub dyn_template_test($$$$);
43 43 my $parent = bse_make_catalog
44 44 (
45 45 cfg => $cfg,
46   - title => "test catalog",
  46 + title => "test & catalog",
47 47 body => "Test catalog for catalog tests",
48 48 force_dynamic => 1,
49 49 );
@@ -509,8 +509,8 @@ Top Title: [<:= top.title |html :>]
509 509 Embedded: [<:= embedded | html :>]
510 510 Dynamic: [<:= dynamic | html :>]
511 511 TEMPLATE
512   -Article Title: [test catalog]
513   -Top Title: [test catalog]
  512 +Article Title: [test &amp; catalog]
  513 +Top Title: [test &amp; catalog]
514 514 Embedded: [0]
515 515 Dynamic: [1]
516 516 EXPECTED

No commit comments for this range

Something went wrong with that request. Please try again.