From 551497ef94f6239b109316d8fab32f0909b13f73 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:42:42 -0300 Subject: Squashed 'mod/less/' content from commit 380edad git-subtree-dir: mod/less git-subtree-split: 380edadb3a5e524a8e6ef6df063b678f2f00516f --- vendors/lessphp/tests/sort.php | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 vendors/lessphp/tests/sort.php (limited to 'vendors/lessphp/tests/sort.php') diff --git a/vendors/lessphp/tests/sort.php b/vendors/lessphp/tests/sort.php new file mode 100644 index 000000000..38662cb24 --- /dev/null +++ b/vendors/lessphp/tests/sort.php @@ -0,0 +1,57 @@ +sort_key)) { + sort($block->tags, SORT_STRING); + $block->sort_key = implode(",", $block->tags); + } + + return $block->sort_key; +} + +class sort_css extends lessc { + function __construct() { + parent::__construct(); + } + + // normalize numbers + function compileValue($value) { + $ignore = array('list', 'keyword', 'string', 'color', 'function'); + if ($value[0] == 'number' || !in_array($value[0], $ignore)) { + $value[1] = $value[1] + 0; // convert to either double or int + } + + return parent::compileValue($value); + } + + function parse_and_sort($str) { + $root = $this->parseTree($str); + + $less = $this; + usort($root->props, function($a, $b) use ($less) { + + $sort = strcmp(sort_key($a[1]), sort_key($b[1])); + if ($sort == 0) + return strcmp($less->compileBlock($a[1]), $less->compileBlock($b[1])); + return $sort; + }); + + return $this->compileBlock($root); + } +} + +$sorter = new sort_css; +echo $sorter->parse_and_sort(file_get_contents($fname)); + -- cgit v1.2.3