diff options
author | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-10 20:42:51 +0000 |
---|---|---|
committer | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-10 20:42:51 +0000 |
commit | 99535516a8275b3c98a90cb037d2c88219c2b756 (patch) | |
tree | 66dadc45c8914b3d3d0d2949c277c5514bcf3c46 /lib/Reaction/UI | |
parent | ad0b52c377cccb45543fbd76d2e85288dfe4045e (diff) | |
download | reaction-99535516a8275b3c98a90cb037d2c88219c2b756.tar.gz reaction-99535516a8275b3c98a90cb037d2c88219c2b756.zip |
String fragment viewport
Diffstat (limited to 'lib/Reaction/UI')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field/String/Fragment.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm b/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm new file mode 100644 index 0000000..4205769 --- /dev/null +++ b/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm @@ -0,0 +1,44 @@ +package Reaction::UI::ViewPort::Field::String::Fragment; + +use Reaction::Class; +use MooseX::Types::Moose qw/Int/; +extends 'Reaction::UI::ViewPort::Field::String'; + +has max_length => ( + is => 'rw', + isa => Int, + required => 1, + default => sub { 80 } +); + +sub _build_layout { 'field/string' }; + +around _build_value_string => sub { + my $super = shift; + my $self = $_[0]; + my $string = $super->(@_); + my $max_len = $self->max_length; + if(length($string) > $max_len){ + $string = join('', substr( $string, 0, $max_len - 3 ), '...'); + } + return $string; +}; + +1; + +__END__; + +=head1 DESCRIPTION + +If it was possible to address the widgets in any way this wouldn't be necessary. + +Ideally this would be a widget instead of a viewport. But there is currently no +way to implement this in a widget, because it is impossible to pass any +arguments to widgets. + +Using this module will require subclassing the Object or Member Viewport to +override the builder classes for the field you desire to render as a string +fragment. If we ever get a way to pass arguments to layouts or widgets, this +will be greatly simplified. Don't hold your breath. + +=cut |