Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 71f55f78

Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt

  • ID 71f55f78545971d867d1e3abe9daaee0f6a1e380
  • Vorgänger 37a84d92
  • Nachfolger ad9563c8

HTML-IDs aus Attributnamen nur mit für IDs gültigen Zeichen bilden

Unterschiede anzeigen:

SL/Template/Plugin/L.pm
17 17
  return bless { }, $class;
18 18
}
19 19

  
20
sub name_to_id {
21
  my $self =  shift;
22
  my $name =  shift;
23

  
24
  $name    =~ s/[^\w_]/_/g;
25
  $name    =~ s/_+/_/g;
26

  
27
  return $name;
28
}
29

  
20 30
sub attributes {
21 31
  my $self    = shift;
22 32
  my $options = shift || {};
......
48 58
  my $attributes        = shift || {};
49 59

  
50 60
  $attributes->{name}   = $name;
51
  $attributes->{id}   ||= $name;
61
  $attributes->{id}   ||= $self->name_to_id($name);
52 62

  
53 63
  return $self->html_tag('select', $options_str, $attributes);
54 64
}
......
106 116

  
107 117
=head1 FUNCTIONS
108 118

  
119
=head2 LOW-LEVEL FUNCTIONS
120

  
109 121
=over 4
110 122

  
123
=item C<name_to_id $name>
124

  
125
Converts a name to a HTML id by replacing various characters.
126

  
111 127
=item C<attributes \%items>
112 128

  
113 129
Creates a string from all elements in C<\%items> suitable for usage as
......
121 137
or empty then only a E<lt>tag/E<gt> tag will be created. Attributes
122 138
are key/value pairs added to the opening tag.
123 139

  
140
C<$content_string> is not HTML escaped.
141

  
142
=back
143

  
144
=head2 HIGH-LEVEL FUNCTIONS
145

  
146
=over 4
147

  
148
=item C<select_tag $name, $options_string, \%attributes>
149

  
150
Creates a HTML 'select' tag named $name with the contents
151
$options_string and with arbitrary HTML attributes from
152
C<\%attributes>. The tag's C<id> defaults to C<name_to_id($name)>.
153

  
154
The $options_string is usually created by the C<options_for_select>
155
function.
156

  
157
=back
158

  
159
=head2 CONVERSION FUNCTIONS
160

  
161
=over 4
162

  
124 163
=item C<options_for_select \@collection, \%options>
125 164

  
126 165
Creates a string suitable for a HTML 'select' tag consisting of one
......
149 188
For cases 3 and 4 C<$options{value}> defaults to C<id> and
150 189
C<$options{title}> defaults to C<$options{value}>.
151 190

  
152
=item C<select_tag $name, $options_string, \%attributes>
153

  
154
Creates a HTML 'select' tag named $name with the contents
155
$options_string and with arbitrary HTML attributes from
156
C<\%attributes>. The tag's C<id> defaults to C<$name>.
157

  
158
The $options_string is usually created by the C<options_for_select>
159
function.
160

  
161 191
=back
162 192

  
163 193
=head1 MODULE AUTHORS

Auch abrufbar als: Unified diff