| 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 compressed formatter |
| 19 |
* |
| 20 |
* @author Leaf Corcoran <leafot@gmail.com> |
| 21 |
*/ |
| 22 |
class Compressed extends Formatter |
| 23 |
{ |
| 24 |
/** |
| 25 |
* {@inheritdoc} |
| 26 |
*/ |
| 27 |
public function __construct() |
| 28 |
{ |
| 29 |
$this->indentLevel = 0; |
| 30 |
$this->indentChar = ' '; |
| 31 |
$this->break = ''; |
| 32 |
$this->open = '{'; |
| 33 |
$this->close = '}'; |
| 34 |
$this->tagSeparator = ','; |
| 35 |
$this->assignSeparator = ':'; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* {@inheritdoc} |
| 40 |
*/ |
| 41 |
public function stripSemicolon(&$lines) |
| 42 |
{ |
| 43 |
if (($count = count($lines)) |
| 44 |
&& substr($lines[$count - 1], -1) === ';' |
| 45 |
) { |
| 46 |
$lines[$count - 1] = substr($lines[$count - 1], 0, -1); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* {@inheritdoc} |
| 52 |
*/ |
| 53 |
public function blockLines(OutputBlock $block) |
| 54 |
{ |
| 55 |
$inner = $this->indentStr(); |
| 56 |
|
| 57 |
$glue = $this->break . $inner; |
| 58 |
|
| 59 |
foreach ($block->lines as $index => $line) { |
| 60 |
if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') { |
| 61 |
unset($block->lines[$index]); |
| 62 |
} elseif (substr($line, 0, 3) === '/*!') { |
| 63 |
$block->lines[$index] = '/*' . substr($line, 3); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
echo $inner . implode($glue, $block->lines); |
| 68 |
|
| 69 |
if (! empty($block->children)) { |
| 70 |
echo $this->break; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* {@inherit} |
| 76 |
*/ |
| 77 |
public function format(OutputBlock $block) |
| 78 |
{ |
| 79 |
return parent::format($block); |
| 80 |
|
| 81 |
// TODO: we need to fix the 2 "compressed" tests where the "close" is applied |
| 82 |
return trim(str_replace(';}', '}', parent::format($block))); |
| 83 |
} |
| 84 |
} |
| 85 |
|