diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-17 15:35:59 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-17 15:35:59 +0100 |
commit | c8f39ab32bd46e4a4b578a018655d84b41223a60 (patch) | |
tree | a57e8c8504152e4866ef60ddd87a6bfcb1990d30 /perllib/FixMyStreet/App/View/Web.pm | |
parent | 7372afa95033cc39546664ad7a4f335bb7ea3e53 (diff) |
add split_into_lines method
Diffstat (limited to 'perllib/FixMyStreet/App/View/Web.pm')
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index cbb68df0d..61d7c6ca5 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -17,6 +17,7 @@ __PACKAGE__->config( render_die => 1, expose_methods => [ 'loc', 'nget', 'tprintf', 'display_crossell_advert', 'prettify_epoch', + 'split_into_lines', ], ); @@ -105,5 +106,28 @@ sub prettify_epoch { return Page::prettify_epoch( $c->req, $epoch, $short_bool ); } +=head2 split_into_lines + + [% FOREACH line IN split_into_lines( text ) %] + <p> + [% line | html %] + </p> + [% END %] + +Split some text into an array of lines on double new lines. + +=cut + +sub split_into_lines { + my ( $self, $c, $text ) = @_; + + my @lines; + $text =~ s/\r//g; + + @lines = split /\n{2,}/, $text; + + return \@lines; +} + 1; |