Done #66, dev dynamic extends

This commit is contained in:
Ivan Shalganov
2014-02-22 20:34:53 +04:00
parent 3adafb6fcc
commit a523d4a4aa
29 changed files with 174 additions and 92 deletions

View File

@@ -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";
}

View File

@@ -2,7 +2,7 @@
namespace Fenom;
use Fenom, Fenom\TestCase;
class ExtendsTemplateTest extends TestCase
class ExtendsTemplateTest_ extends TestCase
{
public function _testSandbox()

View File

@@ -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()));
}
}

View File

@@ -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 ---|";
});

View File

@@ -1,3 +1,3 @@
{use 'autoextends/use.tpl'}
{use 'extends/auto/use.tpl'}
{block 'header'}Child 2 header{/block}

View File

@@ -0,0 +1,2 @@
{extends 'extends/dynamic/parent.tpl'}
{block 'body'}Child 1 {parent}{/block}

View 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}

View File

@@ -0,0 +1,2 @@
{extends 'extends/dynamic/child.2.tpl'}
{block 'body'}Child 3 content{/block}

View File

@@ -0,0 +1,2 @@
{block 'footer'}Footer from use{/block}
{block 'header'}Header from use{/block}

View File

@@ -0,0 +1,2 @@
{extends 'extends/static/parent.tpl'}
{block 'body'}Child 1 {parent}{/block}

View File

@@ -0,0 +1,3 @@
{extends 'extends/static/child.1.tpl'}
{use 'extends/static/use.tpl'}
{block 'header'}Child 2 header{/block}

View File

@@ -0,0 +1,2 @@
{extends 'extends/static/child.2.tpl'}
{block 'body'}Child 3 content{/block}

View File

@@ -0,0 +1,2 @@
{extends 'extends/static/nested/parent.tpl'}
{block 'header'}Child 1: {parent}{/block}

View File

@@ -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}

View 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}

View File

@@ -0,0 +1,2 @@
{block 'footer'}Footer from use{/block}
{block 'header'}Header from use{/block}

View File

@@ -1,2 +0,0 @@
{block 'body'}Child 1 content{/block}

View File

@@ -1,2 +0,0 @@
{block 'header'}Child 2 header{/block}

View File

@@ -1,2 +0,0 @@
{block 'body'}Child 3 content{/block}