From 0f81a2be50c8ace0a5941f59fbdf58515ea8134c Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Thu, 3 Dec 2015 15:00:14 +0300 Subject: [PATCH 1/2] Detached Rulesets support http://lesscss.org/features/#detached-rulesets-feature --- lessc.inc.php | 16 ++++++++++++++++ tests/inputs/ruleset.less | 11 +++++++++++ tests/outputs/ruleset.css | 6 ++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/inputs/ruleset.less create mode 100644 tests/outputs/ruleset.css diff --git a/lessc.inc.php b/lessc.inc.php index 2292f219..7f461973 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -690,6 +690,7 @@ protected function compileProp($prop, $block, $out) { list(, $child) = $prop; $this->compileBlock($child); break; + case 'ruleset': case 'mixin': list(, $path, $args, $suffix) = $prop; @@ -720,6 +721,11 @@ protected function compileProp($prop, $block, $out) { $this->throwError("{$prop[1][0]} is undefined"); } + if(strpos($prop[1][0], "$") === 0) { + //Use Ruleset Logic - Only last element + $mixins = [array_pop($mixins)]; + } + foreach ($mixins as $mixin) { if ($mixin === $block && !$orderedArgs) { continue; @@ -2458,6 +2464,16 @@ protected function parseChunk() { $this->append(array("directive", $dirName, $dirValue)); return true; } + } elseif ($this->literal(":", true)) { + //Ruleset Definition + if (($this->openString("{", $dirValue, null, array(";")) || true) && + $this->literal("{")) + { + $dir = $this->pushBlock($this->fixTags(array("@".$dirName))); + $dir->name = $dirName; + if (isset($dirValue)) $dir->value = $dirValue; + return true; + } } } diff --git a/tests/inputs/ruleset.less b/tests/inputs/ruleset.less new file mode 100644 index 00000000..68e9038b --- /dev/null +++ b/tests/inputs/ruleset.less @@ -0,0 +1,11 @@ +@detached-ruleset: { background: red; border: none; }; +@detached-ruleset: { background: blue; }; + +body { + .top { + @detached-ruleset(); + } +} +.top { + @detached-ruleset(); +} \ No newline at end of file diff --git a/tests/outputs/ruleset.css b/tests/outputs/ruleset.css new file mode 100644 index 00000000..ed453096 --- /dev/null +++ b/tests/outputs/ruleset.css @@ -0,0 +1,6 @@ +body .top { + background: blue; +} +.top { + background: blue; +} From 3c8a7383141a280acf88747cfea75f2dbaf9a32c Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Thu, 3 Dec 2015 15:09:32 +0300 Subject: [PATCH 2/2] Fix PHP5.3 incompatibility --- lessc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lessc.inc.php b/lessc.inc.php index 7f461973..07d55472 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -723,7 +723,7 @@ protected function compileProp($prop, $block, $out) { if(strpos($prop[1][0], "$") === 0) { //Use Ruleset Logic - Only last element - $mixins = [array_pop($mixins)]; + $mixins = array(array_pop($mixins)); } foreach ($mixins as $mixin) {