Add recursive macros support (#28)

This commit is contained in:
bzick
2013-07-29 14:53:21 +04:00
parent 97e891895a
commit 4edd0e1708
8 changed files with 135 additions and 49 deletions

View File

@@ -42,6 +42,25 @@ class MacrosTest extends TestCase {
a: {macro.plus x=5 y=3}.
');
$this->tpl("macro_recursive.tpl", '{macro factorial(num)}
{if $num}
{$num} {macro.factorial num=$num-1}
{/if}
{/macro}
{macro.factorial num=10}');
}
public function _testSandbox() {
try {
$this->fenom->compile("macro_recursive.tpl");
$this->fenom->flush();
var_dump($this->fenom->fetch("macro_recursive.tpl", []));
} catch(\Exception $e) {
var_dump($e->getMessage().": ".$e->getTraceAsString());
}
exit;
}
public function testMacros() {
@@ -72,4 +91,11 @@ class MacrosTest extends TestCase {
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
}
public function testRecursive() {
$this->fenom->compile('macro_recursive.tpl');
$this->fenom->flush();
$tpl = $this->fenom->getTemplate('macro_recursive.tpl');
$this->assertSame("10 9 8 7 6 5 4 3 2 1", Modifier::strip($tpl->fetch(array()), true));
}
}