Revision 7395dba6
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
SL/Layout/Base.pm | ||
---|---|---|
107 | 107 |
|
108 | 108 |
|
109 | 109 |
######################################### |
110 |
# Interface
|
|
110 |
# Stylesheets
|
|
111 | 111 |
######################################## |
112 | 112 |
|
113 |
# override in sub layouts |
|
114 |
sub static_stylesheets {} |
|
115 |
|
|
113 | 116 |
sub add_stylesheets { |
114 | 117 |
&use_stylesheet; |
115 | 118 |
} |
... | ... | |
117 | 120 |
sub use_stylesheet { |
118 | 121 |
my $self = shift; |
119 | 122 |
push @{ $self->{stylesheets} ||= [] }, @_ if @_; |
120 |
@{ $self->{stylesheets} ||= [] }; |
|
123 |
(map { $_->use_stylesheet } $self->sub_layouts), $self->static_stylesheets, @{ $self->{stylesheets} ||= [] };
|
|
121 | 124 |
} |
122 | 125 |
|
123 | 126 |
sub stylesheets { |
... | ... | |
125 | 128 |
my $css_path = $self->get_stylesheet_for_user; |
126 | 129 |
|
127 | 130 |
return uniq grep { $_ } map { $self->_find_stylesheet($_, $css_path) } |
128 |
$self->use_stylesheet, map { $_->use_stylesheet } $self->sub_layouts;
|
|
131 |
$self->use_stylesheet; |
|
129 | 132 |
} |
130 | 133 |
|
131 | 134 |
sub _find_stylesheet { |
... | ... | |
154 | 157 |
return $css_path; |
155 | 158 |
} |
156 | 159 |
|
160 |
######################################### |
|
161 |
# Javascripts |
|
162 |
######################################## |
|
163 |
|
|
164 |
# override in sub layouts |
|
165 |
sub static_javascripts {} |
|
166 |
|
|
157 | 167 |
sub add_javascripts { |
158 | 168 |
&use_javascript |
159 | 169 |
} |
... | ... | |
161 | 171 |
sub use_javascript { |
162 | 172 |
my $self = shift; |
163 | 173 |
push @{ $self->{javascripts} ||= [] }, @_ if @_; |
164 |
@{ $self->{javascripts} ||= [] }; |
|
174 |
map({ $_->use_javascript } $self->sub_layouts), $self->static_javascripts, @{ $self->{javascripts} ||= [] };
|
|
165 | 175 |
} |
166 | 176 |
|
167 | 177 |
sub javascripts { |
168 | 178 |
my ($self) = @_; |
169 | 179 |
|
170 | 180 |
return uniq grep { $_ } map { $self->_find_javascript($_) } |
171 |
map({ $_->use_javascript } $self->sub_layouts), $self->use_javascript;
|
|
181 |
$self->use_javascript; |
|
172 | 182 |
} |
173 | 183 |
|
174 | 184 |
sub _find_javascript { |
... | ... | |
289 | 299 |
$_[0]->SUPER::post_content |
290 | 300 |
} |
291 | 301 |
|
292 |
For the stylesheet and javascript callbacks things are hard, because of the |
|
293 |
backwards compatibility, and the built-in sanity checks. The best way currently |
|
294 |
is to just add your content and dispatch to the base method. |
|
295 | 302 |
|
296 |
sub stylesheets { |
|
297 |
$_[0]->add_stylesheets(qw(mystyle1.css mystyle2.css); |
|
298 |
$_[0]->SUPER::stylesheets; |
|
303 |
Stylesheets and Javascripts can be added to every layout and sub-layout at |
|
304 |
runtime with L</add_stylesheets> and L</add_javascripts> (C<use_stylesheets> |
|
305 |
and C<use_javascripts> are aliases for backwards compatibility): |
|
306 |
|
|
307 |
$layout->add_stylesheets("custom.css"); |
|
308 |
$layout->add_javascripts("app.js", "widget.js"); |
|
309 |
|
|
310 |
Or they can be overwritten in sub layouts with the calls L</static_stylesheets> |
|
311 |
and L</static_javascripts>: |
|
312 |
|
|
313 |
sub static_stylesheets { |
|
314 |
"custom.css" |
|
315 |
} |
|
316 |
|
|
317 |
sub static_javascripts { |
|
318 |
qw(app.css widget.js) |
|
299 | 319 |
} |
300 | 320 |
|
321 |
Note how these are relative to the base dirs of the currently selected |
|
322 |
stylesheets. Javascripts are resolved relative to the C<js/> basedir. |
|
323 |
|
|
324 |
Setting directly with C<stylesheets> and C<javascripts> is eprecated. |
|
325 |
|
|
326 |
|
|
301 | 327 |
=head1 GORY DETAILS ABOUT JAVASCRIPT AND STYLESHEET OVERLOADING |
302 | 328 |
|
303 | 329 |
The original code used to store one stylesheet in C<< $form->{stylesheet} >> and |
Auch abrufbar als: Unified diff
Layout::Base: besseres sub_layout javascript/css dispatching
sub_layouts werden jetzt mit add/use aggregiert. add/use gibt aber immer
auch die der sub_layouts zurück.
Statt die zu überschreiben gibt es jetzt die neuen callbacks
die zusätzlich zurückgeliefert werden.
Die alten einstiegspunkte
machen jetzt die Auflösung in die Webpfade, so dass nur das oberste
layout den Mechanismus überschreiben braucht wenn benötigt.