From 71f55f78545971d867d1e3abe9daaee0f6a1e380 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 8 Jan 2010 14:56:36 +0100 Subject: [PATCH] =?utf8?q?HTML-IDs=20aus=20Attributnamen=20nur=20mit=20f?= =?utf8?q?=C3=BCr=20IDs=20g=C3=BCltigen=20Zeichen=20bilden?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Template/Plugin/L.pm | 50 ++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index f044fc165..93de09bb2 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -17,6 +17,16 @@ sub new { return bless { }, $class; } +sub name_to_id { + my $self = shift; + my $name = shift; + + $name =~ s/[^\w_]/_/g; + $name =~ s/_+/_/g; + + return $name; +} + sub attributes { my $self = shift; my $options = shift || {}; @@ -48,7 +58,7 @@ sub select_tag { my $attributes = shift || {}; $attributes->{name} = $name; - $attributes->{id} ||= $name; + $attributes->{id} ||= $self->name_to_id($name); return $self->html_tag('select', $options_str, $attributes); } @@ -106,8 +116,14 @@ functions that create HTML tags from various kinds of data sources. =head1 FUNCTIONS +=head2 LOW-LEVEL FUNCTIONS + =over 4 +=item C + +Converts a name to a HTML id by replacing various characters. + =item C Creates a string from all elements in C<\%items> suitable for usage as @@ -121,6 +137,29 @@ C<$content_string> between the two. If C<$content_string> is undefined or empty then only a Etag/E tag will be created. Attributes are key/value pairs added to the opening tag. +C<$content_string> is not HTML escaped. + +=back + +=head2 HIGH-LEVEL FUNCTIONS + +=over 4 + +=item C + +Creates a HTML 'select' tag named $name with the contents +$options_string and with arbitrary HTML attributes from +C<\%attributes>. The tag's C defaults to C. + +The $options_string is usually created by the C +function. + +=back + +=head2 CONVERSION FUNCTIONS + +=over 4 + =item C Creates a string suitable for a HTML 'select' tag consisting of one @@ -149,15 +188,6 @@ respectively. For cases 3 and 4 C<$options{value}> defaults to C and C<$options{title}> defaults to C<$options{value}>. -=item C - -Creates a HTML 'select' tag named $name with the contents -$options_string and with arbitrary HTML attributes from -C<\%attributes>. The tag's C defaults to C<$name>. - -The $options_string is usually created by the C -function. - =back =head1 MODULE AUTHORS -- 2.20.1