优代部分代码;block标签内可以使用{__block__}来引用所继承模板中相应block标签的内容;

模板包含文件记录及更新时间直接写入缓存的模板中;改进标签别名的处理方式,别名不再定义方法;
去除include标签传参自动生成变量的代码;cx类增加function方法,用来生成匿名函数,结合{~$函数名()}可用于递归的实现。
This commit is contained in:
oldrind
2016-03-11 21:58:18 +08:00
parent 542a3333d6
commit 71dbdcb874
9 changed files with 390 additions and 413 deletions

View File

@@ -469,7 +469,7 @@ EOF;
{import file="base,common" type="php" /}
EOF;
$data = <<<EOF
<?php import("base"); ?><?php import("common"); ?>
<?php \\think\\Loader::import("base"); ?><?php \\think\\Loader::import("common"); ?>
EOF;
$cx->parseTag($content);
$this->assertEquals($content, $data);
@@ -563,4 +563,31 @@ EOF;
$this->expectOutputString('123456789');
}
public function testFunction()
{
$template = new template();
$data = [
'list' => ['language' => 'php', 'version' => ['5.4', '5.5']],
'a' => '[',
'b' => ']',
];
$content = <<<EOF
{function name="func" vars="\$data" call="\$list" use="&\$a,&\$b"}
{foreach \$data as \$key=>\$val}
{if is_array(\$val)}
{~\$func(\$val)}
{else}
{if !is_numeric(\$key)}
{\$key.':'.\$val.','}
{else}
{\$a.\$val.\$b}
{/if}
{/if}
{/foreach}
{/function}
EOF;
$template->fetch($content, $data);
$this->expectOutputString("language:php,[5.4][5.5]");
}
}