Bivio::UI::HTML::Widget::Title
# Copyright (c) 1999-2001 bivio Software, Inc. All rights reserved. # $Id$ package Bivio::UI::HTML::Widget::Title; use strict; # NAME # # Bivio::UI::HTML::Widget::Title - renders title from subtopic, topic, and realm # # RELEASE SCOPE # # bOP # # SYNOPSIS # # use Bivio::UI::HTML::Widget::Title; # Bivio::UI::HTML::Widget::Title->new($attrs); # # EXTENDS # # Bivio::UI::Widget # use Bivio::UI::Widget; @Bivio::UI::HTML::Widget::Title::ISA = qw(Bivio::UI::Widget); # DESCRIPTION # # Bivio::UI::HTML::Widget::Title adds a level of titleion to # the rendering of widgets. The widget which is this widget's value # is rendered dynamically by accessing this widget's attributes dynamically. # # ATTRIBUTES # # # values : array_ref (required) # # Each element will be rendered with # Bivio::UI::Widget::unsafe_render_value # # If result is undef or zerol length, no value # is rendered. In all cases, the strings are passed to escaped. # # title_separator : string [' - '] (inherited) # # Used to separate values in title. # # #=IMPORTS use Bivio::HTML; #=VARIABLES my($_IDI) = __PACKAGE__->instance_data_index; my($_DEFAULT_SEPARATOR) = ' - '; # FACTORIES # # # static new(array_ref values, string separator, hash_ref attributes) : Bivio::UI::HTML::Widget::Form # # static new(hash_ref attributes) : Bivio::UI::HTML::Widget::Form # # Creates a new Form widget. # sub new { my($self) = shift->SUPER::new(@_); $self->[$_IDI] = {}; return $self; } # METHODS # # # initialize() # # No op. # sub initialize { my($self) = @_; my($fields) = $self->[$_IDI]; return if $fields->{values}; my($i) = 0; $fields->{values} = [map { $self->initialize_value($i++, $_); } @{$self->get('values')}]; $fields->{separator} = $self->ancestral_get('title_separator', $_DEFAULT_SEPARATOR); return; } # # static internal_new_args() : hash_ref # # Implements positional argument parsing for new. # sub internal_new_args { my(undef, $values, $seperator, $attributes) = @_; return '"values" must be defined' unless ref($values); return { values => $values, (defined($seperator) ? (seperator => $seperator) : ()), ($attributes ? %$attributes : ()), }; } # # render(any source, string_ref buffer) # # Render the title by joining the values. We set the Title in the # reply as well. # sub render { my($self, $source, $buffer) = @_; my($fields) = $self->[$_IDI]; my(@v, @t) = (); my($i) = 0; foreach my $v (@{$fields->{values}}) { my($x) = $v; if (ref($x)) { my($b) = ''; $self->unsafe_render_value($i++, $x, $source, \$b); next unless length($b); $x = $b; } push(@v, Bivio::HTML->escape($x)); push(@t, $x); } $$buffer .= '<title>'.join($fields->{separator}, @v)."</title>\n"; $source->get('reply')->set_header('Title', join($fields->{separator}, @t)); return; } #=PRIVATE METHODS # COPYRIGHT # # Copyright (c) 1999-2001 bivio Software, Inc. All rights reserved. # # VERSION # # $Id$ # 1;