scss_formatter

SCSS base formatter.

Defined (1)

The class is defined in the following location(s).

/modules/custom-css/custom-css/preprocessors/scss.inc.php  
  1. class scss_formatter { 
  2. public $indentChar = " "; 
  3.  
  4. public $break = "\n"; 
  5. public $open = " {"; 
  6. public $close = "}"; 
  7. public $tagSeparator = ", "; 
  8. public $assignSeparator = ": "; 
  9.  
  10. public function __construct() { 
  11. $this->indentLevel = 0; 
  12.  
  13. public function indentStr($n = 0) { 
  14. return str_repeat($this->indentChar, max($this->indentLevel + $n, 0)); 
  15.  
  16. public function property($name, $value) { 
  17. return $name . $this->assignSeparator . $value . ";"; 
  18.  
  19. protected function block($block) { 
  20. if (empty($block->lines) && empty($block->children)) return; 
  21.  
  22. $inner = $pre = $this->indentStr(); 
  23.  
  24. if (!empty($block->selectors)) { 
  25. echo $pre . 
  26. implode($this->tagSeparator, $block->selectors) . 
  27. $this->open . $this->break; 
  28. $this->indentLevel++; 
  29. $inner = $this->indentStr(); 
  30.  
  31. if (!empty($block->lines)) { 
  32. $glue = $this->break.$inner; 
  33. echo $inner . implode($glue, $block->lines); 
  34. if (!empty($block->children)) { 
  35. echo $this->break; 
  36.  
  37. foreach ($block->children as $child) { 
  38. $this->block($child); 
  39.  
  40. if (!empty($block->selectors)) { 
  41. $this->indentLevel--; 
  42. if (empty($block->children)) echo $this->break; 
  43. echo $pre . $this->close . $this->break; 
  44.  
  45. public function format($block) { 
  46. ob_start(); 
  47. $this->block($block); 
  48. $out = ob_get_clean(); 
  49.  
  50. return $out;