line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::CSSLoader; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: move css loading to the end of the document |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
5864
|
use strict; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
343
|
|
6
|
10
|
|
|
10
|
|
43
|
use warnings; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
340
|
|
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
4556
|
use parent 'Mojolicious::Plugin'; |
|
10
|
|
|
|
|
2829
|
|
|
10
|
|
|
|
|
56
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.06; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
10
|
|
|
10
|
1
|
6968
|
my ($self, $app, $config) = @_; |
14
|
|
|
|
|
|
|
|
15
|
10
|
|
100
|
|
|
59
|
my $base = $config->{base} || ''; |
16
|
10
|
|
100
|
|
|
42
|
my $media = $config->{media} || ''; |
17
|
|
|
|
|
|
|
|
18
|
10
|
100
|
66
|
|
|
58
|
if ( $base and substr( $base, -1 ) ne '/' ) { |
19
|
2
|
|
|
|
|
4
|
$base .= '/'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$app->helper( css_load => sub { |
23
|
36
|
|
|
36
|
|
637234
|
my $c = shift; |
24
|
|
|
|
|
|
|
|
25
|
36
|
100
|
|
|
|
168
|
if ( $_[1]->{check} ) { |
26
|
7
|
50
|
|
|
|
139
|
my $asset = $c->app->static->file( |
27
|
|
|
|
|
|
|
$_[1]->{no_base} ? $_[0] : "$base$_[0]" |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
7
|
100
|
|
|
|
927
|
return '' if !$asset; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
33
|
|
|
|
|
97
|
push @{ $c->stash->{__CSSLOADERFILES__} }, [ @_ ]; |
|
33
|
|
|
|
|
89
|
|
34
|
10
|
|
|
|
|
87
|
} ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$app->hook( after_render => sub { |
37
|
24
|
|
|
24
|
|
7949
|
my ($c, $content, $format) = @_; |
38
|
|
|
|
|
|
|
|
39
|
24
|
50
|
|
|
|
100
|
return if $format ne 'html'; |
40
|
24
|
100
|
|
|
|
76
|
return if !$c->stash->{__CSSLOADERFILES__}; |
41
|
|
|
|
|
|
|
|
42
|
33
|
|
|
|
|
66
|
my $load_css = |
43
|
|
|
|
|
|
|
join "\n", |
44
|
|
|
|
|
|
|
map{ |
45
|
33
|
50
|
|
|
|
190
|
my ($file,$config) = @{ $_ }; |
|
23
|
|
|
|
|
256
|
|
46
|
33
|
100
|
|
|
|
94
|
my $local_base = $config->{no_base} ? '' : $base; |
47
|
33
|
|
|
|
|
49
|
my $local_media = ""; |
48
|
|
|
|
|
|
|
|
49
|
33
|
100
|
|
|
|
78
|
$local_media = ' media="' . $media . '"' if $media; |
50
|
33
|
100
|
|
|
|
90
|
$local_media = ' media="' . $config->{media} . '"' if $config->{media}; |
51
|
|
|
|
|
|
|
|
52
|
33
|
|
|
|
|
50
|
my $ie_start = ''; |
53
|
33
|
|
|
|
|
37
|
my $ie_end = ''; |
54
|
|
|
|
|
|
|
|
55
|
33
|
100
|
|
|
|
82
|
if ( exists $config->{ie} ) { |
56
|
7
|
|
|
|
|
9
|
my $start_extra = ''; |
57
|
7
|
|
|
|
|
12
|
my $end_extra = ''; |
58
|
7
|
|
|
|
|
9
|
my $cmp = ''; |
59
|
7
|
|
|
|
|
9
|
my $version = ''; |
60
|
|
|
|
|
|
|
|
61
|
7
|
100
|
100
|
|
|
40
|
if ( !ref $config->{ie} && !$config->{ie} ) { |
|
|
100
|
|
|
|
|
|
62
|
1
|
|
|
|
|
2
|
$start_extra = ''; |
63
|
1
|
|
|
|
|
1
|
$end_extra = '", $end_extra; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
33
|
100
|
|
|
|
214
|
$config->{no_file} ? |
82
|
|
|
|
|
|
|
qq~$ie_start$ie_end~ : |
83
|
|
|
|
|
|
|
qq~$ie_start$ie_end~; |
84
|
|
|
|
|
|
|
} |
85
|
23
|
|
|
|
|
195
|
@{ $c->stash->{__CSSLOADERFILES__} || [] }; |
86
|
|
|
|
|
|
|
|
87
|
23
|
50
|
|
|
|
84
|
return if !$load_css; |
88
|
|
|
|
|
|
|
|
89
|
23
|
100
|
|
|
|
28
|
${$content} =~ s!()!$load_css$1! or ${$content} = $load_css . ${$content}; |
|
22
|
|
|
|
|
56
|
|
|
22
|
|
|
|
|
42
|
|
|
23
|
|
|
|
|
124
|
|
90
|
10
|
|
|
|
|
962
|
}); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |