@@ -15,6 +15,19 @@ $SOURCE_MAP_PLACEHOLDER =~ s!::!_!g;
15
15
has functions => sub { +{} };
16
16
has generate_source_map => sub { shift -> app-> mode eq ' development' ? 1 : 0 };
17
17
18
+ sub before_process {
19
+ my ($self , $assets ) = @_ ;
20
+
21
+ return $assets -> each (sub {
22
+ my ($asset , $index ) = @_ ;
23
+ return if $asset -> format !~ $FORMAT_RE ;
24
+ my @paths = (_include_path_for_asset($asset ), @{$self -> store-> paths});
25
+ my $content = $asset -> content;
26
+ $asset -> checksum($self -> _checksum(\$content , $asset , [grep {$_ } @paths ]));
27
+ $asset -> content($content ) unless $asset -> path;
28
+ });
29
+ }
30
+
18
31
sub process {
19
32
my ($self , $assets ) = @_ ;
20
33
my $store = $self -> assetpack-> store;
@@ -33,29 +46,24 @@ sub process {
33
46
34
47
return $assets -> each (sub {
35
48
my ($asset , $index ) = @_ ;
36
-
37
49
return if $asset -> format !~ $FORMAT_RE ;
50
+
38
51
my ($attrs , $content ) = ($asset -> TO_JSON, $asset -> content);
39
- local $self -> {checksum_for_file } = {};
40
- local $opts {include_paths }[0] = _include_path($asset );
41
52
$attrs -> {minified } = $self -> assetpack-> minify;
42
53
$attrs -> {key } = sprintf ' sass%s' , $attrs -> {minified } ? ' -min' : ' ' ;
43
54
$attrs -> {format } = ' css' ;
44
- $attrs -> {checksum } = $self -> _checksum(\$content , $asset , $opts {include_paths });
45
55
46
56
return $asset -> content($file )-> FROM_JSON($attrs ) if $file = $store -> load($attrs );
47
57
return if $asset -> isa(' Mojolicious::Plugin::AssetPack::Asset::Null' );
48
- $opts {include_paths }[0] = $asset -> path ? $asset -> path-> dirname : undef ;
49
- $opts {include_paths } = [grep {$_ } @{$opts {include_paths }}];
50
- diag ' Process "%s" with checksum %s.' , $asset -> url, $attrs -> { checksum } if DEBUG;
58
+ local $opts {include_paths }[0] = $asset -> path ? $asset -> path-> dirname : undef ;
59
+ local $opts {include_paths } = [grep {$_ } @{$opts {include_paths }}];
60
+ diag ' Process "%s" with checksum %s.' , $asset -> url, $asset -> checksum if DEBUG;
51
61
52
62
if ($self -> {has_module } //= eval { load_module ' CSS::Sass' ; 1 }) {
53
63
$opts {output_style } = _output_style($attrs -> {minified });
54
64
$content = CSS::Sass::sass2scss($content ) if $asset -> format eq ' sass' ;
55
65
my ($css , $err , $stats ) = CSS::Sass::sass_compile($content , %opts );
56
- if ($err ) {
57
- die sprintf ' [Pipe::Sass] Could not compile "%s" with opts=%s: %s' , $asset -> url, dumper(\%opts ), $err ;
58
- }
66
+ $err and Carp::confess(qq/ [Pipe::Sass] Could not compile "@{[$asset ->url]}" with opts=@{[dumper(\% opts)]}: $err / );
59
67
$css = Mojo::Util::encode(' UTF-8' , $css );
60
68
$self -> _add_source_map_asset($asset , \$css , $stats ) if $stats -> {source_map_string };
61
69
$asset -> content($store -> save(\$css , $attrs ))-> FROM_JSON($attrs );
@@ -94,7 +102,6 @@ sub _checksum {
94
102
my $store = $self -> assetpack-> store;
95
103
my @c = (checksum $$ref );
96
104
97
- SEARCH:
98
105
while ($$ref =~ / $IMPORT_RE /gs ) {
99
106
my $pre = $1 ;
100
107
my $rel_path = $4 ;
@@ -113,12 +120,12 @@ SEARCH:
113
120
next if $rel_path =~ m ! ^https?://! and !$dynamic ;
114
121
115
122
unshift @basename , " _$name .$ext " , " $name .$ext " unless $name =~ / \. $ext $ / ;
116
- my $imported = $store -> asset([map { join ' /' , @rel , $_ } @basename ], $paths )
117
- or die qq( [Pipe::Sass] Could not find "$rel_path " file in @ $paths) ;
123
+ my $imported = $self -> store-> asset([map { join ' /' , @rel , $_ } @basename ], $paths )
124
+ or Carp::confess( qq( [Pipe::Sass] Could not find "$rel_path " file in [@{[join ', ', @ $paths]}]. ) );
118
125
119
126
if ($imported -> path) {
120
127
diag ' @import "%s" (%s)' , $rel_path , $imported -> path if DEBUG >= 2;
121
- local $paths -> [0] = _include_path ($imported );
128
+ local $paths -> [0] = _include_path_for_asset ($imported );
122
129
push @c , $self -> _checksum(\$imported -> content, $imported , $paths );
123
130
}
124
131
else {
@@ -132,7 +139,7 @@ SEARCH:
132
139
return checksum join ' :' , @c ;
133
140
}
134
141
135
- sub _include_path {
142
+ sub _include_path_for_asset {
136
143
my $asset = shift ;
137
144
return $asset -> url if $asset -> url =~ m ! ^https?://! ;
138
145
return $asset -> path-> dirname if $asset -> path;
@@ -224,6 +231,10 @@ dev tools.
224
231
225
232
=head1 METHODS
226
233
234
+ =head2 before_process
235
+
236
+ See L<Mojolicious::Plugin::AssetPack::Pipe/before_process> .
237
+
227
238
=head2 process
228
239
229
240
See L<Mojolicious::Plugin::AssetPack::Pipe/process> .
0 commit comments