1 | <?php |
||
14 | class ScssAssetConverter extends Component implements AssetConverterInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var Storage |
||
18 | */ |
||
19 | public $storage; |
||
20 | |||
21 | /** |
||
22 | * @var boolean whether the source asset file should be converted even if |
||
23 | * its result already exists. You may want to set this to be `true` during |
||
24 | * the development stage to make sure the converted assets are always up-to- |
||
25 | * date. Do not set this to true on production servers as it will |
||
26 | * significantly degrade the performance. |
||
27 | */ |
||
28 | public $forceConvert = false; |
||
29 | |||
30 | /** |
||
31 | * @var Compiler |
||
32 | */ |
||
33 | private $compiler; |
||
34 | |||
35 | /** |
||
36 | * Set the destination folder where to copy the compiled css file. |
||
37 | * If the value is null, then it will be generated into the sourcePath of the asset bundle. |
||
38 | * |
||
39 | * ``` |
||
40 | * 'assetManager' => [ |
||
41 | * 'converter' => [ |
||
42 | * 'class' => \lucidtaz\yii2scssphp\ScssAssetConverter::class, |
||
43 | * 'distFolder' => 'css', |
||
44 | * ], |
||
45 | * ], |
||
46 | * ``` |
||
47 | * |
||
48 | * @var string|null |
||
49 | */ |
||
50 | public $distFolder; |
||
51 | |||
52 | /** |
||
53 | * @throws \yii\base\InvalidConfigException |
||
54 | */ |
||
55 | 11 | public function init() |
|
63 | |||
64 | /** |
||
65 | * Converts a given SCSS asset file into a CSS file. |
||
66 | * @param string $asset the asset file path, relative to $basePath |
||
67 | * @param string $basePath the directory the $asset is relative to. |
||
68 | * @return string the converted asset file path, relative to $basePath. |
||
69 | * @throws \yii\base\Exception |
||
70 | */ |
||
71 | 10 | public function convert($asset, $basePath) |
|
94 | |||
95 | 10 | private function getExtension(string $filename): string |
|
99 | |||
100 | 8 | private function replaceExtension(string $filename, string $newExtension): string |
|
105 | |||
106 | 7 | private function convertAndSaveIfNeeded(string $inFile, string $outFile) |
|
113 | |||
114 | 7 | private function shouldConvert(string $inFile, string $outFile): bool |
|
129 | |||
130 | 3 | private function isOlder(string $fileA, string $fileB): bool |
|
134 | |||
135 | /** |
||
136 | * @param $outFile |
||
137 | * @throws \yii\base\Exception |
||
138 | */ |
||
139 | 7 | private function createDistFolderIfNotExists($outFile) |
|
146 | } |
||
147 |