1: <?php
2:
3: namespace WebLoader\Filter;
4:
5: /**
6: * Stylus filter
7: *
8: * @author Patrik Votoček
9: * @license MIT
10: */
11: class StylusFilter
12: {
13:
14: /** @var string */
15: private $bin;
16:
17: /** @var bool */
18: public $compress = FALSE;
19:
20: /** @var bool */
21: public $includeCss = FALSE;
22:
23: /**
24: * @param string
25: */
26: public function __construct($bin = 'stylus')
27: {
28: $this->bin = $bin;
29: }
30:
31: /**
32: * Invoke filter
33: *
34: * @param string
35: * @param \WebLoader\Compiler
36: * @param string
37: * @return string
38: */
39: public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
40: {
41: if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
42: $path =
43: $cmd = $this->bin . ($this->compress ? ' -c' : '') . ($this->includeCss ? ' --include-css' : '') . ' -I ' . pathinfo($file, PATHINFO_DIRNAME);
44: try {
45: $code = Process::run($cmd, $code);
46: } catch (\RuntimeException $e) {
47: throw new \WebLoader\WebLoaderException('Stylus Filter Error', 0, $e);
48: }
49: }
50:
51: return $code;
52: }
53:
54: }
55: