HamlElementNode.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* SVN FILE: $Id: HamlElementNode.php 83 2010-05-17 16:35:54Z chris.l.yates $ */
  3. /**
  4. * HamlElementNode 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. * HamlElementNode class.
  15. * Represents an element.
  16. * @package PHamlP
  17. * @subpackage Haml.tree
  18. */
  19. class HamlElementNode extends HamlNode {
  20. public $isBlock;
  21. public $isSelfClosing;
  22. public $attributes;
  23. public $whitespaceControl;
  24. public $escapeHTML;
  25. public function render() {
  26. $renderer = $this->renderer;
  27. $this->output = $renderer->renderOpeningTag($this);
  28. $close = $renderer->renderClosingTag($this);
  29. if ($this->whitespaceControl['outer']['left']) {
  30. $this->output = ltrim($this->output);
  31. $close = rtrim($close);
  32. $this->parent->output = rtrim($this->parent->output);
  33. }
  34. foreach ($this->children as $index=>$child) {
  35. $output = $child->render();
  36. $output = ($this->whitespaceControl['inner'] ? trim($output) : $output);
  37. if ($index && $this->children[$index-1] instanceof HamlElementNode && $this->children[$index-1]->whitespaceControl['outer']['right']) {
  38. $output = ltrim($output);
  39. }
  40. $this->output .= $output;
  41. } // foreach
  42. return $this->debug($this->output . (isset($child) &&
  43. $child instanceof HamlElementNode &&
  44. $child->whitespaceControl['outer']['right'] ? ltrim($close) : $close));
  45. }
  46. }