HamlHelperNode.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /* SVN FILE: $Id: HamlHelperNode.php 117 2010-09-21 09:41:58Z chris.l.yates@gmail.com $ */
  3. /**
  4. * HamlHelperNode 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. /**
  12. * HamlHelperNode class.
  13. * Represent a helper in the Haml source.
  14. * The helper is run on the output from child nodes when the node is rendered.
  15. * @package PHamlP
  16. * @subpackage Haml.tree
  17. */
  18. class HamlHelperNode extends HamlNode {
  19. const MATCH = '/(.*?)(\w+)\((.+?)\)(?:\s+(.*))?$/';
  20. const PRE = 1;
  21. const NAME = 2;
  22. const ARGS = 3;
  23. const BLOCK = 4;
  24. /**
  25. * @var string the helper class name
  26. */
  27. private $class;
  28. /**
  29. * @var string helper method name
  30. */
  31. private $pre;
  32. /**
  33. * @var string helper method name
  34. */
  35. private $name;
  36. /**
  37. * @var string helper method arguments
  38. */
  39. private $args;
  40. /**
  41. * HamlFilterNode constructor.
  42. * Sets the filter.
  43. * @param string helper class.
  44. * @param string helper call.
  45. * @return HamlHelperNode
  46. */
  47. public function __construct($class, $pre, $name, $args, $parent) {
  48. $this->class = $class;
  49. $this->pre = $pre;
  50. $this->name = $name;
  51. $this->args = $args;
  52. $this->parent = $parent;
  53. $this->root = $parent->root;
  54. $parent->children[] = $this;
  55. }
  56. /**
  57. * Render this node.
  58. * The filter is run on the content of child nodes before being returned.
  59. * @return string the rendered node
  60. */
  61. public function render() {
  62. $children = '';
  63. foreach ($this->children as $child) {
  64. $children .= trim($child->render());
  65. } // foreach
  66. $output = '<?php '.(empty($this->pre) ? 'echo' : $this->pre)." {$this->class}::{$this->name}('$children',{$this->args}); ?>";
  67. return $this->debug($output);
  68. }
  69. }