Revision 46b49275
Von Moritz Bunkus vor mehr als 12 Jahren hinzugefügt
SL/Template/Plugin/L.pm | ||
---|---|---|
570 | 570 |
return '<pre>' . Data::Dumper::Dumper(@_) . '</pre>'; |
571 | 571 |
} |
572 | 572 |
|
573 |
sub truncate { |
|
574 |
my ($self, $text, @slurp) = @_; |
|
575 |
my %params = _hashify(@slurp); |
|
576 |
|
|
577 |
$params{at} ||= 50; |
|
578 |
$params{at} = 3 if 3 > $params{at}; |
|
579 |
$params{at} -= 3; |
|
580 |
|
|
581 |
return $text if length($text) < $params{at}; |
|
582 |
return substr($text, 0, $params{at}) . '...'; |
|
583 |
} |
|
584 |
|
|
573 | 585 |
1; |
574 | 586 |
|
575 | 587 |
__END__ |
... | ... | |
918 | 930 |
|
919 | 931 |
L.tab('Awesome tab wih much info', '_much_info.html', if => SELF.wants_all) |
920 | 932 |
|
933 |
=item C<truncate $text, %params> |
|
934 |
|
|
935 |
Returns the C<$text> truncated after a certain number of |
|
936 |
characters. |
|
937 |
|
|
938 |
The number of characters to truncate at is determined by the parameter |
|
939 |
C<at> which defaults to 50. If the text is longer than C<$params{at}> |
|
940 |
then it will be truncated and postfixed with '...'. Otherwise it will |
|
941 |
be returned unmodified. |
|
942 |
|
|
921 | 943 |
=back |
922 | 944 |
|
923 | 945 |
=head1 MODULE AUTHORS |
Auch abrufbar als: Unified diff
L.truncate: Funktion zum intelligenten Verkürzen eines Strings