1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SCSSPHP |
4
|
|
|
* |
5
|
|
|
* @copyright 2012-2018 Leaf Corcoran |
6
|
|
|
* |
7
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
8
|
|
|
* |
9
|
|
|
* @link http://leafo.github.io/scssphp |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Leafo\ScssPhp\Formatter; |
13
|
|
|
|
14
|
|
|
use Leafo\ScssPhp\Formatter; |
15
|
|
|
use Leafo\ScssPhp\Formatter\OutputBlock; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Debug formatter |
19
|
|
|
* |
20
|
|
|
* @author Anthon Pang <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Debug extends Formatter |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
$this->indentLevel = 0; |
30
|
|
|
$this->indentChar = ''; |
31
|
|
|
$this->break = "\n"; |
32
|
|
|
$this->open = ' {'; |
33
|
|
|
$this->close = ' }'; |
34
|
|
|
$this->tagSeparator = ', '; |
35
|
|
|
$this->assignSeparator = ': '; |
36
|
|
|
$this->keepSemicolons = true; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function indentStr() |
43
|
|
|
{ |
44
|
|
|
return str_repeat(' ', $this->indentLevel); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
protected function blockLines(OutputBlock $block) |
51
|
|
|
{ |
52
|
|
|
$indent = $this->indentStr(); |
53
|
|
|
|
54
|
|
|
if (empty($block->lines)) { |
55
|
|
|
$this->write("{$indent}block->lines: []\n"); |
56
|
|
|
|
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
foreach ($block->lines as $index => $line) { |
61
|
|
|
$this->write("{$indent}block->lines[{$index}]: $line\n"); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
protected function blockSelectors(OutputBlock $block) |
69
|
|
|
{ |
70
|
|
|
$indent = $this->indentStr(); |
71
|
|
|
|
72
|
|
|
if (empty($block->selectors)) { |
73
|
|
|
$this->write("{$indent}block->selectors: []\n"); |
74
|
|
|
|
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
foreach ($block->selectors as $index => $selector) { |
79
|
|
|
$this->write("{$indent}block->selectors[{$index}]: $selector\n"); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
protected function blockChildren(OutputBlock $block) |
87
|
|
|
{ |
88
|
|
|
$indent = $this->indentStr(); |
89
|
|
|
|
90
|
|
|
if (empty($block->children)) { |
91
|
|
|
$this->write("{$indent}block->children: []\n"); |
92
|
|
|
|
93
|
|
|
return; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->indentLevel++; |
97
|
|
|
|
98
|
|
|
foreach ($block->children as $i => $child) { |
99
|
|
|
$this->block($child); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->indentLevel--; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
protected function block(OutputBlock $block) |
109
|
|
|
{ |
110
|
|
|
$indent = $this->indentStr(); |
111
|
|
|
|
112
|
|
|
$this->write("{$indent}block->type: {$block->type}\n" . |
113
|
|
|
"{$indent}block->depth: {$block->depth}\n"); |
114
|
|
|
|
115
|
|
|
$this->currentBlock = $block; |
116
|
|
|
|
117
|
|
|
$this->blockSelectors($block); |
118
|
|
|
$this->blockLines($block); |
119
|
|
|
$this->blockChildren($block); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|