| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||
| 4 | |||||||||||||||
| 5 | =head1 NAME | ||||||||||||||
| 6 | |||||||||||||||
| 7 | Quiq::Html::List - HTML-Aufzählungsliste | ||||||||||||||
| 8 | |||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||
| 10 | |||||||||||||||
| 11 | L<Quiq::Html::Base> | ||||||||||||||
| 12 | |||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||
| 14 | |||||||||||||||
| 15 | Die Klasse dient der Erzeugung von Aufzählungslisten in HTML. | ||||||||||||||
| 16 | Sie kann die Listenarten | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =over 2 | ||||||||||||||
| 19 | |||||||||||||||
| 20 | =item * | ||||||||||||||
| 21 | |||||||||||||||
| 22 | Ordered List (<ol>) | ||||||||||||||
| 23 | |||||||||||||||
| 24 | =item * | ||||||||||||||
| 25 | |||||||||||||||
| 26 | Unordered List (<ul>) | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =item * | ||||||||||||||
| 29 | |||||||||||||||
| 30 | Description List (<dl>) | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =back | ||||||||||||||
| 33 | |||||||||||||||
| 34 | erzeugen. Siehe Abschnitt L<EXAMPLES|"EXAMPLES">. | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =head1 ATTRIBUTES | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =over 4 | ||||||||||||||
| 39 | |||||||||||||||
| 40 | =item isText => $bool (Default: 0) | ||||||||||||||
| 41 | |||||||||||||||
| 42 | Der Content aller List-Items besteht aus Text, d.h. <, >, & werden | ||||||||||||||
| 43 | geschützt. | ||||||||||||||
| 44 | |||||||||||||||
| 45 | =item items => \@arr (Default: []) | ||||||||||||||
| 46 | |||||||||||||||
| 47 | Content der List-Items. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =item type => 'ordered' | 'unordered' | 'description' (Default: 'unordered') | ||||||||||||||
| 50 | |||||||||||||||
| 51 | Legt fest, ob die Aufzählungsliste eine I<Ordered List> (<ol>), eine | ||||||||||||||
| 52 | I<Unordered List> (<ul>) oder eine I<Description List> (<dl>) ist. | ||||||||||||||
| 53 | |||||||||||||||
| 54 | =back | ||||||||||||||
| 55 | |||||||||||||||
| 56 | =head1 EXAMPLES | ||||||||||||||
| 57 | |||||||||||||||
| 58 | =head2 Unordered List | ||||||||||||||
| 59 | |||||||||||||||
| 60 | Die I<Unordered List> ist der Default. | ||||||||||||||
| 61 | |||||||||||||||
| 62 | Der Aufruf | ||||||||||||||
| 63 | |||||||||||||||
| 64 | $html = Quiq::Html::List->html($h, | ||||||||||||||
| 65 | id => 'list01', | ||||||||||||||
| 66 | class => 'list', | ||||||||||||||
| 67 | isText => 1, | ||||||||||||||
| 68 | items => ['Apfel & Birne','Orange','Pflaume','Zitrone'], | ||||||||||||||
| 69 | ); | ||||||||||||||
| 70 | |||||||||||||||
| 71 | liefert | ||||||||||||||
| 72 | |||||||||||||||
| 73 | <ul id="list01" class="list"> | ||||||||||||||
| 74 | <li>Apfel & Birne</li> | ||||||||||||||
| 75 | <li>Orange</li> | ||||||||||||||
| 76 | <li>Pflaume</li> | ||||||||||||||
| 77 | <li>Zitrone</li> | ||||||||||||||
| 78 | </ul> | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =head2 Ordered List | ||||||||||||||
| 81 | |||||||||||||||
| 82 | Eine I<Ordered List> wird bei Setzung des Attributs | ||||||||||||||
| 83 | C<< type=>'ordered' >> erzeugt. | ||||||||||||||
| 84 | |||||||||||||||
| 85 | Der Aufruf | ||||||||||||||
| 86 | |||||||||||||||
| 87 | $html = Quiq::Html::List->html($h, | ||||||||||||||
| 88 | type => 'ordered', | ||||||||||||||
| 89 | id => 'list02', | ||||||||||||||
| 90 | class => 'list', | ||||||||||||||
| 91 | isText => 1, | ||||||||||||||
| 92 | items => ['Apfel & Birne','Orange','Pflaume','Zitrone'], | ||||||||||||||
| 93 | ); | ||||||||||||||
| 94 | |||||||||||||||
| 95 | liefert | ||||||||||||||
| 96 | |||||||||||||||
| 97 | <ol id="list02" class="list"> | ||||||||||||||
| 98 | <li>Apfel & Birne</li> | ||||||||||||||
| 99 | <li>Orange</li> | ||||||||||||||
| 100 | <li>Pflaume</li> | ||||||||||||||
| 101 | <li>Zitrone</li> | ||||||||||||||
| 102 | </ol> | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =cut | ||||||||||||||
| 105 | |||||||||||||||
| 106 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 107 | |||||||||||||||
| 108 | package Quiq::Html::List; | ||||||||||||||
| 109 | 4 | ▶ | use base qw/Quiq::Html::Base/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 110 | |||||||||||||||
| 111 | 4 | ▶ | use v5.10; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 112 | 4 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 113 | 4 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 114 | |||||||||||||||
| 115 | 4 | our $VERSION = '1.240'; | |||||||||||||
| 116 | |||||||||||||||
| 117 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head1 METHODS | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =head2 Konstruktor | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =head3 new() - Instantiiere Objekt | ||||||||||||||
| 124 | |||||||||||||||
| 125 | =head4 Synopsis | ||||||||||||||
| 126 | |||||||||||||||
| 127 | $obj = $class->new(@keyVal); | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =head4 Description | ||||||||||||||
| 130 | |||||||||||||||
| 131 | Instantiiere ein Aufzählungslisten-Objekt und liefere eine | ||||||||||||||
| 132 | Referenz auf dieses Objekt zurück. | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =cut | ||||||||||||||
| 135 | |||||||||||||||
| 136 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 137 | |||||||||||||||
| 138 | 3 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 139 | 3 | my $class = shift; | |||||||||||||
| 140 | # @_: @keyVal | ||||||||||||||
| 141 | |||||||||||||||
| 142 | 3 | my $self = $class->SUPER::new( | |||||||||||||
| 143 | items => [], | ||||||||||||||
| 144 | isText => 0, | ||||||||||||||
| 145 | type => 'unordered', | ||||||||||||||
| 146 | ); | ||||||||||||||
| 147 | 3 | $self->set(@_); | |||||||||||||
| 148 | |||||||||||||||
| 149 | 3 | return $self; | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | |||||||||||||||
| 152 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 153 | |||||||||||||||
| 154 | =head2 Objektmethoden | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =head3 html() - Generiere HTML | ||||||||||||||
| 157 | |||||||||||||||
| 158 | =head4 Synopsis | ||||||||||||||
| 159 | |||||||||||||||
| 160 | $html = $obj->html($h); | ||||||||||||||
| 161 | $html = $class->html($h,@keyVal); | ||||||||||||||
| 162 | |||||||||||||||
| 163 | =head4 Description | ||||||||||||||
| 164 | |||||||||||||||
| 165 | Generiere den HTML-Code eines Aufzählungslisten-Objekts und liefere | ||||||||||||||
| 166 | diesen zurück. Als Klassenmethode gerufen, wird das Objekt intern | ||||||||||||||
| 167 | erzeugt und mit den Attributen @keyVal instantiiert. | ||||||||||||||
| 168 | |||||||||||||||
| 169 | =cut | ||||||||||||||
| 170 | |||||||||||||||
| 171 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 172 | |||||||||||||||
| 173 | 3 | ▶ | sub html { | ||||||||||||
|
Subroutine
html: called CC=8 SCAR=26.0
Pod
documented
| |||||||||||||||
| 174 | 3 | my $this = shift; | |||||||||||||
| 175 | 3 | my $h = shift; | |||||||||||||
| 176 | |||||||||||||||
| 177 | 3 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 178 | |||||||||||||||
| 179 | 3 | my ($class,$id,$itemA,$isText,$type) = | |||||||||||||
| 180 | $self->get(qw/class id items isText type/); | ||||||||||||||
| 181 | |||||||||||||||
| 182 | 3 | ▶ | if ($type eq 'description') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 183 | 0 | $type = 'dl'; | |||||||||||||
| 184 | } | ||||||||||||||
| 185 | elsif ($type eq 'ordered') { | ||||||||||||||
| 186 | 1 | $type = 'ol'; | |||||||||||||
| 187 | } | ||||||||||||||
| 188 | else { | ||||||||||||||
| 189 | 2 | $type = 'ul'; | |||||||||||||
| 190 | } | ||||||||||||||
| 191 | |||||||||||||||
| 192 | return $h->tag($type, | ||||||||||||||
| 193 | id => $id, | ||||||||||||||
| 194 | class => $class, | ||||||||||||||
| 195 | 3 | do { | |||||||||||||
| 196 | 3 | my $html; | |||||||||||||
| 197 | 3 | ▶ | if ($type eq 'dl') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | 0 | ▶ | for (my $i = 0; $i < @$itemA; $i += 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 199 | 0 | my $val = $itemA->[$i+1]; | |||||||||||||
| 200 | 0 | ▶ | if (!defined($val)) { # || $val eq '') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 201 | 0 | next; | |||||||||||||
| 202 | } | ||||||||||||||
| 203 | 0 | $html .= $h->tag('dt', | |||||||||||||
| 204 | -text => $isText, | ||||||||||||||
| 205 | $itemA->[$i] | ||||||||||||||
| 206 | ); | ||||||||||||||
| 207 | # Wir rücken <dd> zusätzlich ein | ||||||||||||||
| 208 | 0 | my $tmp = $h->tag('dd', | |||||||||||||
| 209 | -text => $isText, | ||||||||||||||
| 210 | $val | ||||||||||||||
| 211 | ); | ||||||||||||||
| 212 | 0 | $tmp =~ s/^/ /mg; | |||||||||||||
| 213 | 0 | $html .= $tmp; | |||||||||||||
| 214 | } | ||||||||||||||
| 215 | } | ||||||||||||||
| 216 | else { | ||||||||||||||
| 217 | 3 | for my $item (@$itemA) { | |||||||||||||
| 218 | 10 | $html .= $h->tag('li', | |||||||||||||
| 219 | -text => $isText, | ||||||||||||||
| 220 | $item, | ||||||||||||||
| 221 | ); | ||||||||||||||
| 222 | } | ||||||||||||||
| 223 | } | ||||||||||||||
| 224 | 3 | $html; | |||||||||||||
| 225 | } | ||||||||||||||
| 226 | ); | ||||||||||||||
| 227 | } | ||||||||||||||
| 228 | |||||||||||||||
| 229 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 230 | |||||||||||||||
| 231 | =head1 VERSION | ||||||||||||||
| 232 | |||||||||||||||
| 233 | 1.240 | ||||||||||||||
| 234 | |||||||||||||||
| 235 | =head1 AUTHOR | ||||||||||||||
| 236 | |||||||||||||||
| 237 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||
| 238 | |||||||||||||||
| 239 | =head1 COPYRIGHT | ||||||||||||||
| 240 | |||||||||||||||
| 241 | Copyright (C) 2026 Frank Seitz | ||||||||||||||
| 242 | |||||||||||||||
| 243 | =head1 LICENSE | ||||||||||||||
| 244 | |||||||||||||||
| 245 | This code is free software; you can redistribute it and/or modify | ||||||||||||||
| 246 | it under the same terms as Perl itself. | ||||||||||||||
| 247 | |||||||||||||||
| 248 | =cut | ||||||||||||||
| 249 | |||||||||||||||
| 250 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 251 | |||||||||||||||
| 252 | 4 | 1; | |||||||||||||
| 253 | |||||||||||||||
| 254 | # eof | ||||||||||||||