2016-07-20 16:45:59 +08:00
|
|
|
<?php
|
2020-12-09 13:16:13 +08:00
|
|
|
|
2016-07-20 16:45:59 +08:00
|
|
|
/**
|
|
|
|
* SCSSPHP
|
|
|
|
*
|
2020-12-09 13:16:13 +08:00
|
|
|
* @copyright 2012-2020 Leaf Corcoran
|
2016-07-20 16:45:59 +08:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/MIT MIT
|
|
|
|
*
|
2019-06-28 09:42:24 +08:00
|
|
|
* @link http://scssphp.github.io/scssphp
|
2016-07-20 16:45:59 +08:00
|
|
|
*/
|
|
|
|
|
2019-06-28 09:42:24 +08:00
|
|
|
namespace ScssPhp\ScssPhp\Formatter;
|
2016-07-20 16:45:59 +08:00
|
|
|
|
2019-06-28 09:42:24 +08:00
|
|
|
use ScssPhp\ScssPhp\Formatter;
|
2016-07-20 16:45:59 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Crunched formatter
|
|
|
|
*
|
|
|
|
* @author Anthon Pang <anthon.pang@gmail.com>
|
2020-12-09 13:16:13 +08:00
|
|
|
*
|
|
|
|
* @deprecated since 1.4.0. Use the Compressed formatter instead.
|
2021-12-30 12:10:34 +00:00
|
|
|
*
|
|
|
|
* @internal
|
2016-07-20 16:45:59 +08:00
|
|
|
*/
|
|
|
|
class Crunched extends Formatter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2020-12-09 13:16:13 +08:00
|
|
|
@trigger_error('The Crunched formatter is deprecated since 1.4.0. Use the Compressed formatter instead.', E_USER_DEPRECATED);
|
|
|
|
|
2016-07-20 16:45:59 +08:00
|
|
|
$this->indentLevel = 0;
|
|
|
|
$this->indentChar = ' ';
|
|
|
|
$this->break = '';
|
|
|
|
$this->open = '{';
|
|
|
|
$this->close = '}';
|
|
|
|
$this->tagSeparator = ',';
|
|
|
|
$this->assignSeparator = ':';
|
|
|
|
$this->keepSemicolons = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function blockLines(OutputBlock $block)
|
|
|
|
{
|
|
|
|
$inner = $this->indentStr();
|
|
|
|
|
|
|
|
$glue = $this->break . $inner;
|
|
|
|
|
|
|
|
foreach ($block->lines as $index => $line) {
|
|
|
|
if (substr($line, 0, 2) === '/*') {
|
|
|
|
unset($block->lines[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 10:36:40 +01:00
|
|
|
$this->write($inner . implode($glue, $block->lines));
|
2016-07-20 16:45:59 +08:00
|
|
|
|
|
|
|
if (! empty($block->children)) {
|
2018-03-16 10:36:40 +01:00
|
|
|
$this->write($this->break);
|
2016-07-20 16:45:59 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-11 11:53:29 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output block selectors
|
|
|
|
*
|
2019-06-28 09:42:24 +08:00
|
|
|
* @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
|
2019-06-11 11:53:29 +08:00
|
|
|
*/
|
|
|
|
protected function blockSelectors(OutputBlock $block)
|
|
|
|
{
|
2021-12-30 12:10:34 +00:00
|
|
|
assert(! empty($block->selectors));
|
|
|
|
|
2019-06-11 11:53:29 +08:00
|
|
|
$inner = $this->indentStr();
|
|
|
|
|
|
|
|
$this->write(
|
|
|
|
$inner
|
|
|
|
. implode(
|
|
|
|
$this->tagSeparator,
|
|
|
|
str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
|
|
|
|
)
|
|
|
|
. $this->open . $this->break
|
|
|
|
);
|
|
|
|
}
|
2016-07-20 16:45:59 +08:00
|
|
|
}
|