|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* SCSSPHP |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright 2012-2020 Leaf Corcoran |
|
7
|
|
|
* |
|
8
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://scssphp.github.io/scssphp |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace ScssPhp\ScssPhp\Formatter; |
|
14
|
|
|
|
|
15
|
|
|
use ScssPhp\ScssPhp\Formatter; |
|
16
|
|
|
use ScssPhp\ScssPhp\Formatter\OutputBlock; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Compressed formatter |
|
20
|
|
|
* |
|
21
|
|
|
* @author Leaf Corcoran <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Compressed extends Formatter |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->indentLevel = 0; |
|
31
|
|
|
$this->indentChar = ' '; |
|
32
|
|
|
$this->break = ''; |
|
33
|
|
|
$this->open = '{'; |
|
34
|
|
|
$this->close = '}'; |
|
35
|
|
|
$this->tagSeparator = ','; |
|
36
|
|
|
$this->assignSeparator = ':'; |
|
37
|
|
|
$this->keepSemicolons = false; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function blockLines(OutputBlock $block) |
|
44
|
|
|
{ |
|
45
|
|
|
$inner = $this->indentStr(); |
|
46
|
|
|
|
|
47
|
|
|
$glue = $this->break . $inner; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($block->lines as $index => $line) { |
|
50
|
|
|
if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') { |
|
51
|
|
|
unset($block->lines[$index]); |
|
52
|
|
|
} elseif (substr($line, 0, 3) === '/*!') { |
|
53
|
|
|
$block->lines[$index] = '/*' . substr($line, 3); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->write($inner . implode($glue, $block->lines)); |
|
58
|
|
|
|
|
59
|
|
|
if (! empty($block->children)) { |
|
60
|
|
|
$this->write($this->break); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Output block selectors |
|
66
|
|
|
* |
|
67
|
|
|
* @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function blockSelectors(OutputBlock $block) |
|
70
|
|
|
{ |
|
71
|
|
|
$inner = $this->indentStr(); |
|
72
|
|
|
|
|
73
|
|
|
$this->write( |
|
74
|
|
|
$inner |
|
75
|
|
|
. implode( |
|
76
|
|
|
$this->tagSeparator, |
|
77
|
|
|
str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors) |
|
78
|
|
|
) |
|
79
|
|
|
. $this->open . $this->break |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|