engine.less_js.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Class \LessEngineLess_js
  4. */
  5. class LessEngineLess_js extends LessEngine {
  6. /**
  7. * @var \Lessjs
  8. */
  9. private $less_js_parser;
  10. /**
  11. * Instantiates new instances of \Lessjs.
  12. *
  13. * @param string $input_file_path
  14. *
  15. * @see \Lessjs
  16. */
  17. public function __construct($input_file_path) {
  18. parent::__construct($input_file_path);
  19. $this->less_js_parser = Lessjs::create($this->input_file_path);
  20. }
  21. /**
  22. * We override here because getting dependencies from less.js requires another
  23. * full parse. This way we only do that if dependencies are requested.
  24. *
  25. * @return string[]
  26. *
  27. * @see \Lessjs::depends()
  28. */
  29. public function getDependencies() {
  30. $this->dependencies = $this->less_js_parser->depends();
  31. return parent::getDependencies();
  32. }
  33. /**
  34. * {@inheritdoc}
  35. * This compiles using engine specific function calls.
  36. */
  37. public function compile() {
  38. $compiled_styles = NULL;
  39. try {
  40. $this->less_js_parser->source_maps($this->source_maps_enabled, $this->source_maps_base_path, $this->source_maps_root_path);
  41. foreach ($this->import_directories as $directory) {
  42. $this->less_js_parser->include_path($directory);
  43. }
  44. foreach ($this->variables as $var_name => $var_value) {
  45. $this->less_js_parser->modify_var(trim($var_name, '@'), trim($var_value, ';'));
  46. }
  47. $compiled_styles = $this->less_js_parser->compile();
  48. }
  49. catch (Exception $e) {
  50. throw $e;
  51. }
  52. return $compiled_styles;
  53. }
  54. }