|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
This project is Licenced under The MIT License (MIT) |
|
4
|
|
|
|
|
5
|
|
|
Copyright (c) 2014 Christopher Seufert |
|
6
|
|
|
|
|
7
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
in the Software without restriction, including without limitation the rights |
|
10
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
furnished to do so, subject to the following conditions: |
|
13
|
|
|
|
|
14
|
|
|
The above copyright notice and this permission notice shall be included in |
|
15
|
|
|
all copies or substantial portions of the Software. |
|
16
|
|
|
|
|
17
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23
|
|
|
THE SOFTWARE. |
|
24
|
|
|
|
|
25
|
|
|
*/ |
|
26
|
|
|
namespace Seufert\Hamle\Filter; |
|
27
|
|
|
|
|
28
|
|
|
use SassFile; |
|
29
|
|
|
use SassParser; |
|
30
|
|
|
use SassRenderer; |
|
31
|
|
|
use stdConf; |
|
32
|
|
|
|
|
33
|
|
|
class Sass extends Css { |
|
34
|
|
|
static function filterText($s) { |
|
35
|
|
|
$as = explode("\n", $s); |
|
36
|
|
|
$indent = -1; |
|
37
|
|
|
foreach ($as as $line) |
|
38
|
|
|
if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
39
|
|
|
$lnInd = strlen($m[1]); |
|
40
|
|
|
if ($indent < 0) $indent = $lnInd; |
|
41
|
|
|
$indent = min($indent, $lnInd); |
|
42
|
|
|
} |
|
43
|
|
|
foreach ($as as $k => $v) |
|
44
|
|
|
$as[$k] = substr($v, $indent); |
|
45
|
|
|
$s = implode("\n", $as); |
|
46
|
|
|
|
|
47
|
|
|
require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
|
48
|
|
|
$sp = new SassParser(array("cache" => FALSE, |
|
49
|
|
|
"style" => stdConf::get("me.developer") ? SassRenderer::STYLE_EXPANDED : SassRenderer::STYLE_COMPRESSED, |
|
50
|
|
|
"syntax" => SassFile::SASS, 'debug' => TRUE)); |
|
51
|
|
|
$tree = $sp->toTree($s); |
|
52
|
|
|
$out = $tree->render(); |
|
53
|
|
|
$pad = str_pad("", $indent, " "); |
|
54
|
|
|
return $pad . str_replace("\n", "\n$pad", trim($out)); |
|
55
|
|
|
} |
|
56
|
|
|
} |