|
@@ -175,6 +175,9 @@ class Mustache {
|
|
|
public function render($template = null, $view = null, $partials = null) {
|
|
public function render($template = null, $view = null, $partials = null) {
|
|
|
if ($template === null) $template = $this->_template;
|
|
if ($template === null) $template = $this->_template;
|
|
|
if ($partials !== null) $this->_partials = $partials;
|
|
if ($partials !== null) $this->_partials = $partials;
|
|
|
|
|
+
|
|
|
|
|
+ $otag_orig = $this->_otag;
|
|
|
|
|
+ $ctag_orig = $this->_ctag;
|
|
|
|
|
|
|
|
if ($view) {
|
|
if ($view) {
|
|
|
$this->_context = array($view);
|
|
$this->_context = array($view);
|
|
@@ -183,7 +186,12 @@ class Mustache {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$template = $this->_renderPragmas($template);
|
|
$template = $this->_renderPragmas($template);
|
|
|
- return $this->_renderTemplate($template, $this->_context);
|
|
|
|
|
|
|
+ $template = $this->_renderTemplate($template, $this->_context);
|
|
|
|
|
+
|
|
|
|
|
+ $this->_otag = $otag_orig;
|
|
|
|
|
+ $this->_ctag = $ctag_orig;
|
|
|
|
|
+
|
|
|
|
|
+ return $template;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -213,14 +221,16 @@ class Mustache {
|
|
|
protected function _renderTemplate($template) {
|
|
protected function _renderTemplate($template) {
|
|
|
if ($section = $this->_findSection($template)) {
|
|
if ($section = $this->_findSection($template)) {
|
|
|
list($before, $type, $tag_name, $content, $after) = $section;
|
|
list($before, $type, $tag_name, $content, $after) = $section;
|
|
|
|
|
+
|
|
|
|
|
+ $rendered_before = $this->_renderTags($before);
|
|
|
|
|
|
|
|
- $renderedContent = '';
|
|
|
|
|
|
|
+ $rendered_content = '';
|
|
|
$val = $this->_getVariable($tag_name);
|
|
$val = $this->_getVariable($tag_name);
|
|
|
switch($type) {
|
|
switch($type) {
|
|
|
// inverted section
|
|
// inverted section
|
|
|
case '^':
|
|
case '^':
|
|
|
if (empty($val)) {
|
|
if (empty($val)) {
|
|
|
- $renderedContent = $this->_renderTemplate($content);
|
|
|
|
|
|
|
+ $rendered_content = $this->_renderTemplate($content);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -229,22 +239,22 @@ class Mustache {
|
|
|
if ($this->_varIsIterable($val)) {
|
|
if ($this->_varIsIterable($val)) {
|
|
|
foreach ($val as $local_context) {
|
|
foreach ($val as $local_context) {
|
|
|
$this->_pushContext($local_context);
|
|
$this->_pushContext($local_context);
|
|
|
- $renderedContent .= $this->_renderTemplate($content);
|
|
|
|
|
|
|
+ $rendered_content .= $this->_renderTemplate($content);
|
|
|
$this->_popContext();
|
|
$this->_popContext();
|
|
|
}
|
|
}
|
|
|
} else if ($val) {
|
|
} else if ($val) {
|
|
|
if (is_array($val) || is_object($val)) {
|
|
if (is_array($val) || is_object($val)) {
|
|
|
$this->_pushContext($val);
|
|
$this->_pushContext($val);
|
|
|
- $renderedContent = $this->_renderTemplate($content);
|
|
|
|
|
|
|
+ $rendered_content = $this->_renderTemplate($content);
|
|
|
$this->_popContext();
|
|
$this->_popContext();
|
|
|
} else {
|
|
} else {
|
|
|
- $renderedContent = $this->_renderTemplate($content);
|
|
|
|
|
|
|
+ $rendered_content = $this->_renderTemplate($content);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return $this->_renderTags($before) . $renderedContent . $this->_renderTemplate($after);
|
|
|
|
|
|
|
+ return $rendered_before . $rendered_content . $this->_renderTemplate($after);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $this->_renderTags($template);
|
|
return $this->_renderTags($template);
|
|
@@ -260,7 +270,7 @@ class Mustache {
|
|
|
*/
|
|
*/
|
|
|
protected function _prepareSectionRegEx($otag, $ctag) {
|
|
protected function _prepareSectionRegEx($otag, $ctag) {
|
|
|
return sprintf(
|
|
return sprintf(
|
|
|
- '/(?:(?<=\\n)[ \\t]*)?%s(?P<type>[%s])(?P<tag_name>.+?)%s\\n?/s',
|
|
|
|
|
|
|
+ '/(?:(?<=\\n)[ \\t]*)?%s(?:(?P<type>[%s])(?P<tag_name>.+?)|=(?P<delims>.*?)=)%s\\n?/s',
|
|
|
preg_quote($otag, '/'),
|
|
preg_quote($otag, '/'),
|
|
|
self::SECTION_TYPES,
|
|
self::SECTION_TYPES,
|
|
|
preg_quote($ctag, '/')
|
|
preg_quote($ctag, '/')
|
|
@@ -286,11 +296,24 @@ class Mustache {
|
|
|
$section_stack = array();
|
|
$section_stack = array();
|
|
|
$matches = array();
|
|
$matches = array();
|
|
|
while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) {
|
|
while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) {
|
|
|
|
|
+ if (isset($matches['delims'][0])) {
|
|
|
|
|
+ list($otag, $ctag) = explode(' ', $matches['delims'][0]);
|
|
|
|
|
+ $regEx = $this->_prepareSectionRegEx($otag, $ctag);
|
|
|
|
|
+ $search_offset = $matches[0][1] + strlen($matches[0][0]);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$match = $matches[0][0];
|
|
$match = $matches[0][0];
|
|
|
$offset = $matches[0][1];
|
|
$offset = $matches[0][1];
|
|
|
$type = $matches['type'][0];
|
|
$type = $matches['type'][0];
|
|
|
$tag_name = trim($matches['tag_name'][0]);
|
|
$tag_name = trim($matches['tag_name'][0]);
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($matches['delims'][0])) {
|
|
|
|
|
+ list($otag, $ctag) = explode(' ', $matches['delims'][0]);
|
|
|
|
|
+ $regEx = $this->_prepareSectionRegEx($otag, $ctag);
|
|
|
|
|
+ $search_offset = $offset + strlen($match);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$search_offset = $offset + strlen($match);
|
|
$search_offset = $offset + strlen($match);
|
|
|
|
|
|
|
@@ -475,9 +498,6 @@ class Mustache {
|
|
|
return $template;
|
|
return $template;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $otag_orig = $this->_otag;
|
|
|
|
|
- $ctag_orig = $this->_ctag;
|
|
|
|
|
-
|
|
|
|
|
$first = true;
|
|
$first = true;
|
|
|
$this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag, true);
|
|
$this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag, true);
|
|
|
|
|
|
|
@@ -517,9 +537,6 @@ class Mustache {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $this->_otag = $otag_orig;
|
|
|
|
|
- $this->_ctag = $ctag_orig;
|
|
|
|
|
-
|
|
|
|
|
return $html . $template;
|
|
return $html . $template;
|
|
|
}
|
|
}
|
|
|
|
|
|