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
|
11
|
|
|
11
|
|
6789
|
use strict; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
447
|
|
6
|
11
|
|
|
11
|
|
55
|
use warnings; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
373
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
5567
|
use parent 'Mojolicious::Plugin'; |
|
11
|
|
|
|
|
3140
|
|
|
11
|
|
|
|
|
73
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.07; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
11
|
|
|
11
|
1
|
9683
|
my ($self, $app, $config) = @_; |
14
|
|
|
|
|
|
|
|
15
|
11
|
|
100
|
|
|
80
|
my $base = $config->{base} || ''; |
16
|
11
|
|
100
|
|
|
62
|
my $media = $config->{media} || ''; |
17
|
|
|
|
|
|
|
|
18
|
11
|
100
|
66
|
|
|
75
|
if ( $base and substr( $base, -1 ) ne '/' ) { |
19
|
3
|
|
|
|
|
6
|
$base .= '/'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$app->helper( css_load => sub { |
23
|
39
|
|
|
39
|
|
506320
|
my $c = shift; |
24
|
|
|
|
|
|
|
|
25
|
39
|
100
|
|
|
|
205
|
if ( $_[1]->{check} ) { |
26
|
7
|
50
|
|
|
|
140
|
my $asset = $c->app->static->file( |
27
|
|
|
|
|
|
|
$_[1]->{no_base} ? $_[0] : "$base$_[0]" |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
7
|
100
|
|
|
|
1077
|
return '' if !$asset; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
36
|
|
|
|
|
125
|
push @{ $c->stash->{__CSSLOADERFILES__} }, [ @_ ]; |
|
36
|
|
|
|
|
112
|
|
34
|
11
|
|
|
|
|
114
|
} ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$app->hook( after_render => sub { |
37
|
26
|
|
|
26
|
|
8459
|
my ($c, $content, $format) = @_; |
38
|
|
|
|
|
|
|
|
39
|
26
|
50
|
|
|
|
118
|
return if $format ne 'html'; |
40
|
26
|
100
|
|
|
|
80
|
return if !$c->stash->{__CSSLOADERFILES__}; |
41
|
|
|
|
|
|
|
|
42
|
36
|
|
|
|
|
74
|
my $load_css = |
43
|
|
|
|
|
|
|
join "\n", |
44
|
|
|
|
|
|
|
map{ |
45
|
36
|
50
|
|
|
|
832
|
my ($file,$config) = @{ $_ }; |
|
25
|
|
|
|
|
75
|
|
46
|
36
|
100
|
|
|
|
118
|
my $local_base = $config->{no_base} ? '' : $base; |
47
|
|
|
|
|
|
|
|
48
|
36
|
100
|
|
|
|
113
|
$local_base = $c->url_for( $local_base ) if $local_base; |
49
|
|
|
|
|
|
|
|
50
|
36
|
|
|
|
|
3350
|
my $local_media = ""; |
51
|
|
|
|
|
|
|
|
52
|
36
|
100
|
|
|
|
107
|
$local_media = ' media="' . $media . '"' if $media; |
53
|
36
|
100
|
|
|
|
89
|
$local_media = ' media="' . $config->{media} . '"' if $config->{media}; |
54
|
|
|
|
|
|
|
|
55
|
36
|
|
|
|
|
60
|
my $ie_start = ''; |
56
|
36
|
|
|
|
|
54
|
my $ie_end = ''; |
57
|
|
|
|
|
|
|
|
58
|
36
|
100
|
|
|
|
102
|
if ( exists $config->{ie} ) { |
59
|
7
|
|
|
|
|
9
|
my $start_extra = ''; |
60
|
7
|
|
|
|
|
7
|
my $end_extra = ''; |
61
|
7
|
|
|
|
|
14
|
my $cmp = ''; |
62
|
7
|
|
|
|
|
7
|
my $version = ''; |
63
|
|
|
|
|
|
|
|
64
|
7
|
100
|
100
|
|
|
46
|
if ( !ref $config->{ie} && !$config->{ie} ) { |
|
|
100
|
|
|
|
|
|
65
|
1
|
|
|
|
|
2
|
$start_extra = ''; |
66
|
1
|
|
|
|
|
1
|
$end_extra = '", $end_extra; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
36
|
100
|
|
|
|
521
|
$config->{no_file} ? |
85
|
|
|
|
|
|
|
qq~$ie_start$ie_end~ : |
86
|
|
|
|
|
|
|
qq~$ie_start$ie_end~; |
87
|
|
|
|
|
|
|
} |
88
|
25
|
|
|
|
|
235
|
@{ $c->stash->{__CSSLOADERFILES__} || [] }; |
89
|
|
|
|
|
|
|
|
90
|
25
|
50
|
|
|
|
1626
|
return if !$load_css; |
91
|
|
|
|
|
|
|
|
92
|
25
|
100
|
|
|
|
36
|
${$content} =~ s!()!$load_css$1! or ${$content} = $load_css . ${$content}; |
|
24
|
|
|
|
|
74
|
|
|
24
|
|
|
|
|
52
|
|
|
25
|
|
|
|
|
108
|
|
93
|
11
|
|
|
|
|
1181
|
}); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |