mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 04:28:44 +02:00
N°2226: Upgrade ScssPHP to v1.0.0
This commit is contained in:
@@ -2,16 +2,18 @@
|
||||
/**
|
||||
* SCSSPHP
|
||||
*
|
||||
* @copyright 2012-2015 Leaf Corcoran
|
||||
* @copyright 2012-2019 Leaf Corcoran
|
||||
*
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*
|
||||
* @link http://leafo.github.io/scssphp
|
||||
* @link http://scssphp.github.io/scssphp
|
||||
*/
|
||||
namespace Leafo\ScssPhp\Formatter;
|
||||
|
||||
use Leafo\ScssPhp\Formatter;
|
||||
use Leafo\ScssPhp\Formatter\OutputBlock;
|
||||
namespace ScssPhp\ScssPhp\Formatter;
|
||||
|
||||
use ScssPhp\ScssPhp\Formatter;
|
||||
use ScssPhp\ScssPhp\Formatter\OutputBlock;
|
||||
|
||||
/**
|
||||
* Nested formatter
|
||||
*
|
||||
@@ -23,6 +25,7 @@ class Nested extends Formatter
|
||||
* @var integer
|
||||
*/
|
||||
private $depth;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -30,47 +33,58 @@ class Nested extends Formatter
|
||||
{
|
||||
$this->indentLevel = 0;
|
||||
$this->indentChar = ' ';
|
||||
$this->break = '
|
||||
';
|
||||
$this->break = "\n";
|
||||
$this->open = ' {';
|
||||
$this->close = ' }';
|
||||
$this->tagSeparator = ', ';
|
||||
$this->assignSeparator = ': ';
|
||||
$this->keepSemicolons = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function indentStr()
|
||||
{
|
||||
$n = $this->depth - 1;
|
||||
|
||||
return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockLines(OutputBlock $block)
|
||||
{
|
||||
$inner = $this->indentStr();
|
||||
|
||||
$glue = $this->break . $inner;
|
||||
|
||||
foreach ($block->lines as $index => $line) {
|
||||
if (substr($line, 0, 2) === '/*') {
|
||||
$block->lines[$index] = preg_replace('/(\\r|\\n)+/', $glue, $line);
|
||||
$block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line);
|
||||
}
|
||||
}
|
||||
echo $inner . implode($glue, $block->lines);
|
||||
if (!empty($block->children)) {
|
||||
echo $this->break;
|
||||
|
||||
$this->write($inner . implode($glue, $block->lines));
|
||||
|
||||
if (! empty($block->children)) {
|
||||
$this->write($this->break);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockSelectors(OutputBlock $block)
|
||||
{
|
||||
$inner = $this->indentStr();
|
||||
echo $inner . implode($this->tagSeparator, $block->selectors) . $this->open . $this->break;
|
||||
|
||||
$this->write($inner
|
||||
. implode($this->tagSeparator, $block->selectors)
|
||||
. $this->open . $this->break);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -78,17 +92,21 @@ class Nested extends Formatter
|
||||
{
|
||||
foreach ($block->children as $i => $child) {
|
||||
$this->block($child);
|
||||
|
||||
if ($i < count($block->children) - 1) {
|
||||
echo $this->break;
|
||||
$this->write($this->break);
|
||||
|
||||
if (isset($block->children[$i + 1])) {
|
||||
$next = $block->children[$i + 1];
|
||||
|
||||
if ($next->depth === max($block->depth, 1) && $child->depth >= $next->depth) {
|
||||
echo $this->break;
|
||||
$this->write($this->break);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -97,52 +115,72 @@ class Nested extends Formatter
|
||||
if ($block->type === 'root') {
|
||||
$this->adjustAllChildren($block);
|
||||
}
|
||||
|
||||
if (empty($block->lines) && empty($block->children)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->currentBlock = $block;
|
||||
|
||||
|
||||
$this->depth = $block->depth;
|
||||
if (!empty($block->selectors)) {
|
||||
|
||||
if (! empty($block->selectors)) {
|
||||
$this->blockSelectors($block);
|
||||
|
||||
$this->indentLevel++;
|
||||
}
|
||||
if (!empty($block->lines)) {
|
||||
|
||||
if (! empty($block->lines)) {
|
||||
$this->blockLines($block);
|
||||
}
|
||||
if (!empty($block->children)) {
|
||||
|
||||
if (! empty($block->children)) {
|
||||
$this->blockChildren($block);
|
||||
}
|
||||
if (!empty($block->selectors)) {
|
||||
|
||||
if (! empty($block->selectors)) {
|
||||
$this->indentLevel--;
|
||||
echo $this->close;
|
||||
|
||||
$this->write($this->close);
|
||||
}
|
||||
|
||||
if ($block->type === 'root') {
|
||||
echo $this->break;
|
||||
$this->write($this->break);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the depths of all children, depth first
|
||||
*
|
||||
* @param \Leafo\ScssPhp\Formatter\OutputBlock $block
|
||||
* @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
|
||||
*/
|
||||
private function adjustAllChildren(OutputBlock $block)
|
||||
{
|
||||
// flatten empty nested blocks
|
||||
$children = array();
|
||||
$children = [];
|
||||
|
||||
foreach ($block->children as $i => $child) {
|
||||
if (empty($child->lines) && empty($child->children)) {
|
||||
if (isset($block->children[$i + 1])) {
|
||||
$block->children[$i + 1]->depth = $child->depth;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
$count = count($children);
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$depth = $children[$i]->depth;
|
||||
$j = $i + 1;
|
||||
|
||||
if (isset($children[$j]) && $depth < $children[$j]->depth) {
|
||||
$childDepth = $children[$j]->depth;
|
||||
|
||||
for (; $j < $count; $j++) {
|
||||
if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) {
|
||||
$children[$j]->depth = $depth + 1;
|
||||
@@ -150,10 +188,13 @@ class Nested extends Formatter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$block->children = $children;
|
||||
|
||||
// make relative to parent
|
||||
foreach ($block->children as $child) {
|
||||
$this->adjustAllChildren($child);
|
||||
|
||||
$child->depth = $child->depth - $block->depth;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user