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

svn at limb-project.com svn at limb-project.com
Thu Sep 20 09:54:27 MSD 2007


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

Added:
   3.x/trunk/limb/macro/src/tags/list.tag.php
   3.x/trunk/limb/macro/src/tags/list_empty.tag.php
   3.x/trunk/limb/macro/src/tags/list_item.tag.php
   3.x/trunk/limb/macro/src/tags/list_separator.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php
Log:
-- adding initial implementation of <%list%> tag (MCR-5)

Added: 3.x/trunk/limb/macro/src/tags/list.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/list.tag.php	2007-09-20 05:54:27 UTC (rev 6320)
@@ -0,0 +1,43 @@
+<?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');
+
+/**
+ * The parent compile time component for lists
+ * @tag list
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroListTag extends lmbMacroTag
+{
+  function generateContents($code)
+  {
+    $counter = $code->getTempVarRef();
+    $using = $this->get('using');
+    $as = $this->get('as');
+
+    $list_item = $this->findImmediateChildByClass('lmbMacroListItemTag');
+    $list_empty = $this->findImmediateChildByClass('lmbMacroListEmptyTag');
+
+    $code->writePHP($counter . ' = 0;');
+    $code->writePHP('foreach(' . $using . ' as ' . $as . ') {');
+    $list_item->generateContents($code);
+    $code->writePHP($counter . '++;');
+    $code->writePHP('}');
+
+    if($list_empty)
+    {
+      $code->writePHP('if(' . $counter . ' == 0) {');
+      $list_empty->generateContents($code);
+      $code->writePHP('}');
+    }
+  }
+}
+

Added: 3.x/trunk/limb/macro/src/tags/list_empty.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list_empty.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/list_empty.tag.php	2007-09-20 05:54:27 UTC (rev 6320)
@@ -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');
+
+/**
+ * Empty List tag for a list which failed to have any contents
+ * @tag list:empty
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroListEmptyTag extends lmbMacroTag
+{
+}
+

Added: 3.x/trunk/limb/macro/src/tags/list_item.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list_item.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/list_item.tag.php	2007-09-20 05:54:27 UTC (rev 6320)
@@ -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 items (rows) in the list
+ * @tag list:item
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroListItemTag extends lmbMacroTag
+{
+}
+

Added: 3.x/trunk/limb/macro/src/tags/list_separator.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/list_separator.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/list_separator.tag.php	2007-09-20 05:54:27 UTC (rev 6320)
@@ -0,0 +1,24 @@
+<?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)
+  {
+  }
+}
+

Added: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroListTagTest.class.php	2007-09-20 05:54:27 UTC (rev 6320)
@@ -0,0 +1,70 @@
+<?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/fs/src/lmbFs.class.php');
+lmb_require('limb/macro/src/lmbMacroTemplate.class.php');
+lmb_require('limb/macro/src/lmbMacroTagDictionary.class.php');
+
+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');
+
+class lmbMacroWrapTagTest extends UnitTestCase
+{
+  function setUp()
+  {
+    lmbFs :: rm(LIMB_VAR_DIR . '/tpl');
+    lmbFs :: mkdir(LIMB_VAR_DIR . '/tpl/compiled');
+  }
+
+  function testSimpleList()
+  {
+    $list = '<%list using="$#list" as="$item"%><%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%>' . 
+            '<%list:empty%>Nothing<%/list:empty%><%/list%>';
+
+    $list_tpl = $this->_createTemplate($list, 'list.html');
+
+    $macro = $this->_createMacro($list_tpl);
+    $macro->set('list', array());
+
+    $out = $macro->render();
+    $this->assertEqual($out, 'Nothing');
+  }
+
+  protected function _createMacro($file)
+  {
+    $base_dir = LIMB_VAR_DIR . '/tpl';
+    $cache_dir = LIMB_VAR_DIR . '/tpl/compiled';
+    $macro = new lmbMacroTemplate($file,
+                                  $cache_dir,
+                                  new lmbMacroTemplateLocator($base_dir, $cache_dir));
+    return $macro;
+  }
+
+  protected function _createTemplate($code, $name)
+  {
+    $file = LIMB_VAR_DIR . '/tpl/' . $name;
+    file_put_contents($file, $code);
+    return $file;
+  }
+}
+



More information about the limb-svn mailing list