[limb-svn] r6789 - in 3.x/trunk/limb/macro: src/compiler src/tags/core tests/cases/compiler tests/cases/tags/core
svn at limb-project.com
svn at limb-project.com
Mon Feb 11 13:07:22 MSK 2008
Author: serega
Date: 2008-02-11 13:07:21 +0300 (Mon, 11 Feb 2008)
New Revision: 6789
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6789
Added:
3.x/trunk/limb/macro/src/tags/core/include_into.tag.php
3.x/trunk/limb/macro/src/tags/core/wrap_into.tag.php
Removed:
3.x/trunk/limb/macro/src/tags/core/into.tag.php
Modified:
3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php
3.x/trunk/limb/macro/src/compiler/lmbMacroNode.class.php
3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php
3.x/trunk/limb/macro/src/compiler/lmbMacroTemplateExecutor.class.php
3.x/trunk/limb/macro/src/tags/core/include.tag.php
3.x/trunk/limb/macro/src/tags/core/slot.tag.php
3.x/trunk/limb/macro/src/tags/core/wrap.tag.php
3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php
3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroIncludeTagTest.class.php
3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroWrapTagTest.class.php
Log:
-- improved version of wrapping and including functionality in MACRO:
* {{slot}} tag now supports "inline" attribute for static cases. Using "inline" means not to wrap slot into separate method in compiled template
* {{slot}} tag now supports passing variables both in dynamic and static cases.
* {{include}} tag also supports "inline"" attribute for static cases.
* {{into}} -> {{wrap:into}} ({{into}} is now an alias of {{wrap:into}}
* {{include:into}} tag added. This tag has the same functionality as {{wrap:into}} but seaches nearest {{include}} parent tag to determine if it's static or dynamic case.
* {{include}} tag now requires a closing tag.
-- fixed output expression for cases like {$#object.item->func()}
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -41,18 +41,26 @@
//$var = $items[0];
$expr .= $var . ' = ' . $items[0] . ';' . "\n";
$code->writePHP($this->tmp . "='';\n");
-
+
for($i=1; $i < sizeof($items); $i++)
{
$item = $items[$i];
- $expr .= "if((is_array({$var}) || ({$var} instanceof ArrayAccess)) && isset({$var}['{$item}'])) " .
- "{ {$this->tmp} = {$var}['{$item}'];\n";
+ if(strpos($item, '->') === false)
+ {
+ $expr .= "if((is_array({$var}) || ({$var} instanceof ArrayAccess)) && isset({$var}['{$item}'])) " .
+ "{ {$this->tmp} = {$var}['{$item}'];\n";
+ }
+ else
+ $expr .= "{$this->tmp} = {$var}{$item};\n";
$var = $this->tmp;
}
//closing brackets
for($i=1; $i < sizeof($items); $i++)
- $expr .= "}else{ {$this->tmp} = '';}\n";
+ {
+ if(strpos($items[$i], '->') === false)
+ $expr .= "}else{ {$this->tmp} = '';}\n";
+ }
$code->writePHP($expr);
}
@@ -66,12 +74,27 @@
$path_items = array();
$in_function = false;
-
+
$item = '';
foreach($tokens as $token)
{
- if(is_scalar($token))
+ if(!is_scalar($token))
{
+ if($token[1] == '->' && !$in_function)
+ {
+ if($item != '$this') // $this-> is a special case
+ {
+ $path_items[] = $item;
+ $item = '->';
+ }
+ else
+ $item .= '->';
+ continue;
+ }
+ $item .= $token[1];
+ }
+ else
+ {
if($token == '(')
$in_function = true;
if($token == ')')
@@ -82,11 +105,8 @@
$item = '';
continue;
}
-
$item .= $token;
}
- else
- $item .= $token[1];
}
$path_items[] = $item;
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroNode.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroNode.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroNode.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -178,12 +178,10 @@
{
if(is_a($child, $class))
$ret[] = $child;
- else
- {
- $more_children = $child->findChildrenByClass($class);
- if(count($more_children))
- $ret = array_merge($ret, $more_children);
- }
+
+ $more_children = $child->findChildrenByClass($class);
+ if(count($more_children))
+ $ret = array_merge($ret, $more_children);
}
return $ret;
}
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -231,7 +231,7 @@
$vals = array();
foreach($this->attributes as $k => $attribute)
{
- $keys[] = '$' . $k;
+ $keys[] = '$' . $attribute->getName();
$vals[] = $this->getEscaped($k);
}
return array($keys, $vals);
@@ -242,10 +242,11 @@
$arr = array();
foreach($this->attributes as $k => $attribute)
{
- if(in_array($k, $skip))
+ $name = $attribute->getName();
+ if(in_array($name, $skip))
continue;
- $arr[$k] = $this->getEscaped($k);
+ $arr[$name] = $this->getEscaped($k);
}
return $arr;
}
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroTemplateExecutor.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroTemplateExecutor.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroTemplateExecutor.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -62,10 +62,12 @@
extract($args);
}
- function includeTemplate($file, $vars = array())
+ function includeTemplate($file, $vars = array(), $slots_handlers = array())
{
$template = new lmbMacroTemplate($file, $this->__config);
$template->setVars(get_object_vars($this));//global template vars
+ foreach($slots_handlers as $name => $handler)
+ $template->set('__slot_handler_' . $name, $handler);
echo $template->render($vars);//local template vars
}
Modified: 3.x/trunk/limb/macro/src/tags/core/include.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/include.tag.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/tags/core/include.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -12,7 +12,6 @@
*
* @tag include
* @req_attributes file
- * @forbid_end_tag
* @package macro
* @version $Id$
*/
@@ -22,20 +21,20 @@
{
parent :: preParse($compiler);
- if(!$this->_isDynamic())
+ if(!$this->isDynamicInclude())
{
$compiler->parseTemplate($this->get('file'), $this);
}
}
- function _isDynamic()
+ function isDynamicInclude()
{
return $this->isDynamic('file');
}
protected function _generateContent($code)
{
- if($this->_isDynamic())
+ if($this->isDynamicInclude())
$this->_generateDynamicaly($code);
else
$this->_generateStaticaly($code);
@@ -43,22 +42,53 @@
function _generateDynamicaly($code)
{
+ $handlers_str = 'array(';
+ $methods = array();
+
+ //collecting {{into}} tags
+ if($intos = $this->_collectIntos())
+ {
+ foreach($intos as $into)
+ {
+ $args = $code->generateVar();
+ $methods[$into->get('slot')] = $code->beginMethod('__slotHandler'. uniqid(), array($args . '= array()'));
+ $code->writePHP("if($args) extract($args);");
+ $into->generateNow($code);
+ $code->endMethod();
+ }
+ }
+
+ foreach($methods as $slot => $method)
+ $handlers_str .= '"' . $slot . '"' . ' => array($this, "' . $method . '"),';
+
+ $handlers_str .= ')';
+
$arg_str = $this->attributesIntoArrayString();
- $code->writePHP('$this->includeTemplate(' . $this->get('file') . ',' . $arg_str . ');');
+ $code->writePHP('$this->includeTemplate(' . $this->get('file') . ', ' . $arg_str . ','. $handlers_str . ');');
}
+
+ protected function _collectIntos()
+ {
+ return $this->findChildrenByClass('lmbMacroIncludeIntoTag');
+ }
function _generateStaticaly($code)
{
- static $counter = 1;
-
- list($keys, $vals) = $this->attributesIntoArgs();
-
- $method = $code->beginMethod('__staticInclude' . ($counter++), $keys);
- parent :: _generateContent($code);
- $code->endMethod();
-
- $code->writePHP('$this->' . $method . '(' . implode(', ', $vals) . ');');
+ if($this->getBool('inline'))
+ parent :: _generateContent($code);
+ else
+ {
+ static $counter = 1;
+
+ list($keys, $vals) = $this->attributesIntoArgs();
+
+ $method = $code->beginMethod('__staticInclude' . ($counter++), $keys);
+ parent :: _generateContent($code);
+ $code->endMethod();
+
+ $code->writePHP('$this->' . $method . '(' . implode(', ', $vals) . ');');
+ }
}
}
Added: 3.x/trunk/limb/macro/src/tags/core/include_into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/include_into.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/include_into.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -0,0 +1,67 @@
+<?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 lmbMacroIntoTag.
+ *
+ * @tag include:into
+ * @aliases include_into
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroIncludeIntoTag extends lmbMacroTag
+{
+ protected $is_dynamic;
+
+ function preParse($compiler)
+ {
+ parent :: preParse($compiler);
+
+ if($parent = $this->findParentByClass('lmbMacroIncludeTag'))
+ $this->is_dynamic = $parent->isDynamicInclude();
+ else
+ {
+ $parent = $this->findRoot();
+ $this->is_dynamic = false;
+ }
+
+ if(!$this->is_dynamic)
+ {
+ $tree_builder = $compiler->getTreeBuilder();
+ $this->_insert($parent, $tree_builder, $this->get('slot'));
+ }
+ }
+
+ function _insert($parent, $tree_builder, $point)
+ {
+ $insertionPoint = $parent->findChild($point);
+ if(empty($insertionPoint))
+ {
+ $params = array('slot' => $point);
+ $params['parent_wrap_tag_file'] = $parent->getTemplateFile();
+ $params['parent_wrap_tag_line'] = $parent->getTemplateLine();
+
+ $this->raise('Wrap slot not found', $params);
+ }
+
+ $tree_builder->pushCursor($insertionPoint, $this->location);
+ }
+
+ function generate($code)
+ {
+ if(!$this->is_dynamic)
+ parent :: generate($code);
+ }
+
+ function generateNow($code)
+ {
+ parent :: generate($code);
+ }
+}
+
Deleted: 3.x/trunk/limb/macro/src/tags/core/into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/into.tag.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/tags/core/into.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -1,58 +0,0 @@
-<?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 lmbMacroIntoTag.
- *
- * @tag into
- * @package macro
- * @version $Id$
- */
-class lmbMacroIntoTag extends lmbMacroTag
-{
- function preParse($compiler)
- {
- parent :: preParse($compiler);
-
- if($wrapper = $this->findParentByClass('lmbMacroWrapTag'))
- {
- $is_dynamic = $wrapper->isDynamicWrap();
- }
- else
- {
- $wrapper = $this->findRoot();
- $is_dynamic = false;
- }
-
- if(!$is_dynamic)
- {
- $tree_builder = $compiler->getTreeBuilder();
- $this->_insert($wrapper, $tree_builder, $this->get('slot'));
- }
- }
-
- function _insert($wrapper, $tree_builder, $point)
- {
- $insertionPoint = $wrapper->findChild($point);
- if(empty($insertionPoint))
- {
- $params = array('slot' => $point);
- if($wrapper !== $this)
- {
- $params['parent_wrap_tag_file'] = $wrapper->getTemplateFile();
- $params['parent_wrap_tag_line'] = $wrapper->getTemplateLine();
- }
-
- $this->raise('Wrap slot not found', $params);
- }
-
- $tree_builder->pushCursor($insertionPoint, $this->location);
- }
-}
-
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 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/tags/core/slot.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -12,6 +12,7 @@
*
* @tag slot
* @package macro
+ * @forbid_end_tag
* @version $Id$
*/
class lmbMacroSlotTag extends lmbMacroTag
@@ -21,18 +22,27 @@
$slot = $this->getNodeId();
//calling slot handler in case of dynamic wrapping
$code->writePHP('if(isset($this->__slot_handler_' . $slot . ')) {');
- $code->writePHP('call_user_func_array($this->__slot_handler_' . $slot . ', array());');
+ $arg_str = $this->attributesIntoArrayString($skip = array('id', 'inline'));
+ $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->children)
+ if(!$this->getBool('inline'))
{
- $method = $code->beginMethod('__slotHandler' . uniqid());
+ $args = $code->generateVar();
+ $method = $code->beginMethod('__slotHandler' . uniqid(), array($args . '= array()'));
+
+ $code->writePHP("if($args) extract($args);");
+
parent :: _generateContent($code);
+
$code->endMethod();
- $code->writePHP('$this->' . $method . '()');
+ //$arg_str = $this->attributesIntoArrayString($skip = array('id', 'inline'));
+ $code->writePHP('$this->' . $method . '(' . $arg_str . ');');
}
+ else
+ parent :: _generateContent($code);
}
}
Modified: 3.x/trunk/limb/macro/src/tags/core/wrap.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/wrap.tag.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/src/tags/core/wrap.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -68,7 +68,7 @@
protected function _collectIntos()
{
- return $this->findImmediateChildrenByClass('lmbMacroIntoTag');
+ return $this->findChildrenByClass('lmbMacroWrapIntoTag');
}
protected function _generateContent($code)
@@ -83,14 +83,18 @@
{
foreach($intos as $into)
{
- $methods[$into->get('slot')] = $code->beginMethod('__slotHandler'. uniqid());
- $into->generate($code);
+ $args = $code->generateVar();
+ $methods[$into->get('slot')] = $code->beginMethod('__slotHandler'. uniqid(), array($args . '= array()'));
+ $code->writePHP("if($args) extract($args);");
+ $into->generateNow($code);
$code->endMethod();
}
}
else
{
- $methods[$this->get('into')] = $code->beginMethod('__slotHandler'. uniqid());
+ $args = $code->generateVar();
+ $methods[$this->get('into')] = $code->beginMethod('__slotHandler'. uniqid(), array($args . '= array()'));
+ $code->writePHP("if($args) extract($args);");
parent :: _generateContent($code);
$code->endMethod();
}
Copied: 3.x/trunk/limb/macro/src/tags/core/wrap_into.tag.php (from rev 6787, 3.x/trunk/limb/macro/src/tags/core/into.tag.php)
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/wrap_into.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/core/wrap_into.tag.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -0,0 +1,72 @@
+<?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 lmbMacroIntoTag.
+ *
+ * @tag wrap:into
+ * @aliases into, wrap_into
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroWrapIntoTag extends lmbMacroTag
+{
+ protected $is_dynamic;
+
+ function preParse($compiler)
+ {
+ parent :: preParse($compiler);
+
+ if($wrapper = $this->findParentByClass('lmbMacroWrapTag'))
+ {
+ $this->is_dynamic = $wrapper->isDynamicWrap();
+ }
+ else
+ {
+ $wrapper = $this->findRoot();
+ $this->is_dynamic = false;
+ }
+
+ if(!$this->is_dynamic)
+ {
+ $tree_builder = $compiler->getTreeBuilder();
+ $this->_insert($wrapper, $tree_builder, $this->get('slot'));
+ }
+ }
+
+ function _insert($wrapper, $tree_builder, $point)
+ {
+ $insertionPoint = $wrapper->findChild($point);
+ if(empty($insertionPoint))
+ {
+ $params = array('slot' => $point);
+ if($wrapper !== $this)
+ {
+ $params['parent_wrap_tag_file'] = $wrapper->getTemplateFile();
+ $params['parent_wrap_tag_line'] = $wrapper->getTemplateLine();
+ }
+
+ $this->raise('Wrap slot not found', $params);
+ }
+
+ $tree_builder->pushCursor($insertionPoint, $this->location);
+ }
+
+ function generate($code)
+ {
+ if(!$this->is_dynamic)
+ parent :: generate($code);
+ }
+
+ function generateNow($code)
+ {
+ parent :: generate($code);
+ }
+}
+
Modified: 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -158,6 +158,16 @@
$this->assertEqual($out, '<h1>aaa - 10</h1>');
}
+ function testFunctionCallAfterPathBasedChunkWithParamsInOutputExpression()
+ {
+ $code = '<h1>{$#bar.extra->func2("aaa", $#foo)}</h1>';
+ $tpl = $this->_createMacroTemplate($code, 'tpl.html');
+ $tpl->set('bar', array('extra' => new lmbMacroOutputExpressionTestClass()));
+ $tpl->set('foo', 10);
+ $out = $tpl->render();
+ $this->assertEqual($out, '<h1>aaa - 10</h1>');
+ }
+
function testPathAfterFunctionCallInOutputExpression()
{
$code = '<h1>{$#bar->func3().zoo}</h1>';
Modified: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroIncludeTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroIncludeTagTest.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroIncludeTagTest.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -53,6 +53,20 @@
$this->assertEqual($out, '<body><p>Numbers: 1 2</p></body>');
}
+ function testStaticInlineInclude()
+ {
+ $bar = '<body><?php $var2=2;?>{{include file="foo.html" inline="true"/}}</body>';
+ $foo = '<p>Number: <?php echo $var2;?></p>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<body><p>Number: 2</p></body>');
+ }
+
function testStaticIncludeMixLocalAndTemplateVariables()
{
$bar = '<body><?php $var2=2;?>{{include file="foo.html" var1="1" var2="$var2"/}}</body>';
@@ -112,6 +126,45 @@
$out = $macro->render();
$this->assertEqual($out, '<body><p>Hello, Fred Atkins!</p></body>');
- }
+ }
+
+ function testStaticIncludeWithChildIntoTagsAndVariables()
+ {
+ $bar = '<body><?php $var2=2;?>'.
+ '{{include file="foo.html" var1="1" var2="$var2"}}'.
+ '{{include:into slot="slot1"}}<b><?php echo $varA;?></b>{{/include:into}}'.
+ '{{include:into slot="slot2"}}<u><?php echo $varB;?></u>{{/include:into}}'.
+ '{{/include}}'.
+ '</body>';
+ $foo = '<p>Numbers: {{slot id="slot1" varA="$var1"/}} {{slot id="slot2" varB="$var2"/}}</p>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<body><p>Numbers: <b>1</b> <u>2</u></p></body>');
+ }
+
+ function testDynamicIncludeWithChildIntoTagsAndVariables()
+ {
+ $bar = '<body><?php $var2=2;?>'.
+ '{{include file="$#included" var1="1" var2="$var2"}}'.
+ '{{include:into slot="slot1"}}<b><?php echo $varA;?></b>{{/include:into}}'.
+ '{{include:into slot="slot2"}}<u><?php echo $varB;?></u>{{/include:into}}'.
+ '{{/include}}'.
+ '</body>';
+ $foo = '<p>Numbers: {{slot id="slot1" varA="$var1"/}} {{slot id="slot2" varB="$var2"/}}</p>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+ $macro->set('included', 'foo.html');
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<body><p>Numbers: <b>1</b> <u>2</u></p></body>');
+ }
}
Modified: 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroWrapTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroWrapTagTest.class.php 2008-02-11 07:34:43 UTC (rev 6788)
+++ 3.x/trunk/limb/macro/tests/cases/tags/core/lmbMacroWrapTagTest.class.php 2008-02-11 10:07:21 UTC (rev 6789)
@@ -229,7 +229,7 @@
function testMultiStaticWrapFromIncludedFile()
{
$child = '{{into slot="slot1"}}Bob{{/into}}{{into slot="slot2"}}Thorton{{/into}}';
- $main = '{{wrap with="base.html"}}{{include file="child.html"}}{{/wrap}}';
+ $main = '{{wrap with="base.html"}}{{include file="child.html"/}}{{/wrap}}';
$base = '<p>Hello, {{slot id="slot2"/}} {{slot id="slot1"/}}</p>';
$child_tpl = $this->_createTemplate($child, 'child.html');
@@ -240,6 +240,62 @@
$out = $macro->render();
$this->assertEqual($out, '<p>Hello, Thorton Bob</p>');
- }
+ }
+
+ function testPassVariablesIntoLocalContextOfSlotTag()
+ {
+ $bar = '{{wrap with="foo.html" into="slot1"}}<?php echo $foo;?>{{/wrap}}';
+ $foo = '<?php $foo = "Bob";?>{{slot id="slot1" foo="$foo"/}}';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'Bob');
+ }
+
+ function testSlotWithInlineAttributeDoesNotCreateAMethodAround()
+ {
+ $bar = '{{wrap with="foo.html" into="slot1"}}<?php $foo = "Tedd";?>{{/wrap}}';
+ $foo = '<?php $foo = "Bob";?>{{slot id="slot1" inline="true"/}}<?php echo $foo;?>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'Tedd');
+ }
+
+ function testMixDynamicWrapWithStaticIncludeWithChildIntoTags()
+ {
+ $layout = '<body>Main: {{slot id="slot_main"/}} Extra: {{slot id="slot_extra"/}}</body>';
+
+ $bar = '{{wrap with="$#layout"}}'.
+ '{{wrap:into slot="slot_main"}}<?php $var2=2;?>'.
+ '{{include file="foo.html" var1="1" var2="$var2"}}'.
+ '{{include:into slot="slot1"}}<b><?php echo $varA;?></b>{{/include:into}}'.
+ '{{include:into slot="slot2"}}<u><?php echo $varB;?></u>{{/include:into}}'.
+ '{{/include}}'.
+ '{{/wrap:into}}'.
+ '{{/wrap}}';
+
+ $foo = '<p>Numbers: {{slot id="slot1" varA="$var1"/}} {{slot id="slot2" varB="$var2"/}}</p> '.
+ '{{wrap:into slot="slot_extra"}}Wow!{{/wrap:into}}'; // !!!Note this wrap:into tag
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+ $layout_tpl = $this->_createTemplate($layout, 'layout.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+ $macro->set('layout', 'layout.html');
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<body>Main: <p>Numbers: <b>1</b> <u>2</u></p> Extra: Wow!</body>');
+ }
+
}
More information about the limb-svn
mailing list