/
ScssProcessor.php
50 lines (41 loc) · 1.39 KB
/
ScssProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Concrete\Core\StyleCustomizer\Processor;
use Concrete\Core\StyleCustomizer\Normalizer\NormalizedVariableCollection;
use Illuminate\Filesystem\Filesystem;
use ScssPhp\ScssPhp\Compiler;
use ScssPhp\ScssPhp\ValueConverter;
class ScssProcessor implements ProcessorInterface
{
/**
* @var Compiler
*/
protected $compiler;
/**
* @var Filesystem
*/
protected $filesystem;
/**
* ScssProcessor constructor.
* @param Compiler $compiler
*/
public function __construct(Filesystem $filesystem, Compiler $compiler)
{
$this->filesystem = $filesystem;
$this->compiler = $compiler;
}
public function compileFileToString(string $file, NormalizedVariableCollection $collection): string
{
$scss = $this->filesystem->get($file);
$this->compiler->addImportPath(dirname($file)); // so that relative imports work
$variables = [];
foreach ($collection->getValues() as $variable) {
$variables[$variable->getName()] = ValueConverter::parseValue($variable->getValue());
}
$this->compiler->replaceVariables($variables);
$this->compiler->addImportPath(
DIR_BASE_CORE . DIRECTORY_SEPARATOR . DIRNAME_BEDROCK . DIRECTORY_SEPARATOR . DIRNAME_BEDROCK_ASSETS
);
$css = $this->compiler->compileString($scss)->getCss();
return $css;
}
}