| 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\Formatter; |
| 13 |
|
| 14 |
use Leafo\ScssPhp\Formatter; |
| 15 |
use Leafo\ScssPhp\Formatter\OutputBlock; |
| 16 |
|
| 17 |
/** |
| 18 |
* SCSS debug formatter |
| 19 |
* |
| 20 |
* @author Anthon Pang <anthon.pang@gmail.com> |
| 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 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* {@inheritdoc} |
| 40 |
*/ |
| 41 |
protected function indentStr() |
| 42 |
{ |
| 43 |
return str_repeat(' ', $this->indentLevel); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* {@inheritdoc} |
| 48 |
*/ |
| 49 |
protected function blockLines(OutputBlock $block) |
| 50 |
{ |
| 51 |
$indent = $this->indentStr(); |
| 52 |
|
| 53 |
if (empty($block->lines)) { |
| 54 |
echo "{$indent}block->lines: []\n"; |
| 55 |
|
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
foreach ($block->lines as $index => $line) { |
| 60 |
echo "{$indent}block->lines[{$index}]: $line\n"; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* {@inheritdoc} |
| 66 |
*/ |
| 67 |
protected function blockSelectors(OutputBlock $block) |
| 68 |
{ |
| 69 |
$indent = $this->indentStr(); |
| 70 |
|
| 71 |
if (empty($block->selectors)) { |
| 72 |
echo "{$indent}block->selectors: []\n"; |
| 73 |
|
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
foreach ($block->selectors as $index => $selector) { |
| 78 |
echo "{$indent}block->selectors[{$index}]: $selector\n"; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* {@inheritdoc} |
| 84 |
*/ |
| 85 |
protected function blockChildren(OutputBlock $block) |
| 86 |
{ |
| 87 |
$indent = $this->indentStr(); |
| 88 |
|
| 89 |
if (empty($block->children)) { |
| 90 |
echo "{$indent}block->children: []\n"; |
| 91 |
|
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
$this->indentLevel++; |
| 96 |
|
| 97 |
foreach ($block->children as $i => $child) { |
| 98 |
$this->block($child); |
| 99 |
} |
| 100 |
|
| 101 |
$this->indentLevel--; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* {@inheritdoc} |
| 106 |
*/ |
| 107 |
protected function block(OutputBlock $block) |
| 108 |
{ |
| 109 |
$indent = $this->indentStr(); |
| 110 |
|
| 111 |
echo "{$indent}block->type: {$block->type}\n" . |
| 112 |
"{$indent}block->depth: {$block->depth}\n"; |
| 113 |
|
| 114 |
$this->blockSelectors($block); |
| 115 |
$this->blockLines($block); |
| 116 |
$this->blockChildren($block); |
| 117 |
} |
| 118 |
} |
| 119 |
|