| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Html::Image - Image-Block in HTML | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Ein Objekt der Klasse repräsentiert einen Image-Block. Ein | ||||||||||||||||||||||||||||
| 16 | Image-Block stellt ein Bild alleinstehend dar, optional mit | ||||||||||||||||||||||||||||
| 17 | Link und Bildunterschrift. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Aufbau eines Image-Blocks: | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | [<div [class="CLASS"] [id="ID"] [style="STYLE"]>] | ||||||||||||||||||||||||||||
| 22 | [<a href="URL">] | ||||||||||||||||||||||||||||
| 23 | <img src="URL" width="WIDTH" height="HEIGHT" alt="ALT" /> | ||||||||||||||||||||||||||||
| 24 | [<p> | ||||||||||||||||||||||||||||
| 25 | <span class="prefix">PREFIX:</span> <span class="caption">CAPTION</span> | ||||||||||||||||||||||||||||
| 26 | </p>] | ||||||||||||||||||||||||||||
| 27 | [</a>] | ||||||||||||||||||||||||||||
| 28 | [</div>] | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Die in eckige Klammern eingefassten Bestandteile ([...]) sind | ||||||||||||||||||||||||||||
| 31 | optional. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Das Aussehen des Image-Block kann via CSS gestaltet werden. Hier | ||||||||||||||||||||||||||||
| 34 | einige Selektoren, mit denen Bestandteile des Konstrukts in CSS | ||||||||||||||||||||||||||||
| 35 | angesprochen werden können: | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item .CLASS | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Der gesamte Block. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item .CLASS .prefix | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Der Präfix-Text der Bildunterschrift ("Abbildung N:"). | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item .CLASS .caption | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Der Text der Bildunterschrift. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Hierbei ist CLASS der über das Attribut C<class> setzbare | ||||||||||||||||||||||||||||
| 54 | CSS-Klassenname. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =over 4 | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item alt => $text | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Alternativ-Text, wenn Bild nicht angezeigt wird. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item caption => $text | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Text der Bildunterschrift. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item captionPrefix => $text | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Präfix-Text der Bildunterschrift, z.B. "Abbildung 1:". | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =item class => $name | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | CSS-Klasse des Image-Blocks. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item height => $n | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Höhe des Bildes in Pixeln. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =item href => $url | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Hinterlege Bild mit einem Link auf URL $url. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item id => $id | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Die CSS-Id des Image-Blocks. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item src => $url | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Der URL des Bildes. Ist kein URL angegeben oder der Wert leer | ||||||||||||||||||||||||||||
| 91 | (undef oder Leerstring), wird von der Methode html() kein | ||||||||||||||||||||||||||||
| 92 | Image-Block erzeugt, sondern ein Leerstring geliefert. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =item style => $style | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | CSS-Properties des Image-Blocks (d.h. des <div>). | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =item width => $n | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Die Breite des Bildes. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | B<Leerer Block, wenn kein Bild-URL> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | $class->html($h, | ||||||||||||||||||||||||||||
| 109 | src => '', # oder undef | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | produziert: | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | '' | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | B<Block nur mit Bild> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | $class->html($h, | ||||||||||||||||||||||||||||
| 119 | src => 'illusion.png', | ||||||||||||||||||||||||||||
| 120 | width => 100, | ||||||||||||||||||||||||||||
| 121 | height => 100, | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | produziert: | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | <div> | ||||||||||||||||||||||||||||
| 127 | <img src="img/illusion.png" width="100" height="100" alt=""> | ||||||||||||||||||||||||||||
| 128 | </div> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | package Quiq::Html::Image; | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 138 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 METHODS | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head2 Konstruktor | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head3 new() - Instantiiere Verbatim-Block-Objekt | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | $e = $class->new(@keyVal); | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head4 Arguments | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =over 4 | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item @keyVal | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Liste von Attribut/Wert-Paaren. Die Werte werden auf dem Objekt | ||||||||||||||||||||||||||||
| 162 | gesetzt. Siehe Abschnitt ATTRIBUTES. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =back | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head4 Returns | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =over 4 | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item $e | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Image-Block-Objekt (Referenz) | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =back | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head4 Description | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Instantiiere ein Image-Block-Objekt und liefere eine Referenz auf | ||||||||||||||||||||||||||||
| 179 | dieses Objekt zurück. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 187 | # @_: @keyVal | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 2 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 190 | alt => undef, | ||||||||||||||||||||||||||||
| 191 | caption => undef, | ||||||||||||||||||||||||||||
| 192 | captionPrefix => undef, | ||||||||||||||||||||||||||||
| 193 | class => undef, | ||||||||||||||||||||||||||||
| 194 | height => undef, | ||||||||||||||||||||||||||||
| 195 | href => undef, | ||||||||||||||||||||||||||||
| 196 | id => undef, | ||||||||||||||||||||||||||||
| 197 | src => undef, | ||||||||||||||||||||||||||||
| 198 | style => undef, | ||||||||||||||||||||||||||||
| 199 | width => undef, | ||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||
| 201 | 2 | $self->set(@_); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | return $self; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head2 Objektmethoden | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head3 html() - Generiere HTML-Code | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | $html = $e->html($h); | ||||||||||||||||||||||||||||
| 215 | $html = $class->html($h,@keyVal); | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =head4 Arguments | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =over 4 | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =item $h | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Objekt für die HTML-Generierung, d.h. eine Instanz der Klasse | ||||||||||||||||||||||||||||
| 224 | Quiq::Html::Tag. | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =item @keyVal | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | Siehe Konstruktor. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =back | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =head4 Returns | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | HTML-Code (String) | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head4 Description | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | Generiere den HTML-Code des Image-Blocks und liefere diesen | ||||||||||||||||||||||||||||
| 239 | zurück. Als Klassenmethode gerufen, wird das Objekt intern | ||||||||||||||||||||||||||||
| 240 | mit den Attributen @keyVal instantiiert. | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 2 | ▶ | sub html { | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 2 | my $this = shift; | |||||||||||||||||||||||||||
| 248 | 2 | my $h = shift; | |||||||||||||||||||||||||||
| 249 | # @_: @keyVal | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 2 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 2 | my ($alt,$caption,$captionPrefix,$class,$height,$href,$id,$src,$style, | |||||||||||||||||||||||||||
| 254 | $width) = $self->get(qw/alt caption captionPrefix class height href | ||||||||||||||||||||||||||||
| 255 | id src style width/); | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 2 | ▶ | if (!defined($src) || $src eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $src or $src eq ""
MC/DC50%1/2
not defined $src or $src eq ""
not defined $src
$src eq ""
Truth table66%2/3
not(A) or B
A= not defined $srcB= $src eq ""
| |||||||||||||||||||||||||||||
| 258 | # Wenn kein Bild-URL gegeben ist, wird kein Code generiert | ||||||||||||||||||||||||||||
| 259 | 1 | return ''; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 1 | return $h->tag('div', | |||||||||||||||||||||||||||
| 263 | class => $class, | ||||||||||||||||||||||||||||
| 264 | id => $id, | ||||||||||||||||||||||||||||
| 265 | style => $style, | ||||||||||||||||||||||||||||
| 266 | '-', | ||||||||||||||||||||||||||||
| 267 | $h->tag('a', | ||||||||||||||||||||||||||||
| 268 | -fmt => 'v', | ||||||||||||||||||||||||||||
| 269 | -ignoreTagIf => !$href, | ||||||||||||||||||||||||||||
| 270 | href => $href, | ||||||||||||||||||||||||||||
| 271 | '-', | ||||||||||||||||||||||||||||
| 272 | $h->tag('img', | ||||||||||||||||||||||||||||
| 273 | -fmt => 'e', | ||||||||||||||||||||||||||||
| 274 | src => $src, | ||||||||||||||||||||||||||||
| 275 | alt => $alt, | ||||||||||||||||||||||||||||
| 276 | width => $width, | ||||||||||||||||||||||||||||
| 277 | height => $height, | ||||||||||||||||||||||||||||
| 278 | ), | ||||||||||||||||||||||||||||
| 279 | ), | ||||||||||||||||||||||||||||
| 280 | $h->tag('p', | ||||||||||||||||||||||||||||
| 281 | '-', | ||||||||||||||||||||||||||||
| 282 | $h->tag('span', | ||||||||||||||||||||||||||||
| 283 | class => 'prefix', | ||||||||||||||||||||||||||||
| 284 | $captionPrefix | ||||||||||||||||||||||||||||
| 285 | ), | ||||||||||||||||||||||||||||
| 286 | $h->tag('span', | ||||||||||||||||||||||||||||
| 287 | class => 'caption', | ||||||||||||||||||||||||||||
| 288 | $caption | ||||||||||||||||||||||||||||
| 289 | ), | ||||||||||||||||||||||||||||
| 290 | ), | ||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =head1 VERSION | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 1.240 | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 311 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | =cut | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 1 | 1; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # eof | ||||||||||||||||||||||||||||