1 package SL::Presenter::Text;
 
   5 use SL::Presenter::EscapedText qw(escape);
 
   7 use Exporter qw(import);
 
   8 our @EXPORT_OK = qw(format_man_days simple_format truncate);
 
   9 our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
 
  14   my ($text, %params) = @_;
 
  16   escape(Common::truncate($text, %params));
 
  20   my ($text, %params) = @_;
 
  22   $text =  $::locale->quote_special_chars('HTML', $text || '');
 
  24   $text =~ s{\r\n?}{\n}g;                    # \r\n and \r -> \n
 
  25   $text =~ s{\n\n+}{</p>\n\n<p>}g;           # 2+ newline  -> paragraph
 
  26   $text =~ s{([^\n]\n)(?=[^\n])}{$1<br />}g; # 1 newline   -> br
 
  32   my ($value, %params) = @_;
 
  34   return '---' if $params{skip_zero} && !$value;
 
  36   return escape($::locale->text('#1 h', $::form->format_amount(\%::myconfig, $value, 2))) if 8.0 > $value;
 
  39   my $output  = $::locale->text('#1 MD', int($value));
 
  40   my $rest    = ($value - int($value)) * 8.0;
 
  41   $output    .= ' ' . $::locale->text('#1 h', $::form->format_amount(\%::myconfig, $rest)) if $rest > 0.0;
 
  55 SL::Presenter::Text - Presenter module for assorted text helpers
 
  59   use  SL::Presenter::Text qw(truncate);
 
  61   my $long_text = "This is very, very long. Need shorter, surely.";
 
  62   my $truncated = truncate($long_text, at => 10);
 
  63   # Result: "This is..."
 
  69 =item C<format_man_days $value, [%params]>
 
  71 C<$value> is interpreted to mean a number of hours (for C<$value> < 8)
 
  72 / man days (if >= 8). Returns a translated, human-readable version of
 
  73 it, e.g. C<2 PT 2 h> for the value C<18> and German.
 
  75 If the parameter C<skip_zero> is trueish then C<---> is returned
 
  76 instead of the normal formatting if C<$value> equals 0.
 
  78 =item C<truncate $text, %params>
 
  80 Returns the C<$text> truncated after a certain number of
 
  81 characters. See L<Common/truncate> for the actual implementation and
 
  84 =item C<simple_format $text>
 
  86 Applies simple formatting rules to C<$text>: The text is put into
 
  87 paragraph HTML tags. Two consecutive newlines are interpreted as a
 
  88 paragraph change: they close the current paragraph tag and start a new
 
  89 one. Single newlines are converted to line breaks. Carriage returns
 
 100 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>