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

svn at limb-project.com svn at limb-project.com
Thu Sep 20 21:33:12 MSD 2007


Author: pachanga
Date: 2007-09-20 21:33:12 +0400 (Thu, 20 Sep 2007)
New Revision: 6324
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6324

Added:
   3.x/trunk/limb/macro/src/tags/list_glue.tag.php
Removed:
   3.x/trunk/limb/macro/src/tags/list_separator.tag.php
Modified:
   3.x/trunk/limb/macro/src/tags/list.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php
Log:
-- adding support for <%list:glue%> tag(separator)

Modified: 3.x/trunk/limb/macro/src/tags/list.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list.tag.php	2007-09-20 16:58:03 UTC (rev 6323)
+++ 3.x/trunk/limb/macro/src/tags/list.tag.php	2007-09-20 17:33:12 UTC (rev 6324)
@@ -26,6 +26,8 @@
     $code->writePHP($counter . ' = 0;');
     $code->writePHP('foreach(' . $using . ' as ' . $as . ') {');
 
+    $glue = $this->findImmediateChildByClass('lmbMacroListGlueTag');
+
     $found_item_tag = false;
     $postponed_nodes = array();
 
@@ -49,6 +51,12 @@
       elseif(is_a($child, 'lmbMacroListItemTag'))
       {
         $found_item_tag = true;
+        if($glue)
+        {
+          $code->writePHP('if('. $counter . ' > 0) {');
+          $glue->generateContents($code);
+          $code->writePHP('}');
+        }
         $child->generateContents($code);
       }
     }
@@ -74,8 +82,16 @@
 
   protected function _isOneOfListTags($node)
   {
-    return is_a($node, 'lmbMacroListEmptyTag') || 
-           is_a($node, 'lmbMacroListItemTag');
+    $classes = array('lmbMacroListEmptyTag',
+                   'lmbMacroListItemTag',
+                   'lmbMacroListGlueTag');
+
+    foreach($classes as $class)
+    {
+      if(is_a($node, $class))
+        return true;
+    }
+    return false;
   }
 }
 

Copied: 3.x/trunk/limb/macro/src/tags/list_glue.tag.php (from rev 6322, 3.x/trunk/limb/macro/src/tags/list_separator.tag.php)
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list_glue.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/list_glue.tag.php	2007-09-20 17:33:12 UTC (rev 6324)
@@ -0,0 +1,21 @@
+<?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/lmbMacroTag.class.php');
+
+/**
+ * Compile time component for separators in a list
+ * @tag list:glue
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroListGlueTag extends lmbMacroTag
+{
+}
+

Deleted: 3.x/trunk/limb/macro/src/tags/list_separator.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list_separator.tag.php	2007-09-20 16:58:03 UTC (rev 6323)
+++ 3.x/trunk/limb/macro/src/tags/list_separator.tag.php	2007-09-20 17:33:12 UTC (rev 6324)
@@ -1,24 +0,0 @@
-<?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/lmbMacroTag.class.php');
-
-/**
- * Compile time component for separators in a list
- * @tag list:separator
- * @package macro
- * @version $Id$
- */
-class lmbMacroListSeparatorTag extends lmbMacroTag
-{
-  function generateContents($code)
-  {
-  }
-}
-

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 16:58:03 UTC (rev 6323)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php	2007-09-20 17:33:12 UTC (rev 6324)
@@ -14,8 +14,9 @@
 lmbMacroTagDictionary :: instance()->registerFromFile(dirname(__FILE__) . '/../../../src/tags/list.tag.php');
 lmbMacroTagDictionary :: instance()->registerFromFile(dirname(__FILE__) . '/../../../src/tags/list_item.tag.php');
 lmbMacroTagDictionary :: instance()->registerFromFile(dirname(__FILE__) . '/../../../src/tags/list_empty.tag.php');
+lmbMacroTagDictionary :: instance()->registerFromFile(dirname(__FILE__) . '/../../../src/tags/list_glue.tag.php');
 
-class lmbMacroWrapTagTest extends UnitTestCase
+class lmbMacroListTagTest extends UnitTestCase
 {
   function setUp()
   {
@@ -65,7 +66,8 @@
 
   function testTextNodesInsideListTagWithEmptyListTag()
   {
-    $list = '<%list using="$#list" as="$item"%>List: <%list:item%><?=$item?> <%/list:item%> !<%list:empty%>Nothing<%/list:empty%><%/list%>';
+    $list = '<%list using="$#list" as="$item"%>List: <%list:item%><?=$item?> <%/list:item%> !' . 
+            '<%list:empty%>Nothing<%/list:empty%><%/list%>';
 
     $list_tpl = $this->_createTemplate($list, 'list.html');
 
@@ -76,6 +78,20 @@
     $this->assertEqual($out, 'Nothing');
   }
 
+  function testListWithGlue()
+  {
+    $list = '<%list using="$#list" as="$item"%>List:<%list:item%><?=$item?><%/list:item%>!' . 
+            '<%list:glue%>||<%/list:glue%><%/list%>';
+
+    $list_tpl = $this->_createTemplate($list, 'list.html');
+
+    $macro = $this->_createMacro($list_tpl);
+    $macro->set('list', array('Bob', 'Todd', 'Marry'));
+
+    $out = $macro->render();
+    $this->assertEqual($out, 'List:Bob||Todd||Marry!');
+  }
+
   protected function _createMacro($file)
   {
     $base_dir = LIMB_VAR_DIR . '/tpl';



More information about the limb-svn mailing list