PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / assets / libraries / scssphp / src / Formatter.php

Formatter.php in MaxButtons – Create buttons 6.28, at assets/libraries/scssphp/src/Formatter.php

203 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SCSSPHP
4 *
5 * @copyright 2012-2015 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;
13
14 use Leafo\ScssPhp\Formatter\OutputBlock;
15
16 /**
17 * SCSS base formatter
18 *
19 * @author Leaf Corcoran <leafot@gmail.com>
20 */
21 abstract class Formatter
22 {
23 /**
24 * @var integer
25 */
26 public $indentLevel;
27
28 /**
29 * @var string
30 */
31 public $indentChar;
32
33 /**
34 * @var string
35 */
36 public $break;
37
38 /**
39 * @var string
40 */
41 public $open;
42
43 /**
44 * @var string
45 */
46 public $close;
47
48 /**
49 * @var string
50 */
51 public $tagSeparator;
52
53 /**
54 * @var string
55 */
56 public $assignSeparator;
57
58 /**
59 * Initialize formatter
60 *
61 * @api
62 */
63 abstract public function __construct();
64
65 /**
66 * Return indentation (whitespace)
67 *
68 * @return string
69 */
70 protected function indentStr()
71 {
72 return '';
73 }
74
75 /**
76 * Return property assignment
77 *
78 * @api
79 *
80 * @param string $name
81 * @param mixed $value
82 *
83 * @return string
84 */
85 public function property($name, $value)
86 {
87 return rtrim($name) . $this->assignSeparator . $value . ';';
88 }
89
90 /**
91 * Strip semi-colon appended by property(); it's a separator, not a terminator
92 *
93 * @api
94 *
95 * @param array $lines
96 */
97 public function stripSemicolon(&$lines)
98 {
99 }
100
101 /**
102 * Output lines inside a block
103 *
104 * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
105 */
106 protected function blockLines(OutputBlock $block)
107 {
108 $inner = $this->indentStr();
109
110 $glue = $this->break . $inner;
111
112 echo $inner . implode($glue, $block->lines);
113
114 if (! empty($block->children)) {
115 echo $this->break;
116 }
117 }
118
119 /**
120 * Output block selectors
121 *
122 * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
123 */
124 protected function blockSelectors(OutputBlock $block)
125 {
126 $inner = $this->indentStr();
127
128 echo $inner
129 . implode($this->tagSeparator, $block->selectors)
130 . $this->open . $this->break;
131 }
132
133 /**
134 * Output block children
135 *
136 * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
137 */
138 protected function blockChildren(OutputBlock $block)
139 {
140 foreach ($block->children as $child) {
141 $this->block($child);
142 }
143 }
144
145 /**
146 * Output non-empty block
147 *
148 * @param \Leafo\ScssPhp\Formatter\OutputBlock $block
149 */
150 protected function block(OutputBlock $block)
151 {
152 if (empty($block->lines) && empty($block->children)) {
153 return;
154 }
155
156 $pre = $this->indentStr();
157
158 if (! empty($block->selectors)) {
159 $this->blockSelectors($block);
160
161 $this->indentLevel++;
162 }
163
164 if (! empty($block->lines)) {
165 $this->blockLines($block);
166 }
167
168 if (! empty($block->children)) {
169 $this->blockChildren($block);
170 }
171
172 if (! empty($block->selectors)) {
173 $this->indentLevel--;
174
175 if (empty($block->children)) {
176 echo $this->break;
177 }
178
179 echo $pre . $this->close . $this->break;
180 }
181 }
182
183 /**
184 * Entry point to formatting a block
185 *
186 * @api
187 *
188 * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree
189 *
190 * @return string
191 */
192 public function format(OutputBlock $block)
193 {
194 ob_start();
195
196 $this->block($block);
197
198 $out = ob_get_clean();
199
200 return $out;
201 }
202 }
203