aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-08-17 13:18:58 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-08-17 13:18:58 +0100
commitecc2f777c9f00425eccf0816042ece1e455d7c70 (patch)
tree0a2fcc2c9cb3d63392190e5109025b5d5f25d1e5
parent7359d0776b9ebe93207455931bba8858460a7b3b (diff)
Reduce size of JS output strings.
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm2
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm21
-rw-r--r--templates/web/default/maps/openlayers.html2
-rw-r--r--templates/web/default/report/new/category.html13
-rw-r--r--templates/web/default/report/new/councils_text.html3
5 files changed, 32 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index c93ca7334..0f871508e 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -269,7 +269,7 @@ sub ajax : Path('/ajax') {
);
# JSON encode the response
- my $body = JSON->new->utf8(1)->pretty(1)->encode(
+ my $body = JSON->new->utf8(1)->encode(
{
pins => $pins,
current => $on_map_list_html,
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 44f80e375..5579d0d53 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -23,6 +23,7 @@ __PACKAGE__->config(
],
FILTERS => {
escape_js => \&escape_js,
+ html => \&html_filter,
},
COMPILE_EXT => '.ttc',
STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400,
@@ -144,5 +145,25 @@ 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;
+}
+
1;
diff --git a/templates/web/default/maps/openlayers.html b/templates/web/default/maps/openlayers.html
index b84799fdd..3cf615306 100644
--- a/templates/web/default/maps/openlayers.html
+++ b/templates/web/default/maps/openlayers.html
@@ -9,7 +9,7 @@
var fixmystreet = {
'page': '[% page %]',
'area': '[% map.area %]',
- 'all_pins': [% all_pins || "''" | html %],
+ 'all_pins': '[% all_pins %]',
'latitude': [% map.latitude %],
'longitude': [% map.longitude %],
[% IF map.any_zoom -%]
diff --git a/templates/web/default/report/new/category.html b/templates/web/default/report/new/category.html
index 3db776f1a..6ec0eb19f 100644
--- a/templates/web/default/report/new/category.html
+++ b/templates/web/default/report/new/category.html
@@ -1,9 +1,10 @@
+[% FILTER collapse %]
[% IF category_options.size %]
- <label for="form_category">[% category_label | html %]</label>
- <select name="category" id="form_category">
- [%- FOREACH cat_op IN category_options %]
- <option value="[% cat_op | html %]"[% ' selected' IF report.category == cat_op %]>[% cat_op | html %]</option>
- [%- END %]
+ <label for='form_category'>[% category_label | html %]</label>
+ <select name='category' id='form_category'>
+ [% FOREACH cat_op IN category_options %]
+ <option value='[% cat_op | html %]'[% ' selected' IF report.category == cat_op %]>[% cat_op | html %]</option>
+ [% END %]
</select>
[% END %]
-
+[% END -%]
diff --git a/templates/web/default/report/new/councils_text.html b/templates/web/default/report/new/councils_text.html
index d463f399f..1da5746c1 100644
--- a/templates/web/default/report/new/councils_text.html
+++ b/templates/web/default/report/new/councils_text.html
@@ -1,3 +1,4 @@
+[% FILTER collapse %]
[% IF area_ids_to_list.size == 0 %]
[% PROCESS 'report/new/councils_text_none.html' %]
[% ELSIF area_ids_to_list.size == all_councils.size %]
@@ -5,4 +6,4 @@
[% ELSE %]
[% PROCESS 'report/new/councils_text_some.html' %]
[% END %]
-
+[% END -%]