[limb-svn] r6286 - in 3.x/trunk/limb/macro: src tests/cases tests/cases/tags

svn at limb-project.com svn at limb-project.com
Mon Sep 10 16:11:48 MSD 2007


Author: pachanga
Date: 2007-09-10 16:11:48 +0400 (Mon, 10 Sep 2007)
New Revision: 6286
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6286

Added:
   3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateExecutorTest.class.php
Modified:
   3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php
   3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php
Log:
-- parent attributes are exported into dynamically included templates via lmbMacroTemplateExecutore :: includeTemplate(..)

Modified: 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php	2007-09-10 11:30:01 UTC (rev 6285)
+++ 3.x/trunk/limb/macro/src/lmbMacroTemplateExecutor.class.php	2007-09-10 12:11:48 UTC (rev 6286)
@@ -46,7 +46,8 @@
   function includeTemplate($file, $vars = array())
   {
     $template = new lmbMacroTemplate($file, $this->cache_dir, $this->locator);
-    echo $template->render($vars);
+    $template->setVars(get_object_vars($this));//global template vars
+    echo $template->render($vars);//local template vars
   }
 }
 

Added: 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateExecutorTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateExecutorTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTemplateExecutorTest.class.php	2007-09-10 12:11:48 UTC (rev 6286)
@@ -0,0 +1,30 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com 
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ */
+
+lmb_require('limb/macro/src/lmbMacroTemplateExecutor.class.php'); 
+
+class lmbMacroTemplateExecutorTest extends UnitTestCase
+{
+  function testPassVars()
+  {
+    $tpl = new lmbMacroTemplateExecutor(array('foo' => 'foo', 'bar' => 'bar'));
+    $tpl->set('zoo', 'zoo');
+    $this->assertEqual($tpl->foo, 'foo');
+    $this->assertEqual($tpl->bar, 'bar');
+    $this->assertEqual($tpl->zoo, 'zoo');
+  }
+
+  function testMissingVarIsEmpty()
+  {
+    $tpl = new lmbMacroTemplateExecutor();
+    $this->assertNoErrors();
+    $this->assertIdentical($tpl->junk, '');
+  }
+}
+

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-10 11:30:01 UTC (rev 6285)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroIncludeTagTest.class.php	2007-09-10 12:11:48 UTC (rev 6286)
@@ -108,6 +108,22 @@
     $this->assertEqual($out, '<body><p>Hello, Fred!</p></body>');
   } 
 
+  function testDynamicIncludeMixLocalAndTemplateVars()
+  {
+    $bar = '<body><?php $name = "Fred";?><%include file="$this->file" name="$name"/%></body>';
+    $foo = '<p>Hello, <?php echo $name . " " . $this->lastname;?>!</p>';
+
+    $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+    $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+    $macro = $this->_createMacro($bar_tpl);
+    $macro->set('file', 'foo.html');
+    $macro->set('lastname', 'Atkins');
+    
+    $out = $macro->render();
+    $this->assertEqual($out, '<body><p>Hello, Fred Atkins!</p></body>');
+  } 
+
   protected function _createMacro($file)
   {
     $base_dir = LIMB_VAR_DIR . '/tpl';



More information about the limb-svn mailing list