diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-05-27 22:52:06 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-05-27 22:52:06 +0100 |
commit | ca393af1d89f6ff98e6b0f44d506c8621e3b74cc (patch) | |
tree | eb9bf491894600235bbc7f6eed62691396fe5374 /perllib/FixMyStreet/App | |
parent | 9593e182ca601d8b8a3b4564e9072fa74473823c (diff) |
Pull requests #103 and #107, clickable-urls-in-reports, done as a TT function.
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 8f1aaa085..63aade4c9 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -5,6 +5,7 @@ use strict; use warnings; use mySociety::Locale; +use mySociety::Web qw(ent); use FixMyStreet; use CrossSell; @@ -17,7 +18,7 @@ __PACKAGE__->config( render_die => 1, expose_methods => [ 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', - 'split_into_lines', + 'add_links', ], ); @@ -106,27 +107,21 @@ sub prettify_epoch { return Page::prettify_epoch( $c->req, $epoch, $short_bool ); } -=head2 split_into_lines +=head2 add_links - [% FOREACH line IN split_into_lines( text ) %] - <p> - [% line | html %] - </p> - [% END %] + [% add_links( text ) | html_para %] -Split some text into an array of lines on double new lines. +Add some links to some text (and thus HTML-escapes the other text. =cut -sub split_into_lines { +sub add_links { my ( $self, $c, $text ) = @_; - my @lines; $text =~ s/\r//g; - - @lines = split /\n{2,}/, $text; - - return \@lines; + $text = ent($text); + $text =~ s{(https?://[^\s]+)}{<a href="$1">$1</a>}g; + return $text; } 1; |