Add passthrough optimization for lambda sections.

Higher order sections which return mustache-free strings don’t need to be re-parsed, compiled and rendered. Just use the string, silly!

Fixes #141
This commit is contained in:
Justin Hileman
2013-12-14 10:45:17 -08:00
parent e739e216a6
commit 6b7f33c78d
2 changed files with 37 additions and 3 deletions
@@ -71,6 +71,35 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
$dracula->name = 'Dracula';
$this->assertEquals('Count Dracula', $tpl->render($dracula));
}
public function testPassthroughOptimization()
{
$mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
$mustache->expects($this->never())
->method('loadLambda');
$tpl = $mustache->loadTemplate('{{#wrap}}NAME{{/wrap}}');
$foo = new Mustache_Test_Functional_Foo;
$foo->wrap = array($foo, 'wrapWithEm');
$this->assertEquals('<em>NAME</em>', $tpl->render($foo));
}
public function testWithoutPassthroughOptimization()
{
$mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
$mustache->expects($this->once())
->method('loadLambda')
->will($this->returnValue($mustache->loadTemplate('<em>{{ name }}</em>')));
$tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
$foo = new Mustache_Test_Functional_Foo;
$foo->wrap = array($foo, 'wrapWithEm');
$this->assertEquals('<em>' . $foo->name . '</em>', $tpl->render($foo));
}
}
class Mustache_Test_Functional_Foo