[limb-svn] r6261 - in 3.x/trunk/limb/wact: src/tags/list tests/cases/tags/list

svn at limb-project.com svn at limb-project.com
Wed Sep 5 12:30:37 MSD 2007


Author: serega
Date: 2007-09-05 12:30:37 +0400 (Wed, 05 Sep 2007)
New Revision: 6261
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6261

Added:
   3.x/trunk/limb/wact/src/tags/list/total_items.prop.php
Modified:
   3.x/trunk/limb/wact/src/tags/list/separator.tag.php
   3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php
Log:
-- TotalItems property added to <list:list> tag
-- <list:separator> now understand dynamic "step" attribute value

Modified: 3.x/trunk/limb/wact/src/tags/list/separator.tag.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/list/separator.tag.php	2007-09-04 22:35:49 UTC (rev 6260)
+++ 3.x/trunk/limb/wact/src/tags/list/separator.tag.php	2007-09-05 08:30:37 UTC (rev 6261)
@@ -2,9 +2,9 @@
 /*
  * Limb PHP Framework
  *
- * @link http://limb-project.com 
+ * @link http://limb-project.com
  * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 
 /**
@@ -23,26 +23,22 @@
   protected $runtimeIncludeFile = 'limb/wact/src/components/list/WactListSeparatorComponent.class.php';
   protected $runtimeComponentName = 'WactListSeparatorComponent';
 
-  protected $step;
-
   function preParse($compiler)
   {
-    if($step = $step = $this->getAttribute('every'))
-      $this->setAttribute('step', $step);
-
-    if ($step = $this->getAttribute('step'))
-      $this->step = $step;
-    else
-      $this->step = 1;
-
     if ($this->getBoolAttribute('literal'))
       return WACT_PARSER_FORBID_PARSING;
   }
 
   function generateTagContent($code)
   {
-    $code->writePhp($this->getComponentRefCode($code) . '->setStep(' . $this->step .');' . "\n");
+    $step_var = $code->getTempVarRef();
+    $code->writePHP($step_var . ' = ');
 
+    $this->generateStepAttributeValue($code);
+    $code->writePhp(";\n");
+
+    $code->writePhp($this->getComponentRefCode($code) . '->setStep(' . $step_var . ");\n");
+
     $ListList = $this->findParentByClass('WactListListTag');
 
     $code->writePhp($this->getComponentRefCode($code) . '->next();' . "\n");
@@ -56,8 +52,10 @@
     {
       foreach($separators as $separator)
       {
-        if($separator->getAttribute('step') < $this->getAttribute('step'))
-          $code->writePhp($separator->getComponentRefCode($code) . "->skipNext();\n");
+        $code->writePhp('if (');
+        $separator->generateStepAttributeValue($code);
+        $code->writePhp(' < ' . $step_var . ') ');
+        $code->writePhp($separator->getComponentRefCode($code) . "->skipNext();\n");
       }
     }
 
@@ -65,5 +63,15 @@
 
     $code->writePhp('}'. "\n");
   }
+
+  function generateStepAttributeValue($code)
+  {
+    if($this->hasAttribute('every'))
+      $this->attributeNodes['every']->generateExpression($code);
+    elseif($this->hasAttribute('step'))
+      $this->attributeNodes['step']->generateExpression($code);
+    else
+      $code->writePhp("1");
+  }
 }
 

Added: 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php	                        (rev 0)
+++ 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php	2007-09-05 08:30:37 UTC (rev 6261)
@@ -0,0 +1,25 @@
+<?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
+ */
+
+/**
+ * @property TotalItems
+ * @tag_class WactListListTag
+ * @package wact
+ * @version $Id$
+ */
+class WactPagerTotalItemsProperty extends WactCompilerProperty
+{
+  function generateExpression($code)
+  {
+    $code->writePHP($this->context->getComponentRefCode());
+    $code->writePHP('->count()');
+  }
+}
+
+

Modified: 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php
===================================================================
--- 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php	2007-09-04 22:35:49 UTC (rev 6260)
+++ 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php	2007-09-05 08:30:37 UTC (rev 6261)
@@ -2,9 +2,9 @@
 /*
  * Limb PHP Framework
  *
- * @link http://limb-project.com 
+ * @link http://limb-project.com
  * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 
 require_once('limb/wact/tests/cases/WactTemplateTestCase.class.php');
@@ -179,6 +179,21 @@
     $this->assertEqual($output, 'George{$var}Alexander{$var}Benjamin');
   }
 
+  function testSeparatorWithDynamicStepValue()
+  {
+    $template = '<list:LIST id="test">'.
+                '<list:ITEM>{$First}<list:SEPARATOR every="{$#step}">|</list:SEPARATOR></list:ITEM>'.
+                '</list:LIST>';
+
+    $this->registerTestingTemplate('/tags/list/separator_dynamic_step.html', $template);
+
+    $page = $this->initTemplate('/tags/list/separator_dynamic_step.html');
+    $page->setChildDataset('test', $this->founding_fathers);
+    $page->set('step', 2);
+
+    $this->assertEqual($page->capture(), 'GeorgeAlexander|Benjamin');
+  }
+
   function testListDefaultWithDataNotOutput()
   {
     $template = '<list:LIST id="test"><list:ITEM>{$First}-</list:ITEM>'.
@@ -288,6 +303,19 @@
     $this->assertEqual($output, "odd:George-even:Alexander-odd:Benjamin-");
   }
 
+  function testListTotalItemsProperty()
+  {
+    $template = '<list:LIST id="test">{$:TotalItems}</list:LIST>';
+
+    $this->registerTestingTemplate('/tags/list/list-total-items.html', $template);
+    $page = $this->initTemplate('/tags/list/list-total-items.html');
+
+    $list = $page->getChild('test');
+    $list->registerDataSet($this->founding_fathers);
+    $output = $page->capture();
+    $this->assertEqual($output, "3");
+  }
+
   function testListFrom()
   {
     $template = '<list:LIST from="{$test}"><list:ITEM>{$First}-</list:ITEM></list:LIST>';



More information about the limb-svn mailing list