[limb-svn] r6796 - in 3.x/trunk/limb/macro: src/tags/core tests/cases/tags/core
svn at limb-project.com
svn at limb-project.com
Tue Feb 12 11:48:22 MSK 2008
Author: serega
Date: 2008-02-12 11:48:22 +0300 (Tue, 12 Feb 2008)
New Revision: 6796
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6796
Added:
3.x/trunk/limb/macro/src/tags/core/apply_into.tag.php
3.x/trunk/limb/macro/src/tags/core/template_slot.tag.php
Modified:
3.x/trunk/limb/macro/src/tags/core/apply.tag.php
3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php
3.x/trunk/limb/macro/src/tags/core/slot.tag.php
3.x/trunk/limb/macro/src/tags/core/template.tag.php
3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroTemplateTagTest.class.php
Log:
-- improved functionality of {{template}}/{{apply}} tags
* "inline" attribute for {{apply}} tag now supported. In this case {{template}} will not wrap his code with method.
* {{template}} tag now generates a unique method for every {{apply}} call without "inline" attribute
* added {{template:slot}} and {{apply:into}} tags. This two tag allows to insert the content of {{apply:into}} tag in some particular {{template:slot}}.
Modified: 3.x/trunk/limb/macro/src/tags/core/apply.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/apply.tag.php 2008-02-11 21:22:42 UTC (rev 6795)
+++ 3.x/trunk/limb/macro/src/tags/core/apply.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -20,8 +20,25 @@
$name = $this->get('template');
$arg_str = $this->attributesIntoArrayString();
+
+ if(!$template_tag_node = $this->findTemplateTagNode())
+ $this->raise('Template tag not found', array('template' => $name));
+
+ $template_tag_node->setCurrentApplyTag($this);
- $code->writePHP('$this->_template'. $name . '(' . $arg_str . ');');
+ if($this->getBool('inline'))
+ $template_tag_node->generateNow($code, $wrap_with_method = false);
+ else
+ {
+ $template_tag_node->generateNow($code);
+ $code->writePHP('$this->' . $template_tag_node->getMethod() . '(' . $arg_str . ');');
+ }
}
+
+ function findTemplateTagNode()
+ {
+ $name = $this->get('template');
+ return $this->findUpChild('template_' . $name);
+ }
}
Added: 3.x/trunk/limb/macro/src/tags/core/apply_into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/apply_into.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/apply_into.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -0,0 +1,20 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbMacroApplyIntoTag.
+ *
+ * @tag apply:into
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroApplyIntoTag extends lmbMacroPassiveTag
+{
+}
+
Modified: 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php 2008-02-11 21:22:42 UTC (rev 6795)
+++ 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -8,7 +8,7 @@
*/
/**
- * class lmbMacroIntoTag.
+ * class lmbMacroInsertIntoTag.
*
* @tag insert:into
* @aliases into, wrap:into, include:into
Modified: 3.x/trunk/limb/macro/src/tags/core/slot.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/slot.tag.php 2008-02-11 21:22:42 UTC (rev 6795)
+++ 3.x/trunk/limb/macro/src/tags/core/slot.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -26,8 +26,6 @@
$code->writePHP('call_user_func_array($this->__slot_handler_' . $slot . ', array(' . $arg_str . '));');
$code->writePHP('}');
- //we need to isolate statically wrapped template variables via method call
- //in case of dynamic call we don't have children, hence the check
if(!$this->getBool('inline'))
{
$args = $code->generateVar();
Modified: 3.x/trunk/limb/macro/src/tags/core/template.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/template.tag.php 2008-02-11 21:22:42 UTC (rev 6795)
+++ 3.x/trunk/limb/macro/src/tags/core/template.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -13,17 +13,47 @@
* @package macro
* @version $Id$
*/
-class lmbMacroTemplateTag extends lmbMacroTag
+class lmbMacroTemplateTag extends lmbMacroPassiveTag
{
- function _generateContent($code)
+ protected $method;
+ protected $current_apply_tag = null;
+
+ function preParse($compiler)
{
- $name = $this->get('name');
+ if($this->has('name'))
+ $this->set('id', 'template_' . $this->get('name'));
- $args = $code->generateVar();
- $code->beginMethod('_template'. $name, array($args . '= array()'));
- $code->writePHP("if($args) extract($args);");
- parent :: _generateContent($code);
- $code->endMethod();
+ parent :: preParse($compiler);
}
+
+ function generateNow($code, $wrap_with_method = true)
+ {
+ if($wrap_with_method)
+ {
+ $args = $code->generateVar();
+ $this->method = '_template' . uniqid();
+ $code->beginMethod($this->getMethod(), array($args . '= array()'));
+ $code->writePHP("if($args) extract($args);");
+ parent :: generateNow($code);
+ $code->endMethod();
+ }
+ else
+ parent :: generateNow($code);
+ }
+
+ function setCurrentApplyTag(lmbMacroApplyTag $apply_tag)
+ {
+ $this->current_apply_tag = $apply_tag;
+ }
+
+ function getCurrentApplyTag()
+ {
+ return $this->current_apply_tag;
+ }
+
+ function getMethod()
+ {
+ return $this->method;
+ }
}
Added: 3.x/trunk/limb/macro/src/tags/core/template_slot.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/template_slot.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/template_slot.tag.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -0,0 +1,33 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbMacroTemplateSlotTag.
+ * Very simple placeholder for {{apply:into}} tag
+ * @tag template:slot
+ * @package macro
+ * @forbid_end_tag
+ * @version $Id$
+ */
+class lmbMacroTemplateSlotTag extends lmbMacroTag
+{
+ protected function _generateContent($code)
+ {
+ $parent_template_tag = $this->findParentByClass('lmbMacroTemplateTag');
+ $apply_tag = $parent_template_tag->getCurrentApplyTag();
+
+ $intos = $apply_tag->findChildrenByClass('lmbMacroApplyIntoTag');
+ foreach($intos as $into)
+ {
+ if($into->get('slot') == $this->getNodeId())
+ $into->generateNow($code);
+ }
+ }
+}
+
Modified: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroTemplateTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroTemplateTagTest.class.php 2008-02-11 21:22:42 UTC (rev 6795)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroTemplateTagTest.class.php 2008-02-12 08:48:22 UTC (rev 6796)
@@ -31,5 +31,42 @@
$out = $macro->render();
$this->assertEqual($out, 'FOOHEYBAR');
}
+
+ function testApplyTemplateInline()
+ {
+ $content = '{{template name="tpl1"}}' .
+ '{$bar}' .
+ '{{/template}}' .
+ '{{template name="tpl2"}}' .
+ '{$foo}{$hey}' .
+ '{{/template}}' .
+ '<?php $hey = "HEY"; $foo = "FOO"; $bar = "BAR"; ?>'.
+ '{{apply template="tpl2" inline="true"/}}' .
+ '{{apply template="tpl1" inline="true"/}}';
+
+ $tpl = $this->_createTemplate($content, 'tree.html');
+
+ $macro = $this->_createMacro($tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'FOOHEYBAR');
+ }
+
+ function testApplyTemplateWithIntoTags()
+ {
+ $content = '{{template name="tpl1"}}' .
+ '{{template:slot id="slotB"/}}{$bar}{{template:slot id="slotA"/}}' .
+ '{{/template}}' .
+ '<?php $hey = "HEY"; ?>'.
+ '{{apply template="tpl1" bar="$hey"}}{{apply:into slot="slotA"}}Hello!{{/apply:into}}{{/apply}}'.
+ '{{apply template="tpl1" bar="AAA"}}{{apply:into slot="slotB"}}Wow!{{/apply:into}}{{/apply}}';
+
+ $tpl = $this->_createTemplate($content, 'tree.html');
+
+ $macro = $this->_createMacro($tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'HEYHello!Wow!AAA');
+ }
}
More information about the limb-svn
mailing list