ScssCompiler.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Grav\Plugin\Admin;
  3. use ScssPhp\ScssPhp\Compiler;
  4. class ScssCompiler
  5. {
  6. protected $compiler;
  7. public function compiler()
  8. {
  9. if ($this->compiler === null) {
  10. $this->reset();
  11. }
  12. return $this->compiler;
  13. }
  14. public function reset()
  15. {
  16. $this->compiler = new Compiler();
  17. return $this;
  18. }
  19. public function setVariables(array $variables)
  20. {
  21. $this->compiler()->setVariables($variables);
  22. return $this;
  23. }
  24. public function setImportPaths(array $paths)
  25. {
  26. $this->compiler()->setImportPaths($paths);
  27. return $this;
  28. }
  29. public function compile(string $input_file, string $output_file)
  30. {
  31. $input = file_get_contents($input_file);
  32. $output = $this->compiler()->compile($input);
  33. file_put_contents($output_file, $output);
  34. return $this;
  35. }
  36. public function compileAll(array $input_paths, string $output_file)
  37. {
  38. $input = '';
  39. foreach ($input_paths as $input_file) {
  40. $input .= trim(file_get_contents($input_file)) . "\n\n";
  41. }
  42. $output = $this->compiler()->compile($input);
  43. file_put_contents($output_file, $output);
  44. return $this;
  45. }
  46. }