Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / api / scssphp / scssphp / src / Formatter / Expanded.php
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 * Expanded formatter
20 *
21 * @author Leaf Corcoran <leafot@gmail.com>
22 */
23 class Expanded extends Formatter
24 {
25 /**
26 * {@inheritdoc}
27 */
28 public function __construct()
29 {
30 $this->indentLevel = 0;
31 $this->indentChar = ' ';
32 $this->break = "\n";
33 $this->open = ' {';
34 $this->close = '}';
35 $this->tagSeparator = ', ';
36 $this->assignSeparator = ': ';
37 $this->keepSemicolons = true;
38 }
39
40 /**
41 * {@inheritdoc}
42 */
43 protected function indentStr()
44 {
45 return str_repeat($this->indentChar, $this->indentLevel);
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 protected function blockLines(OutputBlock $block)
52 {
53 $inner = $this->indentStr();
54
55 $glue = $this->break . $inner;
56
57 foreach ($block->lines as $index => $line) {
58 if (substr($line, 0, 2) === '/*') {
59 $block->lines[$index] = preg_replace('/\r\n?|\n|\f/', $this->break, $line);
60 }
61 }
62
63 $this->write($inner . implode($glue, $block->lines));
64
65 if (empty($block->selectors) || ! empty($block->children)) {
66 $this->write($this->break);
67 }
68 }
69 }