mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Done #66, dev dynamic extends
This commit is contained in:
@@ -26,4 +26,14 @@ function dump()
|
||||
fwrite(STDERR, "DUMP: " . call_user_func("print_r", $arg, true) . "\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function dumpt()
|
||||
{
|
||||
foreach (func_get_args() as $arg) {
|
||||
fwrite(STDERR, "DUMP: " . call_user_func("print_r", $arg, true) . "\n");
|
||||
|
||||
}
|
||||
$e = new Exception();
|
||||
echo "-------\nDump trace: \n" . $e->getTraceAsString() . "\n";
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace Fenom;
|
||||
use Fenom, Fenom\TestCase;
|
||||
|
||||
class ExtendsTemplateTest extends TestCase
|
||||
class ExtendsTemplateTest_ extends TestCase
|
||||
{
|
||||
|
||||
public function _testSandbox()
|
||||
|
||||
@@ -10,12 +10,8 @@ class ExtendsTest extends TestCase
|
||||
public function _testSandbox()
|
||||
{
|
||||
try {
|
||||
var_dump($this->fenom->getTemplate([
|
||||
'autoextends/child.3.tpl',
|
||||
'autoextends/child.2.tpl',
|
||||
'autoextends/child.1.tpl',
|
||||
'autoextends/parent.tpl',
|
||||
])->getBody());
|
||||
var_dump($this->fenom->getTemplate("extends/static/nested/child.1.tpl")->fetch([]));
|
||||
// var_dump($this->fenom->getTemplate("extends/dynamic/child.2.tpl")->getBody());
|
||||
// var_dump($this->fenom->compileCode('{block "main"}a {parent} b{/block}')->getBody());
|
||||
// $child = $this->fenom->getRawTemplate()->load('autoextends/child.1.tpl', false);
|
||||
// $child->extend('autoextends/parent.tpl');
|
||||
@@ -27,10 +23,10 @@ class ExtendsTest extends TestCase
|
||||
exit;
|
||||
}
|
||||
|
||||
public function testManualExtends()
|
||||
public function testAutoExtendsManual()
|
||||
{
|
||||
$child = $this->fenom->getRawTemplate()->load('autoextends/child.1.tpl', false);
|
||||
$child->extend('autoextends/parent.tpl');
|
||||
$child = $this->fenom->getRawTemplate()->load('extends/auto/child.1.tpl', false);
|
||||
$child->extend('extends/auto/parent.tpl');
|
||||
$child->compile();
|
||||
$result = "Before header
|
||||
Content of the header
|
||||
@@ -52,12 +48,53 @@ Child 3 content
|
||||
Before footer
|
||||
Footer from use";
|
||||
$this->assertSame($result, $this->fenom->fetch([
|
||||
'autoextends/child.3.tpl',
|
||||
'autoextends/child.2.tpl',
|
||||
'autoextends/child.1.tpl',
|
||||
'autoextends/parent.tpl',
|
||||
'extends/auto/child.3.tpl',
|
||||
'extends/auto/child.2.tpl',
|
||||
'extends/auto/child.1.tpl',
|
||||
'extends/auto/parent.tpl',
|
||||
], array()));
|
||||
}
|
||||
|
||||
public function testStaticExtendLevel1() {
|
||||
$result = "Before header
|
||||
Content of the header
|
||||
Before body
|
||||
Child 1 Body
|
||||
Before footer
|
||||
Content of the footer";
|
||||
$this->assertSame($result, $this->fenom->fetch('extends/static/child.1.tpl', array()));
|
||||
}
|
||||
|
||||
public function testStaticExtendLevel3() {
|
||||
$result = "Before header
|
||||
Child 2 header
|
||||
Before body
|
||||
Child 3 content
|
||||
Before footer
|
||||
Footer from use";
|
||||
$this->assertSame($result, $this->fenom->fetch('extends/static/child.3.tpl', array()));
|
||||
}
|
||||
|
||||
public function testStaticExtendNested() {
|
||||
$result = "Before body
|
||||
|
||||
Before header
|
||||
Child 1: Content of the header
|
||||
Before footer
|
||||
Content of the footer
|
||||
";
|
||||
$this->assertSame($result, $this->fenom->fetch('extends/static/nested/child.1.tpl', array()));
|
||||
}
|
||||
|
||||
public function _testDynamicExtendLevel2() {
|
||||
$result = "Before header
|
||||
Content of the header
|
||||
Before body
|
||||
Child 1 Body
|
||||
Before footer
|
||||
Content of the footer";
|
||||
$this->assertSame($result, $this->fenom->fetch('extends/dynamic/child.2.tpl', array()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -144,17 +144,17 @@ class FenomTest extends \Fenom\TestCase
|
||||
public function testFilter()
|
||||
{
|
||||
$punit = $this;
|
||||
$this->fenom->addPreFilter(function ($src, $tpl) use ($punit) {
|
||||
$this->fenom->addPreFilter(function ($tpl, $src) use ($punit) {
|
||||
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "== $src ==";
|
||||
});
|
||||
|
||||
$this->fenom->addPostFilter(function ($code, $tpl) use ($punit) {
|
||||
$this->fenom->addPostFilter(function ($tpl, $code) use ($punit) {
|
||||
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "+++ $code +++";
|
||||
});
|
||||
|
||||
$this->fenom->addFilter(function ($text, $tpl) use ($punit) {
|
||||
$this->fenom->addFilter(function ($tpl, $text) use ($punit) {
|
||||
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||
return "|--- $text ---|";
|
||||
});
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
|
||||
{use 'autoextends/use.tpl'}
|
||||
{use 'extends/auto/use.tpl'}
|
||||
{block 'header'}Child 2 header{/block}
|
||||
2
tests/resources/provider/extends/dynamic/child.1.tpl
Normal file
2
tests/resources/provider/extends/dynamic/child.1.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{extends 'extends/dynamic/parent.tpl'}
|
||||
{block 'body'}Child 1 {parent}{/block}
|
||||
4
tests/resources/provider/extends/dynamic/child.2.tpl
Normal file
4
tests/resources/provider/extends/dynamic/child.2.tpl
Normal file
@@ -0,0 +1,4 @@
|
||||
{var $no = 1}
|
||||
{extends "extends/dynamic/child.{$no}.tpl"}
|
||||
{use 'extends/dynamic/use.tpl'}
|
||||
{block 'header'}Child 2 header{/block}
|
||||
2
tests/resources/provider/extends/dynamic/child.3.tpl
Normal file
2
tests/resources/provider/extends/dynamic/child.3.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{extends 'extends/dynamic/child.2.tpl'}
|
||||
{block 'body'}Child 3 content{/block}
|
||||
2
tests/resources/provider/extends/dynamic/use.tpl
Normal file
2
tests/resources/provider/extends/dynamic/use.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{block 'footer'}Footer from use{/block}
|
||||
{block 'header'}Header from use{/block}
|
||||
2
tests/resources/provider/extends/static/child.1.tpl
Normal file
2
tests/resources/provider/extends/static/child.1.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{extends 'extends/static/parent.tpl'}
|
||||
{block 'body'}Child 1 {parent}{/block}
|
||||
3
tests/resources/provider/extends/static/child.2.tpl
Normal file
3
tests/resources/provider/extends/static/child.2.tpl
Normal file
@@ -0,0 +1,3 @@
|
||||
{extends 'extends/static/child.1.tpl'}
|
||||
{use 'extends/static/use.tpl'}
|
||||
{block 'header'}Child 2 header{/block}
|
||||
2
tests/resources/provider/extends/static/child.3.tpl
Normal file
2
tests/resources/provider/extends/static/child.3.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{extends 'extends/static/child.2.tpl'}
|
||||
{block 'body'}Child 3 content{/block}
|
||||
@@ -0,0 +1,2 @@
|
||||
{extends 'extends/static/nested/parent.tpl'}
|
||||
{block 'header'}Child 1: {parent}{/block}
|
||||
@@ -0,0 +1,7 @@
|
||||
Before body
|
||||
{block 'body'}
|
||||
Before header
|
||||
{block 'header'}Content of the header{/block}
|
||||
Before footer
|
||||
{block 'footer'}Content of the footer{/block}
|
||||
{/block}
|
||||
6
tests/resources/provider/extends/static/parent.tpl
Normal file
6
tests/resources/provider/extends/static/parent.tpl
Normal file
@@ -0,0 +1,6 @@
|
||||
Before header
|
||||
{block 'header'}Content of the header{/block}
|
||||
Before body
|
||||
{block 'body'}Body{/block}
|
||||
Before footer
|
||||
{block 'footer'}Content of the footer{/block}
|
||||
2
tests/resources/provider/extends/static/use.tpl
Normal file
2
tests/resources/provider/extends/static/use.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{block 'footer'}Footer from use{/block}
|
||||
{block 'header'}Header from use{/block}
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
{block 'body'}Child 1 content{/block}
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
{block 'header'}Child 2 header{/block}
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
{block 'body'}Child 3 content{/block}
|
||||
Reference in New Issue
Block a user