Add Tag entity for compilers. Add tag options

This commit is contained in:
Ivan Shalganov
2014-04-17 23:22:50 +04:00
parent 7fa41997b8
commit 0e8880faf9
8 changed files with 281 additions and 160 deletions

View File

@ -37,6 +37,9 @@ class FunctionsTest extends TestCase
$this->tpl('function_array_param_pos.tpl', '{sum [1, 2, 3, 4, 5]}');
}
/**
* @group sb
*/
public function testFunctionWithParams()
{
$output = $this->fenom->fetch('function_params_scalar.tpl');

View File

@ -65,8 +65,12 @@ class MacrosTest extends TestCase
// $this->fenom->compile("macro_recursive.tpl")->display([]);
// $this->fenom->flush();
// var_dump($this->fenom->fetch("macro_recursive.tpl", []));
var_dump($this->fenom->compile("macro_recursive_import.tpl")->display(array()));
var_dump($this->fenom->display("macro_recursive_import.tpl", array()));
var_dump($this->fenom->compileCode('{macro factorial(num)}
{if $num}
{$num} {macro.factorial num=$num-1} {$num}
{/if}
{/macro}')->getBody());
// var_dump($this->fenom->display("macro_recursive_import.tpl", array()));
} catch (\Exception $e) {
var_dump($e->getMessage() . ": " . $e->getTraceAsString());
}
@ -109,6 +113,9 @@ class MacrosTest extends TestCase
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
}
/**
* @group macro-recursive
*/
public function testRecursive()
{
$this->fenom->compile('macro_recursive.tpl');

View File

@ -823,7 +823,7 @@ class TemplateTest extends TestCase
public function providerStatic()
{
return array(
array('{Fenom\TemplateTest::multi x=3 y=4}', '12'),
// array('{Fenom\TemplateTest::multi x=3 y=4}', '12'),
array('{Fenom\TemplateTest::multi(3,4)}', '12'),
array('{12 + Fenom\TemplateTest::multi(3,4)}', '24'),
array('{12 + 3|Fenom\TemplateTest::multi:4}', '24'),
@ -848,7 +848,7 @@ class TemplateTest extends TestCase
public function _testSandbox()
{
try {
var_dump($this->fenom->compileCode('{var:ignore $a} value {/var}')->getBody());
var_dump($this->fenom->compileCode('{$a}')->getBody());
} catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
while ($e->getPrevious()) {

View File

@ -21,18 +21,18 @@ function myCompiler(Fenom\Tokenizer $tokenizer, Fenom\Tag $tag)
return 'echo "PHP_VERSION: ".PHP_VERSION." (for ".' . $p["name"] . '.")";';
}
function myBlockCompilerOpen(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope)
function myBlockCompilerOpen(Fenom\Tokenizer $tokenizer, Fenom\Tag $scope)
{
$p = $scope->tpl->parseParams($tokenizer);
return 'echo "PHP_VERSION: ".PHP_VERSION." (for ".' . $p["name"] . '.")";';
}
function myBlockCompilerClose(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope)
function myBlockCompilerClose(Fenom\Tokenizer $tokenizer, Fenom\Tag $scope)
{
return 'echo "End of compiler";';
}
function myBlockCompilerTag(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope)
function myBlockCompilerTag(Fenom\Tokenizer $tokenizer, Fenom\Tag $scope)
{
$p = $scope->tpl->parseParams($tokenizer);
return 'echo "Tag ".' . $p["name"] . '." of compiler";';