Merge branch 'dev' into feature/pragma-dot-notation
Conflicts: README.markdown
This commit is contained in:
+17
-2
@@ -142,12 +142,16 @@ class Mustache {
|
|||||||
|
|
||||||
// regular section
|
// regular section
|
||||||
case '#':
|
case '#':
|
||||||
if (is_array($val)) {
|
if ($this->varIsIterable($val)) {
|
||||||
foreach ($val as $local_context) {
|
foreach ($val as $local_context) {
|
||||||
$replace .= $this->_render($content, $this->getContext($context, $local_context));
|
$replace .= $this->_render($content, $this->getContext($context, $local_context));
|
||||||
}
|
}
|
||||||
} else if ($val) {
|
} else if ($val) {
|
||||||
$replace .= $content;
|
if (is_array($val) || is_object($val)) {
|
||||||
|
$replace .= $this->_render($content, $this->getContext($context, $val));
|
||||||
|
} else {
|
||||||
|
$replace .= $content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -411,6 +415,17 @@ class Mustache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given $var should be iterated (i.e. in a section context).
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @param mixed $var
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function varIsIterable($var) {
|
||||||
|
return is_object($var) || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var))));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a string to be used in a regular expression.
|
* Prepare a string to be used in a regular expression.
|
||||||
*
|
*
|
||||||
|
|||||||
+4
-2
@@ -81,8 +81,10 @@ And render it:
|
|||||||
Known Issues
|
Known Issues
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* There's no way to toggle a pragma other than checking out the feature branch for each pragma... Need a clean way to do this.
|
* There's no way to toggle a pragma other than checking out the feature branch for each pragma...
|
||||||
* Sections don't respect delimiter changes -- `delimiters` example currently fails with an "unclosed section" exception.
|
Need a clean way to do this.
|
||||||
|
* Sections don't respect delimiter changes -- `delimiters` example currently fails with an
|
||||||
|
"unclosed section" exception.
|
||||||
* Test coverage is incomplete.
|
* Test coverage is incomplete.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ChildContext extends Mustache {
|
||||||
|
public $parent = array(
|
||||||
|
'child' => 'child works',
|
||||||
|
);
|
||||||
|
|
||||||
|
public $grandparent = array(
|
||||||
|
'parent' => array(
|
||||||
|
'child' => 'grandchild works',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<h1>{{#parent}}{{child}}{{/parent}}</h1>
|
||||||
|
<h2>{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}</h2>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<h1>child works</h1>
|
||||||
|
<h2>grandchild works</h2>
|
||||||
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
class Complex extends Mustache {
|
class Complex extends Mustache {
|
||||||
public $header = 'Colors';
|
public $header = 'Colors';
|
||||||
|
|
||||||
public $item = array(
|
public $item = array(
|
||||||
array('name' => 'red', 'current' => true, 'url' => '#Red'),
|
array('name' => 'red', 'current' => true, 'url' => '#Red'),
|
||||||
array('name' => 'green', 'current' => false, 'url' => '#Green'),
|
array('name' => 'green', 'current' => false, 'url' => '#Green'),
|
||||||
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
||||||
);
|
);
|
||||||
|
|
||||||
public function notEmpty() {
|
public function notEmpty() {
|
||||||
return !($this->isEmpty());
|
return !($this->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEmpty() {
|
public function isEmpty() {
|
||||||
return count($this->item) === 0;
|
return count($this->item) === 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
class Delimiters extends Mustache {
|
class Delimiters extends Mustache {
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle() {
|
||||||
return array(
|
return array(
|
||||||
array('item' => "And it worked the second time."),
|
array('item' => "And it worked the second time."),
|
||||||
array('item' => "As well as the third."),
|
array('item' => "As well as the third."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@ class DoubleSection extends Mustache {
|
|||||||
public function t() {
|
public function t() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $two = "second";
|
public $two = "second";
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
class Sections extends Mustache {
|
class Sections extends Mustache {
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle() {
|
||||||
return array(
|
return array(
|
||||||
array('item' => "And it worked the second time."),
|
array('item' => "And it worked the second time."),
|
||||||
array('item' => "As well as the third."),
|
array('item' => "As well as the third."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user