Per the spec, missing partials should be treated as an empty string.
This commit is contained in:
@@ -221,7 +221,11 @@ class Mustache_Compiler {
|
|||||||
return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $this->walk($nodes, $level));
|
return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $this->walk($nodes, $level));
|
||||||
}
|
}
|
||||||
|
|
||||||
const PARTIAL = '$buffer .= $this->mustache->loadPartial(%s)->renderInternal($context, %s);';
|
const PARTIAL = '
|
||||||
|
if ($partial = $this->mustache->loadPartial(%s)) {
|
||||||
|
$buffer .= $partial->renderInternal($context, %s);
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate Mustache Template partial call PHP source.
|
* Generate Mustache Template partial call PHP source.
|
||||||
|
|||||||
@@ -414,7 +414,11 @@ class Mustache_Mustache {
|
|||||||
* @return Mustache_Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadPartial($name) {
|
public function loadPartial($name) {
|
||||||
|
try {
|
||||||
return $this->loadSource($this->getPartialsLoader()->load($name));
|
return $this->loadSource($this->getPartialsLoader()->load($name));
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
// If the named partial cannot be found, return null.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -146,6 +146,17 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMissingPartialsTreatedAsEmptyString() {
|
||||||
|
$mustache = new Mustache_Mustache(array(
|
||||||
|
'partials_loader' => new Mustache_Loader_ArrayLoader(array(
|
||||||
|
'foo' => 'FOO',
|
||||||
|
'baz' => 'BAZ',
|
||||||
|
))
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals('FOOBAZ', $mustache->render('{{>foo}}{{>bar}}{{>baz}}', array()));
|
||||||
|
}
|
||||||
|
|
||||||
public function testHelpers() {
|
public function testHelpers() {
|
||||||
$foo = function() { return 'foo'; };
|
$foo = function() { return 'foo'; };
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|||||||
Reference in New Issue
Block a user