Compressed.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SCSSPHP
  4. *
  5. * @copyright 2012-2015 Leaf Corcoran
  6. *
  7. * @license http://opensource.org/licenses/MIT MIT
  8. *
  9. * @link http://leafo.github.io/scssphp
  10. */
  11. namespace Leafo\ScssPhp\Formatter;
  12. use Leafo\ScssPhp\Formatter;
  13. use Leafo\ScssPhp\Formatter\OutputBlock;
  14. /**
  15. * Compressed formatter
  16. *
  17. * @author Leaf Corcoran <leafot@gmail.com>
  18. */
  19. class Compressed extends Formatter
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function __construct()
  25. {
  26. $this->indentLevel = 0;
  27. $this->indentChar = ' ';
  28. $this->break = '';
  29. $this->open = '{';
  30. $this->close = '}';
  31. $this->tagSeparator = ',';
  32. $this->assignSeparator = ':';
  33. $this->keepSemicolons = false;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function blockLines(OutputBlock $block)
  39. {
  40. $inner = $this->indentStr();
  41. $glue = $this->break . $inner;
  42. foreach ($block->lines as $index => $line) {
  43. if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
  44. unset($block->lines[$index]);
  45. } elseif (substr($line, 0, 3) === '/*!') {
  46. $block->lines[$index] = '/*' . substr($line, 3);
  47. }
  48. }
  49. echo $inner . implode($glue, $block->lines);
  50. if (!empty($block->children)) {
  51. echo $this->break;
  52. }
  53. }
  54. }