HamlCodeBlockNode.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /* SVN FILE: $Id: HamlCodeBlockNode.php 92 2010-05-20 17:42:59Z chris.l.yates $ */
  3. /**
  4. * HamlCodeBlockNode class file.
  5. * @author Chris Yates <chris.l.yates@gmail.com>
  6. * @copyright Copyright (c) 2010 PBM Web Development
  7. * @license http://phamlp.googlecode.com/files/license.txt
  8. * @package PHamlP
  9. * @subpackage Haml.tree
  10. */
  11. require_once('HamlRootNode.php');
  12. require_once('HamlNodeExceptions.php');
  13. /**
  14. * HamlCodeBlockNode class.
  15. * Represents a code block - if, elseif, else, foreach, do, and while.
  16. * @package PHamlP
  17. * @subpackage Haml.tree
  18. */
  19. class HamlCodeBlockNode extends HamlNode {
  20. /**
  21. * @var HamlCodeBlockNode else nodes for if statements
  22. */
  23. public $else;
  24. /**
  25. * @var string while clause for do-while loops
  26. */
  27. public $doWhile;
  28. /**
  29. * Adds an "else" statement to this node.
  30. * @param SassIfNode "else" statement node to add
  31. * @return SassIfNode this node
  32. */
  33. public function addElse($node) {
  34. if (is_null($this->else)) {
  35. $node->root = $this->root;
  36. $node->parent = $this->parent;
  37. $this->else = $node;
  38. }
  39. else {
  40. $this->else->addElse($node);
  41. }
  42. return $this;
  43. }
  44. public function render() {
  45. $output = $this->renderer->renderStartCodeBlock($this);
  46. foreach ($this->children as $child) {
  47. $output .= $child->render();
  48. } // foreach
  49. $output .= (empty($this->else) ?
  50. $this->renderer->renderEndCodeBlock($this) : $this->else->render());
  51. return $this->debug($output);
  52. }
  53. }