[limb-svn] r7060 - in 3.x/trunk/limb/macro: src/tags/list tests/cases/tags/list
svn at limb-project.com
svn at limb-project.com
Tue Jun 10 17:48:56 MSD 2008
Author: conf
Date: 2008-06-10 17:48:56 +0400 (Tue, 10 Jun 2008)
New Revision: 7060
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7060
Modified:
3.x/trunk/limb/macro/src/tags/list/list.tag.php
3.x/trunk/limb/macro/tests/cases/tags/list/lmbMacroListTagTest.class.php
Log:
-- added key attribute for list tag.
Modified: 3.x/trunk/limb/macro/src/tags/list/list.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list/list.tag.php 2008-06-09 12:28:30 UTC (rev 7059)
+++ 3.x/trunk/limb/macro/src/tags/list/list.tag.php 2008-06-10 13:48:56 UTC (rev 7060)
@@ -46,7 +46,13 @@
$this->_initializeGlueTags($code);
- $code->writePHP('foreach(' . $this->source_var . ' as ' . $as . ') {');
+ $key = '';
+
+ if ($key_var = $this->get('key')) {
+ $key = $key_var . ' => ';
+ }
+
+ $code->writePHP('foreach(' . $this->source_var . ' as ' . $key . $as . ') {');
if($user_counter = $this->get('counter'))
$code->writePHP($user_counter . ' = ' . $this->counter_var . '+1;');
Modified: 3.x/trunk/limb/macro/tests/cases/tags/list/lmbMacroListTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/list/lmbMacroListTagTest.class.php 2008-06-09 12:28:30 UTC (rev 7059)
+++ 3.x/trunk/limb/macro/tests/cases/tags/list/lmbMacroListTagTest.class.php 2008-06-10 13:48:56 UTC (rev 7060)
@@ -102,6 +102,19 @@
$this->assertEqual($out, 'Nothing');
}
+ function testKeyValue()
+ {
+ $list = '{{list using="$#list" as="$item" key="$name"}}{{list:item}}{$name} is {$item}, {{/list:item}}{{/list}}';
+
+ $list_tpl = $this->_createTemplate($list, 'list.html');
+
+ $macro = $this->_createMacro($list_tpl);
+ $macro->set('list', array('Bob' => 'god', 'Todd' => 'odd', 'zero', 1 => 'one'));
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'Bob is god, Todd is odd, 0 is zero, 1 is one, ');
+ }
+
function testParity()
{
$list = '{{list using="$#list" as="$item" parity="$parity"}}{{list:item}}{$parity}-{$item} {{/list:item}} !{{/list}}';
More information about the limb-svn
mailing list