Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5e9aaf1c

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 5e9aaf1c3e83467ed4f6550627f8c7e6ec6fa811
  • Vorgänger 29185b68
  • Nachfolger 1436ca8d

_hashify: verallgemeinert, getestet, nach SL::Util verschoben (und das dabei erfunden)

Unterschiede anzeigen:

SL/Template/Plugin/L.pm
7 7
use Scalar::Util qw(blessed);
8 8

  
9 9
use SL::Presenter;
10
use SL::Util qw(_hashify);
10 11

  
11 12
use strict;
12 13

  
......
30 31
  return $string;
31 32
}
32 33

  
33
sub _hashify {
34
  return (@_ && (ref($_[0]) eq 'HASH')) ? %{ $_[0] } : @_;
35
}
36

  
37 34
sub new {
38 35
  my ($class, $context, @args) = @_;
39 36

  
......
75 72
}
76 73

  
77 74
sub img_tag {
78
  my ($self, @slurp) = @_;
79
  my %options = _hashify(@slurp);
75
  my ($self, %options) = _hashify(1, @_);
80 76

  
81 77
  $options{alt} ||= '';
82 78

  
......
84 80
}
85 81

  
86 82
sub textarea_tag {
87
  my ($self, $name, $content, @slurp) = @_;
88
  my %attributes      = _hashify(@slurp);
83
  my ($self, $name, $content, %attributes) = _hashify(3, @_);
89 84

  
90 85
  _set_id_attribute(\%attributes, $name);
91 86
  $attributes{rows}  *= 1; # required by standard
......
96 91
}
97 92

  
98 93
sub checkbox_tag {
99
  my ($self, $name, @slurp) = @_;
100
  my %attributes       = _hashify(@slurp);
94
  my ($self, $name, %attributes) = _hashify(2, @_);
101 95

  
102 96
  _set_id_attribute(\%attributes, $name);
103 97
  $attributes{value}   = 1 unless defined $attributes{value};
......
118 112
}
119 113

  
120 114
sub radio_button_tag {
121
  my $self             = shift;
122
  my $name             = shift;
123
  my %attributes       = _hashify(@_);
115
  my ($self, $name, %attributes) = _hashify(2, @_);
124 116

  
125 117
  _set_id_attribute(\%attributes, $name);
126 118
  $attributes{value}   = 1 unless defined $attributes{value};
......
139 131
}
140 132

  
141 133
sub hidden_tag {
142
  my ($self, $name, $value, @slurp) = @_;
143
  return $self->input_tag($name, $value, _hashify(@slurp), type => 'hidden');
134
  my ($self, $name, $value, %attributes) = _hashify(3, @_);
135
  return $self->input_tag($name, $value, %attributes, type => 'hidden');
144 136
}
145 137

  
146 138
sub div_tag {
......
159 151
}
160 152

  
161 153
sub link {
162
  my ($self, $href, $content, @slurp) = @_;
163
  my %params = _hashify(@slurp);
154
  my ($self, $href, $content, %params) = _hashify(3, @_);
164 155

  
165 156
  $href ||= '#';
166 157

  
......
168 159
}
169 160

  
170 161
sub submit_tag {
171
  my ($self, $name, $value, @slurp) = @_;
172
  my %attributes = _hashify(@slurp);
162
  my ($self, $name, $value, %attributes) = _hashify(3, @_);
173 163

  
174 164
  if ( $attributes{confirm} ) {
175 165
    $attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");';
......
179 169
}
180 170

  
181 171
sub button_tag {
182
  my ($self, $onclick, $value, @slurp) = @_;
183
  my %attributes = _hashify(@slurp);
172
  my ($self, $onclick, $value, %attributes) = _hashify(3, @_);
184 173

  
185 174
  _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name};
186 175
  $attributes{type} ||= 'button';
......
201 190
}
202 191

  
203 192
sub yes_no_tag {
204
  my ($self, $name, $value) = splice @_, 0, 3;
205
  my %attributes            = _hashify(@_);
193
  my ($self, $name, $value, %attributes) = _hashify(3, @_);
206 194

  
207 195
  return $self->select_tag($name, [ [ 1 => $::locale->text('Yes') ], [ 0 => $::locale->text('No') ] ], default => $value ? 1 : 0, %attributes);
208 196
}
......
228 216

  
229 217
my $date_tag_id_idx = 0;
230 218
sub date_tag {
231
  my ($self, $name, $value, @slurp) = @_;
219
  my ($self, $name, $value, %params) = _hashify(3, @_);
232 220

  
233
  my %params   = _hashify(@slurp);
234 221
  _set_id_attribute(\%params, $name);
235 222
  my @onchange = $params{onchange} ? (onChange => delete $params{onchange}) : ();
236 223
  my @class    = $params{no_cal} || $params{readonly} ? () : (class => 'datepicker');
......
299 286
}
300 287

  
301 288
sub tabbed {
302
  my ($self, $tabs, @slurp) = @_;
303
  my %params   = _hashify(@slurp);
289
  my ($self, $tabs, %params) = _hashify(2, @_);
304 290
  my $id       = $params{id} || 'tab_' . _tag_id();
305 291

  
306 292
  $params{selected} *= 1;
......
326 312
}
327 313

  
328 314
sub tab {
329
  my ($self, $name, $src, @slurp) = @_;
330
  my %params = _hashify(@slurp);
315
  my ($self, $name, $src, %params) = _hashify(3, @_);
331 316

  
332 317
  $params{method} ||= 'process';
333 318

  
......
348 333
}
349 334

  
350 335
sub areainput_tag {
351
  my ($self, $name, $value, @slurp) = @_;
352
  my %attributes      = _hashify(@slurp);
336
  my ($self, $name, $value, %attributes) = _hashify(3, @_);
353 337

  
354 338
  my ($rows, $cols);
355 339
  my $min  = delete $attributes{min_rows} || 1;
......
367 351
}
368 352

  
369 353
sub multiselect2side {
370
  my ($self, $id, @slurp) = @_;
371
  my %params              = _hashify(@slurp);
354
  my ($self, $id, %params) = _hashify(2, @_);
372 355

  
373 356
  $params{labelsx}        = "\"" . _J($params{labelsx} || $::locale->text('Available')) . "\"";
374 357
  $params{labeldx}        = "\"" . _J($params{labeldx} || $::locale->text('Selected'))  . "\"";
......
387 370
}
388 371

  
389 372
sub sortable_element {
390
  my ($self, $selector, @slurp) = @_;
391
  my %params                    = _hashify(@slurp);
373
  my ($self, $selector, %params) = _hashify(2, @_);
392 374

  
393 375
  my %attributes = ( distance => 5,
394 376
                     helper   => <<'JAVASCRIPT' );
......
445 427
}
446 428

  
447 429
sub online_help_tag {
448
  my ($self, $tag, @slurp) = @_;
449
  my %params               = _hashify(@slurp);
430
  my ($self, $tag, %params) = _hashify(2, @_);
450 431
  my $cc                   = $::myconfig{countrycode};
451 432
  my $file                 = "doc/online/$cc/$tag.html";
452 433
  my $text                 = $params{text} || $::locale->text('Help');
......
463 444
}
464 445

  
465 446
sub sortable_table_header {
466
  my ($self, $by, @slurp) = @_;
467
  my %params              = _hashify(@slurp);
447
  my ($self, $by, %params) = _hashify(2, @_);
468 448

  
469 449
  my $controller          = $self->{CONTEXT}->stash->get('SELF');
470 450
  my $sort_spec           = $controller->get_sort_spec;
......
495 475
  my %template_params = (
496 476
    pages             => \%paginate_params,
497 477
    url_maker         => sub {
498
      my %url_params                                    = _hashify(@_);
478
      my %url_params                                    = _hashify(0, @_);
499 479
      $url_params{ $paginate_spec->{FORM_PARAMS}->[0] } = delete $url_params{page};
500 480
      $url_params{ $paginate_spec->{FORM_PARAMS}->[1] } = delete $url_params{per_page} if exists $url_params{per_page};
501 481

  

Auch abrufbar als: Unified diff