[limb-svn] r7001 - 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
Mon May 12 01:03:16 MSD 2008
Author: pachanga
Date: 2008-05-12 01:03:15 +0400 (Mon, 12 May 2008)
New Revision: 7001
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7001
Added:
3.x/trunk/limb/macro/src/tags/core/newline.tag.php
3.x/trunk/limb/macro/src/tags/core/space.tag.php
3.x/trunk/limb/macro/src/tags/core/tab.tag.php
3.x/trunk/limb/macro/src/tags/core/trim.tag.php
Modified:
3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php
3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php
Log:
-- adding {{space}},{{newline}},{{tab}} tags and ressurecting the previous {{nospace}} implementation into {{trim}}
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php 2008-05-11 17:05:42 UTC (rev 7000)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroTextNode.class.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -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/newline.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/newline.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/newline.tag.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -0,0 +1,14 @@
+<?php
+/**
+ * class lmbMacroNewlineTag.
+ * @tag newline
+ * @aliases nl
+ * @forbid_end_tag
+ */
+class lmbMacroNewlineTag extends lmbMacroTag
+{
+ protected function _generateContent($code)
+ {
+ $code->writeHtml("\n");
+ }
+}
Added: 3.x/trunk/limb/macro/src/tags/core/space.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/space.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/space.tag.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -0,0 +1,14 @@
+<?php
+/**
+ * class lmbMacroSpaceTag.
+ * @tag space
+ * @aliases sp
+ * @forbid_end_tag
+ */
+class lmbMacroSpaceTag extends lmbMacroTag
+{
+ protected function _generateContent($code)
+ {
+ $code->writeHtml(" ");
+ }
+}
Added: 3.x/trunk/limb/macro/src/tags/core/tab.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/tab.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/tab.tag.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -0,0 +1,13 @@
+<?php
+/**
+ * class lmbMacroTabTag.
+ * @tag tab
+ * @forbid_end_tag
+ */
+class lmbMacroTabTag extends lmbMacroTag
+{
+ protected function _generateContent($code)
+ {
+ $code->writeHtml("\t");
+ }
+}
Added: 3.x/trunk/limb/macro/src/tags/core/trim.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/trim.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/trim.tag.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -0,0 +1,15 @@
+<?php
+/**
+ * class lmbMacroTrimTag.
+ * @tag trim
+ * @restrict_self_nesting
+ */
+class lmbMacroTrimTag extends lmbMacroTag
+{
+ protected function _generateContent($code)
+ {
+ lmbMacroTextNode :: setTrim(true);
+ parent :: _generateContent($code);
+ lmbMacroTextNode :: setTrim(false);
+ }
+}
Modified: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php 2008-05-11 17:05:42 UTC (rev 7000)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroNospaceTagTest.class.php 2008-05-11 21:03:15 UTC (rev 7001)
@@ -21,5 +21,50 @@
$this->assertEqual($page->render(), " Todd Bob Hey\n Tomm");
}
+
+ function testTrimSpace()
+ {
+ $template = '{{trim}} Bob {{/trim}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $this->assertEqual($page->render(), 'Bob');
+ }
+
+ function testMixTrimAndNoTrim()
+ {
+ $template = ' Todd {{trim}} Bob {{/trim}} Hey';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $this->assertEqual($page->render(), ' Todd Bob Hey');
+ }
+
+ function testSpace()
+ {
+ $template = '{{trim}}{{sp}}Bob{{sp}}{{/trim}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $this->assertEqual($page->render(), ' Bob ');
+ }
+
+ function testNewline()
+ {
+ $template = '{{trim}}{{nl}}Bob{{nl}}{{/trim}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $this->assertEqual($page->render(), "\nBob\n");
+ }
+
+ function testTab()
+ {
+ $template = '{{trim}}{{tab}}Bob{{tab}}{{/trim}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $this->assertEqual($page->render(), "\tBob\t");
+ }
}
More information about the limb-svn
mailing list