[limb-svn] r6325 - in 3.x/trunk/limb/macro: src/tags tests/cases/tags
svn at limb-project.com
svn at limb-project.com
Thu Sep 20 22:10:01 MSD 2007
Author: pachanga
Date: 2007-09-20 22:10:01 +0400 (Thu, 20 Sep 2007)
New Revision: 6325
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6325
Modified:
3.x/trunk/limb/macro/src/tags/list.tag.php
3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php
Log:
-- adding 'counter' attribute to <%list%> tag which allows to track internal list counter
Modified: 3.x/trunk/limb/macro/src/tags/list.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list.tag.php 2007-09-20 17:33:12 UTC (rev 6324)
+++ 3.x/trunk/limb/macro/src/tags/list.tag.php 2007-09-20 18:10:01 UTC (rev 6325)
@@ -20,18 +20,24 @@
function generateContents($code)
{
$using = $this->get('using');
- $as = $this->get('as');
+ if(!$as = $this->get('as'))
+ $as = '$item';
+
+ //internal list counter
$counter = $code->getTempVarRef();
$code->writePHP($counter . ' = 0;');
$code->writePHP('foreach(' . $using . ' as ' . $as . ') {');
+ if($user_counter = $this->get('counter'))
+ $code->writePHP($user_counter . ' = ' . $counter . '+1;');
+
+ //glue tag
$glue = $this->findImmediateChildByClass('lmbMacroListGlueTag');
$found_item_tag = false;
$postponed_nodes = array();
- //we need to render all nodes before and after <%list:*%> tags
foreach($this->children as $child)
{
//we want to skip all <%list:*%> tags, since they are rendered manually
Modified: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php 2007-09-20 17:33:12 UTC (rev 6324)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php 2007-09-20 18:10:01 UTC (rev 6325)
@@ -37,6 +37,19 @@
$this->assertEqual($out, 'Bob Todd ');
}
+ function testListUsingDefaultItem()
+ {
+ $list = '<%list using="$#list"%><%list:item%><?=$item?> <%/list:item%><%/list%>';
+
+ $list_tpl = $this->_createTemplate($list, 'list.html');
+
+ $macro = $this->_createMacro($list_tpl);
+ $macro->set('list', array('Bob', 'Todd'));
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'Bob Todd ');
+ }
+
function testEmptyList()
{
$list = '<%list using="$#list" as="$item"%><%list:item%><?=$item?><%/list:item%>' .
@@ -51,6 +64,19 @@
$this->assertEqual($out, 'Nothing');
}
+ function testShowCounter()
+ {
+ $list = '<%list using="$#list" counter="$ctr"%><%list:item%><?=$ctr?>)<?=$item?> <%/list:item%><%/list%>';
+
+ $list_tpl = $this->_createTemplate($list, 'list.html');
+
+ $macro = $this->_createMacro($list_tpl);
+ $macro->set('list', array('Bob', 'Todd'));
+
+ $out = $macro->render();
+ $this->assertEqual($out, '1)Bob 2)Todd ');
+ }
+
function testTextNodesInsideListTag()
{
$list = '<%list using="$#list" as="$item"%>List: <%list:item%><?=$item?> <%/list:item%> !<%/list%>';
More information about the limb-svn
mailing list