[limb-svn] r6408 - in 3.x/trunk/limb/macro: src tests/bench tests/cases
svn at limb-project.com
svn at limb-project.com
Wed Oct 10 21:34:01 MSD 2007
Author: pachanga
Date: 2007-10-10 21:34:01 +0400 (Wed, 10 Oct 2007)
New Revision: 6408
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6408
Modified:
3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php
3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php
3.x/trunk/limb/macro/tests/bench/macro-force.php
3.x/trunk/limb/macro/tests/cases/lmbMacroCodeWriterTest.class.php
Log:
-- lmbMacroCodeWriter :: writeToInit($php) added, it allows to add PHP code which will be called first before rendering the rest of template
-- minor improvements
Modified: 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php 2007-10-10 11:55:20 UTC (rev 6407)
+++ 3.x/trunk/limb/macro/src/lmbMacroCodeWriter.class.php 2007-10-10 17:34:01 UTC (rev 6408)
@@ -30,6 +30,8 @@
protected $methods = array();
+ protected $init_code = '';
+
protected $methods_stack = array();
protected $include_list = array();
@@ -45,6 +47,7 @@
$this->beginMethod($render_func, array('$args = array()'));
$this->writePHP('if($args) extract($args);');
+ $this->writePHP('$this->_init();');
}
function getClass()
@@ -117,14 +120,20 @@
{
$this->endMethod();
- return "<?php\n" .
+ $code = "<?php\n" .
//protection from self inclusion
"if(!class_exists('{$this->class}', false)){\n" .
$this->_renderIncludeList() .
"class {$this->class} " . ($this->parent ? "extends {$this->parent} " : '') . "{\n" .
+ (!$this->init_code ? "" :
+ "\nfunction _init() {" .
+ "\n$this->init_code\n" .
+ "}\n"
+ ) .
$this->_renderMethods() .
"\n}" .
"\n}";
+ return $code;
}
function getCode()
@@ -176,6 +185,11 @@
list($this->current_method, $this->current_mode) = array_pop($this->methods_stack);
}
+ function writeToInit($code)
+ {
+ $this->init_code .= $code;
+ }
+
/**
* Utility method, which generates a unique variable name
*/
Modified: 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php 2007-10-10 11:55:20 UTC (rev 6407)
+++ 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php 2007-10-10 17:34:01 UTC (rev 6408)
@@ -7,6 +7,8 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
+lmb_require('limb/macro/src/lmbMacroConfig.class.php');
+
/**
* class lmbMacroTemplateExecutor.
*
@@ -26,6 +28,9 @@
$this->setVars($vars);
}
+ //overridden in children
+ protected function _init(){}
+
function setVars($vars)
{
foreach($vars as $name => $value)
Modified: 3.x/trunk/limb/macro/tests/bench/macro-force.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/macro-force.php 2007-10-10 11:55:20 UTC (rev 6407)
+++ 3.x/trunk/limb/macro/tests/bench/macro-force.php 2007-10-10 17:34:01 UTC (rev 6408)
@@ -11,7 +11,6 @@
for($i=0;$i<1000;$i++)
{
$tpl = new lmbMacroTemplate('macro.phtml', $config);
- $tpl->set('name', 'Bob');
$tpl->render();
}
Modified: 3.x/trunk/limb/macro/tests/cases/lmbMacroCodeWriterTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroCodeWriterTest.class.php 2007-10-10 11:55:20 UTC (rev 6407)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroCodeWriterTest.class.php 2007-10-10 17:34:01 UTC (rev 6408)
@@ -90,6 +90,22 @@
$this->assertEqual($this->_render(), 'abba');
}
+ function testWriteIntoConstructor()
+ {
+ $bar = $this->writer->beginMethod('bar' . mt_rand());
+ $this->writer->writePHP('echo "b-b-b";');
+ $this->writer->endMethod();
+
+ $foo = $this->writer->beginMethod('foo' . mt_rand());
+ $this->writer->writePHP('echo "a-a-a";');
+ $this->writer->endMethod();
+
+ $this->writer->writePHP("\$this->$bar();");
+ $this->writer->writeToInit("\$this->$foo();");
+
+ $this->assertEqual($this->_render(), 'a-a-ab-b-b');
+ }
+
function testGetTempVariable()
{
$var = $this->writer->getTempVariable();
More information about the limb-svn
mailing list