Higher order functions, see: http://bit.ly/9s0dO4

This commit is contained in:
Justin Hileman
2010-06-23 03:16:04 -04:00
parent b096cb108d
commit 60d593dcab
2 changed files with 134 additions and 11 deletions
+17 -11
View File
@@ -188,19 +188,25 @@ class Mustache {
// regular section
case '#':
if ($this->_varIsIterable($val)) {
foreach ($val as $local_context) {
$this->_pushContext($local_context);
if ($val) {
// higher order sections
if (is_callable($val)) {
$content = call_user_func($val, $content);
$replace .= $this->_renderTemplate($content);
$this->_popContext();
}
} else if ($val) {
if (is_array($val) || is_object($val)) {
$this->_pushContext($val);
$replace .= $this->_renderTemplate($content);
$this->_popContext();
} else if ($this->_varIsIterable($val)) {
foreach ($val as $local_context) {
$this->_pushContext($local_context);
$replace .= $this->_renderTemplate($content);
$this->_popContext();
}
} else {
$replace .= $content;
if (is_array($val) || is_object($val)) {
$this->_pushContext($val);
$replace .= $this->_renderTemplate($content);
$this->_popContext();
} else {
$replace .= $content;
}
}
}
break;