File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
$ config = Config::get ('less ' );
6
6
7
- $ compile = function ($ input_file , $ output_file )
7
+ $ imports = function ($ file ) use (&$ imports )
8
+ {
9
+ $ paths = array ();
10
+
11
+ preg_match_all ('/@import\s+"(?P<imports>[^";]+)"/ism ' , File::get ($ file ), $ matches );
12
+ foreach ($ matches ['imports ' ] as $ import )
13
+ {
14
+ $ path = dirname ($ file ) . '/ ' . $ import ;
15
+ if (File::exists ($ path ) || File::exists ($ path .= '.less ' ))
16
+ {
17
+ $ paths [] = $ path ;
18
+ $ paths = array_merge ($ paths , $ imports ($ path ));
19
+ }
20
+ }
21
+
22
+ return $ paths ;
23
+ };
24
+
25
+ $ compile = function ($ input_file , $ output_file ) use ($ imports )
8
26
{
9
27
try
10
28
{
11
- lessc::ccompile ($ input_file , $ output_file );
29
+ $ latest = File::modified ($ input_file );
30
+ foreach ($ imports ($ input_file ) as $ import )
31
+ {
32
+ $ import_modified = File::modified ($ import );
33
+ $ latest = $ import_modified > $ latest ? $ import_modified : $ latest ;
34
+ }
35
+
36
+ if (! File::exists ($ output_file ) || $ latest > File::modified ($ output_file ))
37
+ {
38
+ $ cache = lessc::cexecute ($ input_file );
39
+ File::put ($ output_file , $ cache ['compiled ' ]);
40
+ }
12
41
}
13
42
catch (Exception $ ex )
14
43
{
42
71
$ less = new lessc ();
43
72
foreach ($ config ['snippets ' ] as $ snippet => $ css )
44
73
{
45
- file_put_contents ($ css , $ less ->parse ($ snippet ));
74
+ File:: put ($ css , $ less ->parse ($ snippet ));
46
75
}
47
76
}
You can’t perform that action at this time.
0 commit comments