Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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  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          $this->keepSemicolons = false;
  37      }
  38  
  39      /**
  40       * {@inheritdoc}
  41       */
  42      public function blockLines(OutputBlock $block)
  43      {
  44          $inner = $this->indentStr();
  45  
  46          $glue = $this->break . $inner;
  47  
  48          foreach ($block->lines as $index => $line) {
  49              if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
  50                  unset($block->lines[$index]);
  51              } elseif (substr($line, 0, 3) === '/*!') {
  52                  $block->lines[$index] = '/*' . substr($line, 3);
  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          $inner = $this->indentStr();
  71  
  72          $this->write(
  73              $inner
  74              . implode(
  75                  $this->tagSeparator,
  76                  str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
  77              )
  78              . $this->open . $this->break
  79          );
  80      }
  81  }