1 | <?php |
||
16 | class Module extends ExternalModule |
||
17 | { |
||
18 | /** LESS variable declaration pattern */ |
||
19 | const P_VARIABLE_DECLARATION = '/^\s*\@(?<name>[^\s:]+)\s*\:\s*(?<value>[^;]+);/m'; |
||
20 | 2 | /** LESS mixin declaration pattern */ |
|
21 | const P_MIXIN_DECLARATION = '/^\s*\.(?<name>[^\s(:]+)\s*(?<params>\([^)]+\))\s*(?<code>\{[^}]+\})/m'; |
||
22 | 2 | ||
23 | /** @var string Path to cached mixins & variables */ |
||
24 | 2 | public $cachedLESS; |
|
25 | |||
26 | 2 | /** @var \lessc LESS compiler */ |
|
27 | protected $less; |
||
28 | |||
29 | /** @var array Collection of LESS variables */ |
||
30 | protected $variables = []; |
||
31 | |||
32 | /** @var array Collection of LESS mixins */ |
||
33 | protected $mixins = []; |
||
34 | |||
35 | /** @var string Cached LESS code */ |
||
36 | protected $lessCode; |
||
37 | |||
38 | 2 | /** SamsonFramework load preparation stage handler */ |
|
39 | public function prepare() |
||
57 | |||
58 | /** |
||
59 | * Create LESS variables and mixins cache file. |
||
60 | */ |
||
61 | public function finished() |
||
74 | |||
75 | /** |
||
76 | * Parse LESS variable definition and remove them from code. |
||
77 | * |
||
78 | * @param string $content Source code for parsing LESS variables |
||
79 | * |
||
80 | * @return string Parsed code without LESS variables |
||
81 | */ |
||
82 | protected function parseVariables($content) |
||
100 | |||
101 | /** |
||
102 | * Parse LESS mixins definition and remove them from code. |
||
103 | * |
||
104 | * @param string $resource LESS resource path |
||
105 | * @param string $content Source code for parsing LESS mixins |
||
106 | * |
||
107 | * @return string Parsed code without LESS mixins |
||
108 | */ |
||
109 | protected function parseMixins($resource, $content) |
||
126 | |||
127 | /** |
||
128 | * LESS resource analyzer. |
||
129 | * |
||
130 | * @param string $resource Resource full path |
||
131 | * @param string $extension Resource extension |
||
132 | * @param string $content LESS code |
||
133 | * |
||
134 | * @return array Variables and mixins collection |
||
135 | */ |
||
136 | public function analyzer($resource, $extension, &$content) |
||
147 | |||
148 | /** |
||
149 | * LESS resource compiler. |
||
150 | * |
||
151 | * @param string $resource Resource full path |
||
152 | * @param string $extension Resource extension |
||
153 | * @param string $content Compiled output resource content |
||
154 | * |
||
155 | * @throws \Exception |
||
156 | */ |
||
157 | public function compiler($resource, &$extension, &$content) |
||
178 | } |
||
179 |