[limb-svn] r6307 - in 3.x/trunk/limb/macro: src/tags tests/cases/tags
svn at limb-project.com
svn at limb-project.com
Sun Sep 16 17:30:04 MSD 2007
Author: pachanga
Date: 2007-09-16 17:30:04 +0400 (Sun, 16 Sep 2007)
New Revision: 6307
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6307
Modified:
3.x/trunk/limb/macro/src/tags/into.tag.php
3.x/trunk/limb/macro/src/tags/wrap.tag.php
3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php
Log:
-- dynamic multi <%wrap%> now works too
Modified: 3.x/trunk/limb/macro/src/tags/into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/into.tag.php 2007-09-16 12:29:26 UTC (rev 6306)
+++ 3.x/trunk/limb/macro/src/tags/into.tag.php 2007-09-16 13:30:04 UTC (rev 6307)
@@ -26,8 +26,11 @@
{
parent :: preParse($compiler);
- $tree_builder = $compiler->getTreeBuilder();
- $this->_insert($this->parent, $tree_builder, $this->get('slot'));
+ if(!$this->parent->isDynamic())
+ {
+ $tree_builder = $compiler->getTreeBuilder();
+ $this->_insert($this->parent, $tree_builder, $this->get('slot'));
+ }
}
function _insert($wrapper, $tree_builder, $point)
Modified: 3.x/trunk/limb/macro/src/tags/wrap.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/wrap.tag.php 2007-09-16 12:29:26 UTC (rev 6306)
+++ 3.x/trunk/limb/macro/src/tags/wrap.tag.php 2007-09-16 13:30:04 UTC (rev 6307)
@@ -28,7 +28,10 @@
{
parent :: preParse($compiler);
- if(!$this->isVariable('with'))
+ if($this->isVariable('with'))
+ $this->is_dynamic = true;
+
+ if(!$this->is_dynamic)
{
$file = $this->get('with');
$this->_compileSourceFileName($file, $compiler);
@@ -40,10 +43,13 @@
$this->_insert($this, $tree_builder, $into);
}
}
- else
- $this->is_dynamic = true;
}
+ function isDynamic()
+ {
+ return $this->is_dynamic;
+ }
+
protected function _compileSourceFileName($file, $compiler)
{
$this->sourcefile = $compiler->getTemplateLocator()->locateSourceTemplate($file);
@@ -72,16 +78,38 @@
$tree_builder->pushCursor($insertionPoint, $this->location);
}
+ protected function _collectIntos()
+ {
+ return $this->findImmediateChildrenByClass('lmbMacroIntoTag');
+ }
+
function generateContents($code)
{
if($this->is_dynamic)
{
- $method = $code->beginMethod('__slotHandler'. mt_rand());
- parent :: generateContents($code);
- $code->endMethod();
+ $handlers_str = 'array(';
+ $methods = array();
- $handlers_str = 'array(';
- $handlers_str .= '"' . $this->get('into') . '"' . ' => array($this, "' . $method . '")';
+ //collecting <%into%> tags
+ if($intos = $this->_collectIntos())
+ {
+ foreach($intos as $into)
+ {
+ $methods[$into->get('slot')] = $code->beginMethod('__slotHandler'. mt_rand());
+ $into->generateContents($code);
+ $code->endMethod();
+ }
+ }
+ else
+ {
+ $methods[$this->get('into')] = $code->beginMethod('__slotHandler'. mt_rand());
+ parent :: generateContents($code);
+ $code->endMethod();
+ }
+
+ foreach($methods as $slot => $method)
+ $handlers_str .= '"' . $slot . '"' . ' => array($this, "' . $method . '"),';
+
$handlers_str .= ')';
$code->writePHP('$this->wrapTemplate(' . $this->get('with') . ', ' . $handlers_str . ');');
Modified: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php 2007-09-16 12:29:26 UTC (rev 6306)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php 2007-09-16 13:30:04 UTC (rev 6307)
@@ -96,6 +96,21 @@
$this->assertEqual($out, '<p>Hello, Bob</p>');
}
+ function testMultiDynamicWrap()
+ {
+ $bar = '<%wrap with="$this->layout"%><%into slot="slot1"%>Bob<%/into%><%into slot="slot2"%>Thorton<%/into%><%/wrap%>';
+ $foo = '<p>Hello, <%slot id="slot2"/%> <%slot id="slot1"/%></p>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+ $macro->set('layout', 'foo.html');
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<p>Hello, Thorton Bob</p>');
+ }
+
function testMixStaticAndDynamicWrap()
{
$bar = '<%wrap with="$this->layout" into="slot1"%><?php echo $this->bob?><%/wrap%>';
More information about the limb-svn
mailing list