From ca393af1d89f6ff98e6b0f44d506c8621e3b74cc Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 27 May 2011 22:52:06 +0100 Subject: Pull requests #103 and #107, clickable-urls-in-reports, done as a TT function. --- perllib/FixMyStreet/App/View/Web.pm | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'perllib/FixMyStreet/App/View/Web.pm') 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 ) %] -

- [% line | html %] -

- [% 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]+)}{$1}g; + return $text; } 1; -- cgit v1.2.3