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 | private $compiler; |
||
31 | |||
32 | /** |
||
33 | * Set the destination folder where to copy the compiled css file. |
||
34 | * If the value is null, then it will be generated into the sourcePath of the asset bundle. |
||
35 | * |
||
36 | * ``` |
||
37 | * 'assetManager' => [ |
||
38 | * 'converter' => [ |
||
39 | * 'class' => \lucidtaz\yii2scssphp\ScssAssetConverter::class, |
||
40 | * 'distFolder' => 'css', |
||
41 | * ], |
||
42 | * ], |
||
43 | * ``` |
||
44 | * |
||
45 | * @var string|null |
||
46 | */ |
||
47 | public $distFolder; |
||
48 | |||
49 | /** |
||
50 | * @throws \yii\base\InvalidConfigException |
||
51 | */ |
||
52 | 11 | public function init() |
|
60 | |||
61 | /** |
||
62 | * Converts a given SCSS asset file into a CSS file. |
||
63 | * @param string $asset the asset file path, relative to $basePath |
||
64 | * @param string $basePath the directory the $asset is relative to. |
||
65 | * @return string the converted asset file path, relative to $basePath. |
||
66 | * @throws \yii\base\Exception |
||
67 | */ |
||
68 | 10 | public function convert($asset, $basePath) |
|
91 | |||
92 | 10 | private function getExtension(string $filename): string |
|
96 | |||
97 | 8 | private function replaceExtension(string $filename, string $newExtension): string |
|
102 | |||
103 | 7 | private function convertAndSaveIfNeeded(string $inFile, string $outFile) |
|
110 | |||
111 | 7 | private function shouldConvert(string $inFile, string $outFile): bool |
|
126 | |||
127 | 3 | private function isOlder(string $fileA, string $fileB): bool |
|
131 | |||
132 | /** |
||
133 | * @param string $outFile |
||
134 | * @throws \yii\base\Exception |
||
135 | */ |
||
136 | 7 | private function createDistFolderIfNotExists($outFile) |
|
143 | } |
||
144 |