Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   1  <?php
   2  /**
   3   * SCSSPHP
   4   *
   5   * @copyright 2012-2019 Leaf Corcoran
   6   *
   7   * @license http://opensource.org/licenses/MIT MIT
   8   *
   9   * @link http://scssphp.github.io/scssphp
  10   */
  11  
  12  namespace ScssPhp\ScssPhp\Formatter;
  13  
  14  use ScssPhp\ScssPhp\Formatter;
  15  use ScssPhp\ScssPhp\Formatter\OutputBlock;
  16  
  17  /**
  18   * Crunched formatter
  19   *
  20   * @author Anthon Pang <anthon.pang@gmail.com>
  21   */
  22  class Crunched 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) === '/*') {
  50                  unset($block->lines[$index]);
  51              }
  52          }
  53  
  54          $this->write($inner . implode($glue, $block->lines));
  55  
  56          if (! empty($block->children)) {
  57              $this->write($this->break);
  58          }
  59      }
  60  
  61      /**
  62       * Output block selectors
  63       *
  64       * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
  65       */
  66      protected function blockSelectors(OutputBlock $block)
  67      {
  68          $inner = $this->indentStr();
  69  
  70          $this->write(
  71              $inner
  72              . implode(
  73                  $this->tagSeparator,
  74                  str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
  75              )
  76              . $this->open . $this->break
  77          );
  78      }
  79  }