aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/View/Web.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2016-09-16 17:58:16 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-09-20 17:18:35 +0100
commit148d702917f54327f82e49fe605e5a0d9f2e31ca (patch)
tree465574714026090bda8301a655a1176c5323d426 /perllib/FixMyStreet/App/View/Web.pm
parent99abfad00e301e3a261820db0d54470d9c4ef10c (diff)
Use shared Template base for all templates.
Reduce some duplicated code, and as a side effect gives HTML emails our internal html_para filter, allowing single line returns in contact form submissions.
Diffstat (limited to 'perllib/FixMyStreet/App/View/Web.pm')
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm71
1 files changed, 4 insertions, 67 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 2a3948381..ae06181c8 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -4,26 +4,24 @@ use base 'Catalyst::View::TT';
use strict;
use warnings;
-use mySociety::Locale;
use FixMyStreet;
+use FixMyStreet::Template;
use Utils;
__PACKAGE__->config(
+ CLASS => 'FixMyStreet::Template',
TEMPLATE_EXTENSION => '.html',
INCLUDE_PATH => [
FixMyStreet->path_to( 'templates', 'web', 'base' ),
],
- ENCODING => 'utf8',
render_die => 1,
expose_methods => [
- 'loc', 'nget', 'tprintf', 'prettify_dt',
+ 'tprintf', 'prettify_dt',
'version', 'decode',
],
FILTERS => {
add_links => \&add_links,
escape_js => \&escape_js,
- html => \&html_filter,
- html_para => \&html_paragraph,
},
COMPILE_EXT => '.ttc',
STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400,
@@ -48,32 +46,6 @@ sub _rendering_error {
return 0;
}
-=head2 loc
-
- [% loc('Some text to localize', 'Optional comment for translator') %]
-
-Passes the text to the localisation engine for translations.
-
-=cut
-
-sub loc {
- my ( $self, $c, $msgid ) = @_;
- return _($msgid);
-}
-
-=head2 nget
-
- [% nget( 'singular', 'plural', $number ) %]
-
-Use first or second srting depending on the number.
-
-=cut
-
-sub nget {
- my ( $self, $c, @args ) = @_;
- return mySociety::Locale::nget(@args);
-}
-
=head2 tprintf
[% tprintf( 'foo %s bar', 'insert' ) %]
@@ -115,7 +87,7 @@ Add some links to some text (and thus HTML-escapes the other text.
sub add_links {
my $text = shift;
$text =~ s/\r//g;
- $text = html_filter($text);
+ $text = FixMyStreet::Template::html_filter($text);
$text =~ s{(https?://)([^\s]+)}{"<a href=\"$1$2\">$1" . _space_slash($2) . '</a>'}ge;
return $text;
}
@@ -148,41 +120,6 @@ sub escape_js {
return $text;
}
-=head2 html_filter
-
-Same as Template Toolkit's html_filter, but escapes ' too, as we don't (and
-shouldn't have to) know whether we'll be used inbetween single or double
-quotes.
-
-=cut
-
-sub html_filter {
- my $text = shift;
- for ($text) {
- s/&/&amp;/g;
- s/</&lt;/g;
- s/>/&gt;/g;
- s/"/&quot;/g;
- s/'/&#39;/g;
- }
- return $text;
-}
-
-=head2 html_paragraph
-
-Same as Template Toolkit's html_paragraph, but converts single newlines
-into <br>s too.
-
-=cut
-
-sub html_paragraph {
- my $text = shift;
- my @paras = split(/(?:\r?\n){2,}/, $text);
- s/\r?\n/<br>\n/ for @paras;
- $text = "<p>\n" . join("\n</p>\n\n<p>\n", @paras) . "</p>\n";
- return $text;
-}
-
my %version_hash;
sub version {
my ( $self, $c, $file ) = @_;