Fix for stripping leading/trailing whitespace from partial names,
per http://github.com/janl/mustache.js/issues/issue/34/#comment_244396
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@ class Mustache {
|
|||||||
protected function _renderSection($template, &$context) {
|
protected function _renderSection($template, &$context) {
|
||||||
$otag = $this->_prepareRegEx($this->_otag);
|
$otag = $this->_prepareRegEx($this->_otag);
|
||||||
$ctag = $this->_prepareRegEx($this->_ctag);
|
$ctag = $this->_prepareRegEx($this->_ctag);
|
||||||
$regex = '/' . $otag . '(\\^|\\#)(.+?)' . $ctag . '\\s*([\\s\\S]+?)' . $otag . '\\/\\2' . $ctag . '\\s*/m';
|
$regex = '/' . $otag . '(\\^|\\#)\\s*(.+?)\\s*' . $ctag . '\\s*([\\s\\S]+?)' . $otag . '\\/\\s*\\2\\s*' . $ctag . '\\s*/m';
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
while (preg_match($regex, $template, $matches, PREG_OFFSET_CAPTURE)) {
|
while (preg_match($regex, $template, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whitespace test for tag names.
|
||||||
|
*
|
||||||
|
* Per http://github.com/janl/mustache.js/issues/issue/34/#comment_244396
|
||||||
|
* tags should strip leading and trailing whitespace in key names.
|
||||||
|
*
|
||||||
|
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
|
||||||
|
*
|
||||||
|
* @extends Mustache
|
||||||
|
*/
|
||||||
|
class Whitespace extends Mustache {
|
||||||
|
public $foo = 'alpha';
|
||||||
|
|
||||||
|
public $bar = 'beta';
|
||||||
|
|
||||||
|
public function baz() {
|
||||||
|
return 'gamma';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function qux() {
|
||||||
|
return array(
|
||||||
|
array('key with space' => 'A'),
|
||||||
|
array('key with space' => 'B'),
|
||||||
|
array('key with space' => 'C'),
|
||||||
|
array('key with space' => 'D'),
|
||||||
|
array('key with space' => 'E'),
|
||||||
|
array('key with space' => 'F'),
|
||||||
|
array('key with space' => 'G'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $_partials = array(
|
||||||
|
'alphabet' => " * {{.}}\n",
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{{^ inverted section test }}
|
||||||
|
These are some things:
|
||||||
|
{{/inverted section test }}
|
||||||
|
* {{ foo }}
|
||||||
|
* {{ bar}}
|
||||||
|
* {{ baz }}
|
||||||
|
{{# qux }}
|
||||||
|
* {{ key with space }}
|
||||||
|
{{/ qux }}
|
||||||
|
{{#qux}}.{{/qux}}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
These are some things:
|
||||||
|
* alpha
|
||||||
|
* beta
|
||||||
|
* gamma
|
||||||
|
* A
|
||||||
|
* B
|
||||||
|
* C
|
||||||
|
* D
|
||||||
|
* E
|
||||||
|
* F
|
||||||
|
* G
|
||||||
|
.......
|
||||||
Reference in New Issue
Block a user