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

svn at limb-project.com svn at limb-project.com
Fri May 9 23:40:27 MSD 2008


Author: pachanga
Date: 2008-05-09 23:40:26 +0400 (Fri, 09 May 2008)
New Revision: 6990
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6990

Added:
   3.x/trunk/limb/macro/src/tags/core/nospace.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php
Modified:
   3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php
Log:
-- adding experimental {{nospace}} tag

Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php	2008-05-08 14:24:58 UTC (rev 6989)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php	2008-05-09 19:40:26 UTC (rev 6990)
@@ -15,6 +15,7 @@
  */
 class lmbMacroTextNode extends lmbMacroNode
 {
+  protected static $trim = false;
   protected $contents;
 
   function __construct($location, $text)
@@ -25,10 +26,19 @@
 
   function generate($code_writer)
   {
-    $code_writer->writeHtml($this->contents);
+    if(self :: $trim)
+      $code_writer->writeHtml(trim($this->contents));
+    else
+      $code_writer->writeHtml($this->contents);
+
     parent :: generate($code_writer);
   }
 
+  static function setTrim($flag = true)
+  {
+    self :: $trim = $flag;
+  }
+
   function getText()
   {
     return $this->contents;

Added: 3.x/trunk/limb/macro/src/tags/core/nospace.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/nospace.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/nospace.tag.php	2008-05-09 19:40:26 UTC (rev 6990)
@@ -0,0 +1,15 @@
+<?php
+/**
+ * class lmbMacroNospaceTag.
+ * @tag nospace
+ * @restrict_self_nesting
+ */
+class lmbMacroNospaceTag extends lmbMacroTag
+{
+  protected function _generateContent($code)
+  {
+    lmbMacroTextNode :: setTrim(true);
+    parent :: _generateContent($code);
+    lmbMacroTextNode :: setTrim(false);
+  }
+}

Added: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php	2008-05-09 19:40:26 UTC (rev 6990)
@@ -0,0 +1,30 @@
+<?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
+ */
+
+class lmbMacroNospaceTagTest extends lmbBaseMacroTest
+{
+  function testTrimSpace()
+  {
+    $template = '{{nospace}}   Bob    {{/nospace}}';
+
+    $page = $this->_createMacroTemplate($template, 'tpl.html');
+    
+    $this->assertEqual($page->render(), 'Bob');
+  }
+
+  function testMixTrimAndNoTrim()
+  {
+    $template = ' Todd {{nospace}}   Bob    {{/nospace}} Hey';
+
+    $page = $this->_createMacroTemplate($template, 'tpl.html');
+    
+    $this->assertEqual($page->render(), ' Todd Bob Hey'); 
+  }
+}
+



More information about the limb-svn mailing list