mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add filters for templates (#30)
This commit is contained in:
@@ -47,7 +47,7 @@ class MacrosTest extends TestCase
|
||||
|
||||
$this->tpl("macro_recursive.tpl", '{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1}
|
||||
{$num} {macro.factorial num=$num-1} {$num}
|
||||
{/if}
|
||||
{/macro}
|
||||
|
||||
@@ -104,6 +104,6 @@ class MacrosTest extends TestCase
|
||||
$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));
|
||||
$this->assertSame("10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10", Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,4 +114,24 @@ class FenomTest extends \Fenom\TestCase
|
||||
// printf("remove %010b from option %010b, flags %010b\n", $option, $this->fenom->getOptions(), $flags & ~$option);
|
||||
// $this->assertSame($this->fenom->getOptions(), $flags & ~$option);
|
||||
}
|
||||
|
||||
public function testFilter() {
|
||||
$punit = $this;
|
||||
$this->fenom->addPreFilter(function ($src, $tpl) use ($punit) {
|
||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "== $src ==";
|
||||
});
|
||||
|
||||
$this->fenom->addPostFilter(function ($code, $tpl) use ($punit) {
|
||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "+++ $code +++";
|
||||
});
|
||||
|
||||
$this->fenom->addFilter(function ($text, $tpl) use ($punit) {
|
||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "|--- $text ---|";
|
||||
});
|
||||
|
||||
$this->assertSame('+++ |--- == hello ---||--- world == ---| +++', $this->fenom->compileCode('hello {var $user} god {/var} world')->fetch(array()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user