Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

   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  
  17  /**
  18   * Compressed formatter
  19   *
  20   * @author Leaf Corcoran <leafot@gmail.com>
  21   *
  22   * @internal
  23   */
  24  class Compressed extends Formatter
  25  {
  26      /**
  27       * {@inheritdoc}
  28       */
  29      public function __construct()
  30      {
  31          $this->indentLevel = 0;
  32          $this->indentChar = '  ';
  33          $this->break = '';
  34          $this->open = '{';
  35          $this->close = '}';
  36          $this->tagSeparator = ',';
  37          $this->assignSeparator = ':';
  38          $this->keepSemicolons = false;
  39      }
  40  
  41      /**
  42       * {@inheritdoc}
  43       */
  44      public function blockLines(OutputBlock $block)
  45      {
  46          $inner = $this->indentStr();
  47  
  48          $glue = $this->break . $inner;
  49  
  50          foreach ($block->lines as $index => $line) {
  51              if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
  52                  unset($block->lines[$index]);
  53              }
  54          }
  55  
  56          $this->write($inner . implode($glue, $block->lines));
  57  
  58          if (! empty($block->children)) {
  59              $this->write($this->break);
  60          }
  61      }
  62  
  63      /**
  64       * Output block selectors
  65       *
  66       * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
  67       */
  68      protected function blockSelectors(OutputBlock $block)
  69      {
  70          assert(! empty($block->selectors));
  71  
  72          $inner = $this->indentStr();
  73  
  74          $this->write(
  75              $inner
  76              . implode(
  77                  $this->tagSeparator,
  78                  str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
  79              )
  80              . $this->open . $this->break
  81          );
  82      }
  83  }