mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #158
This commit is contained in:
parent
e0fc70b751
commit
c2751e069c
|
@ -6,7 +6,8 @@ require_once __DIR__.'/../tests/tools.php';
|
||||||
\Fenom::registerAutoload();
|
\Fenom::registerAutoload();
|
||||||
|
|
||||||
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
|
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
|
||||||
$fenom->setOptions(Fenom::AUTO_RELOAD);
|
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_COMPILE);
|
||||||
var_dump($fenom->compileCode('{set $z = "A"~~"B"}')->getBody());
|
//var_dump($fenom->compileCode('{set $z = "A"~~"B"}')->getBody());
|
||||||
//$fenom->display("blocks/second.tpl", []);
|
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
|
||||||
|
var_dump($fenom->display("bug158/main.tpl", []));
|
||||||
// $fenom->getTemplate("problem.tpl");
|
// $fenom->getTemplate("problem.tpl");
|
3
sandbox/templates/bug158/main.tpl
Normal file
3
sandbox/templates/bug158/main.tpl
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{* Отображаемый шаблон *}
|
||||||
|
{import [test] from "bug158/test.tpl" as test}
|
||||||
|
{test.test}
|
7
sandbox/templates/bug158/test.tpl
Normal file
7
sandbox/templates/bug158/test.tpl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{* template:test.tpl *}
|
||||||
|
{macro test($break = false)}
|
||||||
|
Test macro recursive
|
||||||
|
{if $break?}
|
||||||
|
{macro.test break = true}
|
||||||
|
{/if}
|
||||||
|
{/macro}
|
|
@ -428,9 +428,9 @@ class Template extends Render
|
||||||
{
|
{
|
||||||
if ($this->macros) {
|
if ($this->macros) {
|
||||||
$macros = array();
|
$macros = array();
|
||||||
foreach ($this->macros as $m) {
|
foreach ($this->macros as $name => $m) {
|
||||||
if ($m["recursive"]) {
|
if ($m["recursive"]) {
|
||||||
$macros[] = "\t\t'" . $m["name"] . "' => function (\$var, \$tpl) {\n?>" . $m["body"] . "<?php\n}";
|
$macros[] = "\t\t'" . $name . "' => function (\$var, \$tpl) {\n?>" . $m["body"] . "<?php\n}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "array(\n" . implode(",\n", $macros) . ")";
|
return "array(\n" . implode(",\n", $macros) . ")";
|
||||||
|
@ -1369,6 +1369,7 @@ class Template extends Render
|
||||||
{
|
{
|
||||||
$recursive = false;
|
$recursive = false;
|
||||||
$macro = false;
|
$macro = false;
|
||||||
|
|
||||||
if (isset($this->macros[$name])) {
|
if (isset($this->macros[$name])) {
|
||||||
$macro = $this->macros[$name];
|
$macro = $this->macros[$name];
|
||||||
$recursive = $macro['recursive'];
|
$recursive = $macro['recursive'];
|
||||||
|
|
|
@ -77,34 +77,12 @@ class MacrosTest extends TestCase
|
||||||
$this->tpl(
|
$this->tpl(
|
||||||
"macro_recursive_import.tpl",
|
"macro_recursive_import.tpl",
|
||||||
'
|
'
|
||||||
{import "macro_recursive.tpl" as math}
|
{import [factorial] from "macro_recursive.tpl" as math}
|
||||||
|
|
||||||
{math.factorial num=10}'
|
{math.factorial num=10}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _testSandbox()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
// $this->fenom->compile("macro_recursive.tpl")->display([]);
|
|
||||||
// $this->fenom->flush();
|
|
||||||
// var_dump($this->fenom->fetch("macro_recursive.tpl", []));
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @group macros
|
* @group macros
|
||||||
|
@ -162,6 +140,7 @@ class MacrosTest extends TestCase
|
||||||
$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));
|
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testImportRecursive()
|
public function testImportRecursive()
|
||||||
{
|
{
|
||||||
$this->fenom->compile('macro_recursive_import.tpl');
|
$this->fenom->compile('macro_recursive_import.tpl');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user