Revision 4f15b8f0
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/Template/Plugin/L.pm | ||
---|---|---|
52 | 52 |
return $_[0]->{CONTEXT}; |
53 | 53 |
} |
54 | 54 |
|
55 |
sub _call_presenter { |
|
56 |
my ($method, @args) = @_; |
|
57 |
|
|
58 |
my $presenter = $::request->presenter; |
|
59 |
|
|
60 |
return '' unless $presenter->can($method); |
|
61 |
|
|
62 |
splice @args, -1, 1, %{ $args[-1] } if @args && (ref($args[-1]) eq 'HASH'); |
|
63 |
|
|
64 |
$presenter->$method(@args); |
|
65 |
} |
|
66 |
|
|
55 | 67 |
sub name_to_id { |
56 | 68 |
my $self = shift; |
57 | 69 |
my $name = shift; |
... | ... | |
596 | 608 |
} |
597 | 609 |
|
598 | 610 |
sub truncate { |
599 |
my ($self, $text, @slurp) = @_; |
|
600 |
my %params = _hashify(@slurp); |
|
601 |
|
|
602 |
$params{at} ||= 50; |
|
603 |
$params{at} = 3 if 3 > $params{at}; |
|
604 |
$params{at} -= 3; |
|
605 |
|
|
606 |
return $text if length($text) < $params{at}; |
|
607 |
return substr($text, 0, $params{at}) . '...'; |
|
611 |
my $self = shift; |
|
612 |
return _call_presenter('truncate', @_); |
|
608 | 613 |
} |
609 | 614 |
|
610 | 615 |
sub sortable_table_header { |
... | ... | |
651 | 656 |
return SL::Presenter->get->render('common/paginate', %template_params); |
652 | 657 |
} |
653 | 658 |
|
659 |
sub simple_format { |
|
660 |
my $self = shift; |
|
661 |
return _call_presenter('simple_format', @_); |
|
662 |
} |
|
663 |
|
|
654 | 664 |
1; |
655 | 665 |
|
656 | 666 |
__END__ |
... | ... | |
1005 | 1015 |
|
1006 | 1016 |
L.tab('Awesome tab wih much info', '_much_info.html', if => SELF.wants_all) |
1007 | 1017 |
|
1008 |
=item C<truncate $text, %params> |
|
1018 |
=item C<truncate $text, [%params]> |
|
1019 |
|
|
1020 |
See L<SL::Presenter::Text/truncate>. |
|
1009 | 1021 |
|
1010 |
Returns the C<$text> truncated after a certain number of |
|
1011 |
characters. |
|
1022 |
=item C<simple_format $text> |
|
1012 | 1023 |
|
1013 |
The number of characters to truncate at is determined by the parameter |
|
1014 |
C<at> which defaults to 50. If the text is longer than C<$params{at}> |
|
1015 |
then it will be truncated and postfixed with '...'. Otherwise it will |
|
1016 |
be returned unmodified. |
|
1024 |
See L<SL::Presenter::Text/simple_format>. |
|
1017 | 1025 |
|
1018 | 1026 |
=back |
1019 | 1027 |
|
Auch abrufbar als: Unified diff
L: "truncate" und "simple_format" in Presenter verschoben