scss_formatter_nested

SCSS nested formatter.

Defined (1)

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

/library/admin/redux-framework/inc/scssphp/scss.inc.php  
  1. class scss_formatter_nested extends scss_formatter { 
  2. public $close = " }"; 
  3.  
  4. // adjust the depths of all children, depth first 
  5. public function adjustAllChildren($block) { 
  6. // flatten empty nested blocks 
  7. $children = array(); 
  8. foreach ($block->children as $i => $child) { 
  9. if (empty($child->lines) && empty($child->children)) { 
  10. if (isset($block->children[$i + 1])) { 
  11. $block->children[$i + 1]->depth = $child->depth; 
  12. continue; 
  13. $children[] = $child; 
  14.  
  15. $count = count($children); 
  16. for ($i = 0; $i < $count; $i++) { 
  17. $depth = $children[$i]->depth; 
  18. $j = $i + 1; 
  19. if (isset($children[$j]) && $depth < $children[$j]->depth) { 
  20. $childDepth = $children[$j]->depth; 
  21. for (; $j < $count; $j++) { 
  22. if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) { 
  23. $children[$j]->depth = $depth + 1; 
  24.  
  25. $block->children = $children; 
  26.  
  27. // make relative to parent 
  28. foreach ($block->children as $child) { 
  29. $this->adjustAllChildren($child); 
  30. $child->depth = $child->depth - $block->depth; 
  31.  
  32. protected function block($block) { 
  33. if ($block->type == "root") { 
  34. $this->adjustAllChildren($block); 
  35.  
  36. $inner = $pre = $this->indentStr($block->depth - 1); 
  37. if (!empty($block->selectors)) { 
  38. echo $pre . 
  39. implode($this->tagSeparator, $block->selectors) . 
  40. $this->open . $this->break; 
  41. $this->indentLevel++; 
  42. $inner = $this->indentStr($block->depth - 1); 
  43.  
  44. if (!empty($block->lines)) { 
  45. $glue = $this->break.$inner; 
  46. echo $inner . implode($glue, $block->lines); 
  47. if (!empty($block->children)) echo $this->break; 
  48.  
  49. foreach ($block->children as $i => $child) { 
  50. // echo "*** block: ".$block->depth." child: ".$child->depth."\n"; 
  51. $this->block($child); 
  52. if ($i < count($block->children) - 1) { 
  53. echo $this->break; 
  54.  
  55. if (isset($block->children[$i + 1])) { 
  56. $next = $block->children[$i + 1]; 
  57. if ($next->depth == max($block->depth, 1) && $child->depth >= $next->depth) { 
  58. echo $this->break; 
  59.  
  60. if (!empty($block->selectors)) { 
  61. $this->indentLevel--; 
  62. echo $this->close; 
  63.  
  64. if ($block->type == "root") { 
  65. echo $this->break;