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

svn at limb-project.com svn at limb-project.com
Fri Feb 8 13:02:49 MSK 2008


Author: serega
Date: 2008-02-08 13:02:49 +0300 (Fri, 08 Feb 2008)
New Revision: 6778
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6778

Added:
   3.x/trunk/limb/macro/src/tags/tree/tree_node.tag.php
Removed:
   3.x/trunk/limb/macro/src/tags/tree/tree_item.tag.php
Modified:
   3.x/trunk/limb/macro/src/tags/tree/tree.tag.php
   3.x/trunk/limb/macro/src/tags/tree/tree_next_level.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/tree/lmbMacroTreeTagTest.class.php
Log:
-- refactoring of {{tree}} tags:
  * {{tree:branch}} renamed into {{tree:node}}
  * {{tree:item}} renamed into {{tree:nextlevel}}
  * old names moved into aliases to preserve BC
  * recursion method call moved to {{tree:nextlevel}}. Now we can control the place where recursion called.
-- minor refactoring of {{include}} and {{apply}} tag (removed some duplication)

Modified: 3.x/trunk/limb/macro/src/tags/tree/tree.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/tree/tree.tag.php	2008-02-08 09:55:05 UTC (rev 6777)
+++ 3.x/trunk/limb/macro/src/tags/tree/tree.tag.php	2008-02-08 10:02:49 UTC (rev 6778)
@@ -25,9 +25,9 @@
     if(!$kids_prop = $this->get('kids_prop'))
       $kids_prop = 'kids';
 
-    $before_branch = $this->_getTagsBeforeBranch();
-    $after_branch = $this->_getTagsAfterBranch();
-    $branch = $this->findImmediateChildByClass('lmbMacroTreeItemTag');
+    $before_node = $this->_getTagsBeforeNode();
+    $after_node = $this->_getTagsAfterNode();
+    $tree_node = $this->findImmediateChildByClass('lmbMacroTreeNodeTag');
 
     $tree = $this->get('using');
 
@@ -48,18 +48,18 @@
      
     //rendering tags before branch
     $code->writePHP('if(!' . $counter . ") {\n");
-    foreach($before_branch as $tag)
+    foreach($before_node as $tag)
       $tag->generate($code);
     $code->writePHP("}\n");
 
-    $branch->generate($code);
+    $tree_node->generate($code);
 
     $code->writePHP($counter . "++;\n");
     $code->writePHP("}\n");//foreach
 
     //rendering tags after branch
     $code->writePHP('if(' . $counter . ") {\n");
-    foreach($after_branch as $tag)
+    foreach($after_node as $tag)
       $tag->generate($code);
     $code->writePHP("}\n");
 
@@ -74,19 +74,19 @@
     return $this->method;
   }
 
-  protected function _getTagsBeforeBranch()
+  protected function _getTagsBeforeNode()
   {
     $tags = array();
     foreach($this->children as $child)
     {
-      if(is_a($child, 'lmbMacroTreeItemTag'))
+      if(is_a($child, 'lmbMacroTreeNodeTag'))
         break;
       $tags[] = $child;
     }
     return $tags;
   }
 
-  protected function _getTagsAfterBranch()
+  protected function _getTagsAfterNode()
   {
     $tags = array();
     $collect = false;
@@ -94,7 +94,7 @@
     {
       if($collect)
         $tags[] = $child;
-      if(is_a($child, 'lmbMacroTreeItemTag'))
+      if(is_a($child, 'lmbMacroTreeNodeTag'))
         $collect = true;
     }
     return $tags;

Deleted: 3.x/trunk/limb/macro/src/tags/tree/tree_item.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/tree/tree_item.tag.php	2008-02-08 09:55:05 UTC (rev 6777)
+++ 3.x/trunk/limb/macro/src/tags/tree/tree_item.tag.php	2008-02-08 10:02:49 UTC (rev 6778)
@@ -1,18 +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
- */
-
-/**
- * @tag tree:item
- * @package macro
- * @version $Id$
- */
-class lmbMacroTreeItemTag extends lmbMacroTag
-{
-}
-

Modified: 3.x/trunk/limb/macro/src/tags/tree/tree_next_level.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/tree/tree_next_level.tag.php	2008-02-08 09:55:05 UTC (rev 6777)
+++ 3.x/trunk/limb/macro/src/tags/tree/tree_next_level.tag.php	2008-02-08 10:02:49 UTC (rev 6778)
@@ -9,6 +9,7 @@
 
 /**
  * @tag tree:nextlevel
+ * @aliases tree:item
  * @package macro
  * @version $Id$
  */

Copied: 3.x/trunk/limb/macro/src/tags/tree/tree_node.tag.php (from rev 6777, 3.x/trunk/limb/macro/src/tags/tree/tree_item.tag.php)
===================================================================
--- 3.x/trunk/limb/macro/src/tags/tree/tree_node.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/tree/tree_node.tag.php	2008-02-08 10:02:49 UTC (rev 6778)
@@ -0,0 +1,19 @@
+<?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
+ */
+
+/**
+ * @tag tree:node
+ * @aliases tree:branch
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroTreeNodeTag extends lmbMacroTag
+{
+}
+

Modified: 3.x/trunk/limb/macro/tests/cases/tags/tree/lmbMacroTreeTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/tree/lmbMacroTreeTagTest.class.php	2008-02-08 09:55:05 UTC (rev 6777)
+++ 3.x/trunk/limb/macro/tests/cases/tags/tree/lmbMacroTreeTagTest.class.php	2008-02-08 10:02:49 UTC (rev 6778)
@@ -76,5 +76,28 @@
     $out = $macro->render();
     $this->assertEqual($out, '<ul><li>1.1)foo</li><li>1.2)bar<ul><li>1.2.1)bar1</li><li>1.2.2)bar2</li></ul></li><li>1.3)hey</li></ul>');
   }
+  
+  function testCheckBC()
+  {
+    $content = '{{tree using="$#tree" as="$item" kids_prop="kids" counter="$counter" prefix="1"}}' . 
+                  '<ul>' . 
+                  '{{tree:branch}}' . 
+                  '<li>{$prefix}.{$counter})'.
+                  '{{tree:item prefix="$new_prefix"}}{$item.title}<?php $new_prefix = $prefix . "." . $counter; ?>{{/tree:item}}</li>' . 
+                  '{{/tree:branch}}' .
+                  '</ul>' . 
+                '{{/tree}}';
+
+    $tpl = $this->_createTemplate($content, 'tree.html');
+
+    $macro = $this->_createMacro($tpl);
+    $macro->set('tree', array(array('title' => 'foo'), 
+                              array('title' => 'bar', 'kids' => array(array('title' => 'bar1'),
+                                                                      array('title' => 'bar2'))), 
+                              array('title' => 'hey')));
+
+    $out = $macro->render();
+    $this->assertEqual($out, '<ul><li>1.1)foo</li><li>1.2)bar<ul><li>1.2.1)bar1</li><li>1.2.2)bar2</li></ul></li><li>1.3)hey</li></ul>');
+  }
 }
 



More information about the limb-svn mailing list