[limb-svn] r6270 - in 3.x/trunk/limb/macro: src tests/cases tests/cases/tags
svn at limb-project.com
svn at limb-project.com
Fri Sep 7 12:02:59 MSD 2007
Author: pachanga
Date: 2007-09-07 12:02:59 +0400 (Fri, 07 Sep 2007)
New Revision: 6270
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6270
Modified:
3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php
3.x/trunk/limb/macro/src/lmbMacroCompiler.class.php
3.x/trunk/limb/macro/src/lmbMacroTemplate.class.php
3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateTest.class.php
3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php
Log:
-- draft implementation of <%include%> tag with static include added
Modified: 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php 2007-09-06 22:21:52 UTC (rev 6269)
+++ 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php 2007-09-07 08:02:59 UTC (rev 6270)
@@ -36,13 +36,14 @@
protected $temp_var_name = 1;
- function __construct($class, $parent = 'lmbMacroTemplateExecutor')
+ function __construct($class, $render_func = 'render')
{
$this->class = $class;
- $this->parent = $parent;
+ $this->render_func = $render_func;
+ $this->parent = 'lmbMacroTemplateExecutor';
+ $this->registerInclude('limb/macro/src/lmbMacroTemplateExecutor.class.php');
- $this->registerInclude('limb/macro/src/lmbMacroTemplateExecutor.class.php');
- $this->beginMethod('render');
+ $this->beginMethod($render_func);
}
function getClass()
Modified: 3.x/trunk/limb/macro/src/lmbMacroCompiler.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroCompiler.class.php 2007-09-06 22:21:52 UTC (rev 6269)
+++ 3.x/trunk/limb/macro/src/lmbMacroCompiler.class.php 2007-09-07 08:02:59 UTC (rev 6270)
@@ -40,7 +40,6 @@
*/
protected $tag_dictionary;
-
function __construct($tag_dictionary, $template_locator)
{
$this->template_locator = $template_locator;
@@ -48,26 +47,22 @@
$this->tree_builder = new lmbMacroTreeBuilder($this);
}
- function compile($file_name)
+ function compile($source_file, $compiled_file, $class, $render_func)
{
- if(!$source_file_path = $this->template_locator->locateSourceTemplate($file_name))
- throw new lmbMacroException('Template source file not found', array('file_name' => $file_name));
+ $root_node = new lmbMacroNode(new lmbMacroSourceLocation($source_file, ''));
+ $this->parseTemplate($source_file, $root_node);
- $root_node = new lmbMacroNode(new lmbMacroSourceLocation($source_file_path, ''));
- $this->parseTemplate($file_name, $root_node);
$root_node->prepare();
- $compiled_file_path = $this->template_locator->locateCompiledTemplate($file_name);
- list($class, $render_func, $generated_code) = $this->_generateTemplateCode(md5($compiled_file_path), $root_node);
- self :: writeFile($compiled_file_path, $generated_code);
- return array($class, $render_func, $compiled_file_path);
+ $generated_code = $this->_generateTemplateCode($class, $render_func, $root_node);
+ self :: writeFile($compiled_file, $generated_code);
}
- function _generateTemplateCode($hash, $root_node)
+ function _generateTemplateCode($class, $render_func, $root_node)
{
- $code_writer = new lmbMacroCodeWriter($class = 'TemplateExecutor' . $hash);
+ $code_writer = new lmbMacroCodeWriter($class, $render_func);
$root_node->generate($code_writer);
- return array($class, $code_writer->getRenderMethod(), $code_writer->renderCode());
+ return $code_writer->renderCode();
}
function parseTemplate($source_file_path, $root_node)
Modified: 3.x/trunk/limb/macro/src/lmbMacroTemplate.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTemplate.class.php 2007-09-06 22:21:52 UTC (rev 6269)
+++ 3.x/trunk/limb/macro/src/lmbMacroTemplate.class.php 2007-09-07 08:02:59 UTC (rev 6270)
@@ -39,15 +39,21 @@
function render()
{
- ob_start();
+ if(!$source_file = $this->locator->locateSourceTemplate($this->file))
+ throw new lmbMacroException('Template source file not found', array('file_name' => $this->file));
+ $compiled_file = $this->locator->locateCompiledTemplate($this->file);
+
+ $class = 'TemplateExecutor' . uniqid();//???
+
$compiler = $this->_createCompiler();
- list($class, $func, $compiled_file) = $compiler->compile($this->file);
+ $compiler->compile($source_file, $compiled_file, $class, 'render');
- include_once($compiled_file);
+ include($compiled_file);
$executor = new $class($this->vars);
- $executor->$func();
+ ob_start();
+ $executor->render();
$out = ob_get_contents();
ob_end_clean();
return $out;
Modified: 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateTest.class.php 2007-09-06 22:21:52 UTC (rev 6269)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateTest.class.php 2007-09-07 08:02:59 UTC (rev 6270)
@@ -21,7 +21,7 @@
function testRenderTemplateVar()
{
- $view = $this->_createView('Hello, <?=$this->name?>');
+ $view = $this->_createView('Hello, <?php echo $this->name;?>');
$view->set('name', 'Bob');
$this->assertEqual($view->render(), 'Hello, Bob');
}
Modified: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php 2007-09-06 22:21:52 UTC (rev 6269)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php 2007-09-07 08:02:59 UTC (rev 6270)
@@ -38,13 +38,13 @@
function testIncludePassVariables()
{
$bar = '<body><?php $var2=2;?><%include file="foo.html" var1="1" var2="$var2"/%></body>';
- $foo = '<p>Numbers: <?=$var1?> <?=$var2?></p>';
+ $foo = '<p>Numbers: <?php echo $var1;?> <?php echo $var2;?></p>';
$bar_tpl = $this->_createTemplate($bar, 'bar.html');
$foo_tpl = $this->_createTemplate($foo, 'foo.html');
$macro = $this->_createMacro($bar_tpl);
-
+
$out = $macro->render();
$this->assertEqual($out, '<body><p>Numbers: 1 2</p></body>');
}
More information about the limb-svn
mailing list