HamlNestedRenderer.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* SVN FILE: $Id: HamlNestedRenderer.php 72 2010-04-20 00:41:36Z chris.l.yates $ */
  3. /**
  4. * HamlNestedRenderer 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.renderers
  10. */
  11. /**
  12. * HamlNestedRenderer class.
  13. * Blocks and content are indented according to their nesting level.
  14. * @package PHamlP
  15. * @subpackage Haml.renderers
  16. */
  17. class HamlNestedRenderer extends HamlRenderer {
  18. /**
  19. * Renders the opening tag of an element
  20. */
  21. public function renderOpeningTag($node) {
  22. return ($node->whitespaceControl['outer'] ? '' : $this->getIndent($node)) .
  23. parent::renderOpeningTag($node) . ($node->whitespaceControl['inner'] ? '' :
  24. ($node->isSelfClosing && $node->whitespaceControl['outer'] ? '' : "\n"));
  25. }
  26. /**
  27. * Renders the closing tag of an element
  28. */
  29. public function renderClosingTag($node) {
  30. return ($node->isSelfClosing ? '' : ($node->whitespaceControl['inner'] ? '' :
  31. $this->getIndent($node)) . parent::renderClosingTag($node) .
  32. ($node->whitespaceControl['outer'] ? '' : "\n"));
  33. }
  34. /**
  35. * Renders content.
  36. * @param HamlNode the node being rendered
  37. * @return string the rendered content
  38. */
  39. public function renderContent($node) {
  40. return $this->getIndent($node) . parent::renderContent($node) . "\n";
  41. }
  42. /**
  43. * Renders the opening of a comment
  44. */
  45. public function renderOpenComment($node) {
  46. return parent::renderOpenComment($node) . (empty($node->content) ? "\n" : '');
  47. }
  48. /**
  49. * Renders the closing of a comment
  50. */
  51. public function renderCloseComment($node) {
  52. return parent::renderCloseComment($node) . "\n";
  53. }
  54. /**
  55. * Renders the start of a code block
  56. */
  57. public function renderStartCodeBlock($node) {
  58. return $this->getIndent($node) . parent::renderStartCodeBlock($node) . "\n";
  59. }
  60. /**
  61. * Renders the end of a code block
  62. */
  63. public function renderEndCodeBlock($node) {
  64. return $this->getIndent($node) . parent::renderEndCodeBlock($node) . "\n";
  65. }
  66. private function getIndent($node) {
  67. return str_repeat(' ', 2 * $node->line['indentLevel']);
  68. }
  69. }