Commit ef0858b2 by Seldaek

Fixes sub-templates issues when running through the same template/loading…

Fixes sub-templates issues when running through the same template/loading subtemplates multiple times git-svn-id: svn://dwoo.org/dwoo/trunk@270 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 4ecb676b
......@@ -837,7 +837,6 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
}
$output .= $compiled."\n?>";
foreach ($this->templatePlugins as $function => $attr) {
if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) {
$this->resolveSubTemplateDependencies($function);
......@@ -845,10 +844,12 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
foreach ($this->templatePlugins as $function) {
if (isset($function['called']) && $function['called'] === true) {
$output .= $function['body'];
$output .= $function['body'].PHP_EOL;
}
}
$output .= $compiled."\n?>";
$output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output);
$output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);
......@@ -1416,7 +1417,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
if ($pointer !== null) {
$pointer += strlen($match[1]);
}
if ($operator !== '++' && $operator !== '--') {
$parts = array();
$ptr = 0;
......@@ -1429,7 +1430,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} catch (Dwoo_Exception $e) {
throw new Dwoo_Compilation_Exception($this, 'Assignments require the "if" plugin to be accessible');
}
$parts = $this->mapParams($parts, array('Dwoo_Plugin_if', 'init'), 1);
$parts = $this->getCompiledParams($parts);
......@@ -2977,7 +2978,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$paramlist[$v[0]] = array(var_export($v[2], true), $v[2]);
}
}
if (count($ps)) {
foreach ($ps as $i=>$p) {
array_push($paramlist, $p);
......
......@@ -65,9 +65,12 @@ class Dwoo_Plugin_template extends Dwoo_Block_Plugin implements Dwoo_ICompilable
$init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n";
}
$init .= '/* -- template start output */';
$body = Dwoo_Compiler::PHP_OPEN.'function Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'].'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE.
$funcName = 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'];
$body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE.
$prepend.str_replace(array('$this->','$this,'), array('$dwoo->', '$dwoo,'), $content).$append.
Dwoo_Compiler::PHP_OPEN.$cleanup."\n}".Dwoo_Compiler::PHP_CLOSE;
Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}";
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
}
}
......@@ -494,9 +494,9 @@ bleh();
public function testSubTemplates()
{
$tpl = new Dwoo_Template_String('{load_templates "file:'.TEST_DIRECTORY.'/resources/templates.html"}{menu $menu}{load_templates ""}');
$tpl = new Dwoo_Template_String('{load_templates "file:'.TEST_DIRECTORY.'/resources/templates.html"}{menu $menu}{noparam}{load_templates ""}');
$tpl->forceCompilation();
$this->assertEquals('<ul class="level0"><li>foo</li><li>bar</li><ul class="level1"><li>baz</li><li>qux</li></ul><li>boo</li><ul class="level1"><li>far</li><ul class="level2"><li>faz</li><li>mux</li></ul></ul><li>duck</li></ul>',
$this->assertEquals('<ul class="level0"><li>foo</li><li>bar</li><ul class="level1"><li>baz</li><li>qux</li></ul><li>boo</li><ul class="level1"><li>far</li><ul class="level2"><li>faz</li><li>mux</li></ul></ul><li>duck</li></ul>noparamoutput'."\n",
$this->dwoo->get($tpl, array('menu'=>array('foo', 'bar'=>array('baz','qux'), 'boo'=>array('far'=>array('faz','mux')), 'duck')), $this->compiler));
// fixes the init call not being called (which is normal)
......@@ -504,6 +504,14 @@ bleh();
$fixCall->init('');
}
public function testSubTemplatesMultiInc()
{
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/templateUsage.html');
$tpl->forceCompilation();
$this->assertEquals("\n".'noparamoutput'."\n", $this->dwoo->get($tpl, array(), $this->compiler));
$this->assertEquals("\n".'noparamoutput'."\n", $this->dwoo->get($tpl, array(), $this->compiler));
}
public function testTextFormat()
{
$tpl = new Dwoo_Template_String('aa{textformat wrap=10 wrap_char="\n"}hello world is so unoriginal but hey.. {textformat wrap=4 wrap_char="\n"}a a a a a a{/textformat}it works.{/textformat}bb');
......
{load_templates "templates.html"}
{noparam}
\ No newline at end of file
......@@ -10,4 +10,8 @@
{/if}
{/foreach}
</ul>
{/template}
{template noparam}
noparamoutput
{/template}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment