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

svn at limb-project.com svn at limb-project.com
Thu Apr 24 10:45:07 MSD 2008


Author: serega
Date: 2008-04-24 10:45:07 +0400 (Thu, 24 Apr 2008)
New Revision: 6953
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6953

Added:
   3.x/trunk/limb/macro/src/tags/core/buffer.tag.php
   3.x/trunk/limb/macro/src/tags/core/paste.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroBufferAndPasteTagsTest.class.php
Log:
-- added new {{buffer}} and {{paste}} tags for macro. /limb/macro/tests/cases/tags/core/lmbMacroBufferAndPasteTagsTest.class.php for usage example.

Added: 3.x/trunk/limb/macro/src/tags/core/buffer.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/buffer.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/buffer.tag.php	2008-04-24 06:45:07 UTC (rev 6953)
@@ -0,0 +1,24 @@
+<?php
+/**
+ * class lmbMacroBufferTag.
+ * @tag buffer
+ * @req_attributes into
+ * @restrict_self_nesting
+ */
+class lmbMacroBufferTag extends lmbMacroTag
+{
+  protected function _generateContent($code)
+  {
+    $buffer_var = self :: generatBufferVar($this->get('into'));
+
+    $code->writePHP("ob_start();\n");
+    parent :: _generateContent($code);
+    $code->writePHP("{$buffer_var} = ob_get_contents();\n");
+    $code->writePHP("ob_end_clean();\n");
+  }
+  
+  static function generatBufferVar($buffer_name)
+  {
+    return '$this->'. $buffer_name . '_temp_buffer';
+  }
+}

Added: 3.x/trunk/limb/macro/src/tags/core/paste.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/paste.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/paste.tag.php	2008-04-24 06:45:07 UTC (rev 6953)
@@ -0,0 +1,18 @@
+<?php
+lmb_require('limb/macro/src/tags/core/buffer.tag.php');
+/**
+ * class lmbMacroPasteTag.
+ * @tag paste
+ * @req_attributes from
+ * @forbid_end_tag
+ */
+ 
+class lmbMacroPasteTag extends lmbMacroTag
+{
+  protected function _generateContent($code)
+  {
+    $buffer_var = lmbMacroBufferTag :: generatBufferVar($this->get('from'));
+
+    $code->writePHP("echo {$buffer_var};\n");
+  }
+}

Added: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroBufferAndPasteTagsTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroBufferAndPasteTagsTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroBufferAndPasteTagsTest.class.php	2008-04-24 06:45:07 UTC (rev 6953)
@@ -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
+ */
+
+class lmbMacroBufferAndPasteTagsTest extends lmbBaseMacroTest
+{
+  function testCopyAndPasteFromBuffer()
+  {
+    $template = '{{buffer into="my_buffer"}}F{{/buffer}}N|{{paste from="my_buffer"}}|{{paste from="my_buffer"}}';
+
+    $page = $this->_createMacroTemplate($template, 'tpl.html');
+    
+    $this->assertEqual($page->render(), 'N|F|F');
+  }
+}
+



More information about the limb-svn mailing list