mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
优代部分代码;block标签内可以使用{__block__}来引用所继承模板中相应block标签的内容;
模板包含文件记录及更新时间直接写入缓存的模板中;改进标签别名的处理方式,别名不再定义方法;
去除include标签传参自动生成变量的代码;cx类增加function方法,用来生成匿名函数,结合{~$函数名()}可用于递归的实现。
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
{extend name="extend2" /}
|
||||
{block name="mainbody"}
|
||||
mainbody
|
||||
{/block}
|
||||
{block name="head"}header{/block}
|
||||
@@ -1,5 +1,6 @@
|
||||
{layout name="layout2" replace="[__REPLACE__]" /}
|
||||
<div>
|
||||
{block name="head"}{/block}
|
||||
<div id="wrap">
|
||||
{include file="include" name="info" value="$info.value" /}
|
||||
{block name="main"}
|
||||
{block name="side"}
|
||||
|
||||
@@ -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]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,16 @@ EOF;
|
||||
$template->parse($content);
|
||||
$this->assertEquals($data, $content);
|
||||
|
||||
$content = <<<EOF
|
||||
<#\$info.a?='test'#>
|
||||
EOF;
|
||||
$data = <<<EOF
|
||||
<?php if((is_array(\$info)?\$info['a']:\$info->a)) echo 'test'; ?>
|
||||
EOF;
|
||||
|
||||
$template->parse($content);
|
||||
$this->assertEquals($data, $content);
|
||||
|
||||
$content = <<<EOF
|
||||
<#\$info.a==\$info.b?='test'#>
|
||||
EOF;
|
||||
@@ -332,17 +342,29 @@ EOF;
|
||||
|
||||
$content = <<<EOF
|
||||
{extend name="\$files.extend" /}
|
||||
{block name="main"}
|
||||
main
|
||||
{block name="side"}
|
||||
{__BLOCK__}
|
||||
{include file="\$files.include" name="\$user.name" value="\$user.account" /}
|
||||
{\$message}{literal}{\$message}{/literal}
|
||||
{/block}
|
||||
{block name="mainbody"}
|
||||
mainbody
|
||||
{/block}
|
||||
{/block}
|
||||
EOF;
|
||||
$content2 = <<<EOF
|
||||
<nav>
|
||||
<div>
|
||||
header
|
||||
<div id="wrap">
|
||||
<input name="info" value="value">
|
||||
value:
|
||||
|
||||
main
|
||||
|
||||
|
||||
side
|
||||
|
||||
<input name="name" value="100">
|
||||
value:
|
||||
@@ -360,6 +382,8 @@ value:
|
||||
EOF;
|
||||
$template->fetch($content);
|
||||
$this->expectOutputString($content2);
|
||||
// $template->parse($content);
|
||||
// var_dump($content);
|
||||
}
|
||||
|
||||
public function testVarAssign()
|
||||
|
||||
Reference in New Issue
Block a user