blob: 70b907eace97cef90965a6173431e5ef3e81dbfb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
error_reporting(E_ALL);
require realpath(dirname(__FILE__)).'/../lessc.inc.php';
// sorts the selectors in stylesheet in order to normalize it for comparison
$exe = array_shift($argv); // remove filename
if (!$fname = array_shift($argv)) {
$fname = "php://stdin";
}
class lesscNormalized extends lessc {
public $numberPrecision = 3;
public function compileValue($value) {
if ($value[0] == "raw_color") {
$value = $this->coerceColor($value);
}
return parent::compileValue($value);
}
}
class SortingFormatter extends lessc_formatter_lessjs {
function sortKey($block) {
if (!isset($block->sortKey)) {
sort($block->selectors, SORT_STRING);
$block->sortKey = implode(",", $block->selectors);
}
return $block->sortKey;
}
function sortBlock($block) {
usort($block->children, function($a, $b) {
$sort = strcmp($this->sortKey($a), $this->sortKey($b));
if ($sort == 0) {
// TODO
}
return $sort;
});
}
function block($block) {
$this->sortBlock($block);
return parent::block($block);
}
}
$less = new lesscNormalized();
$less->setFormatter(new SortingFormatter);
echo $less->parse(file_get_contents($fname));
|