Author: Raymond Bosman
Date: 2006-08-31 10:55:07 +0200 (Thu, 31 Aug 2006)
New Revision: 3421
Log:
- Fixed a bug that foreach was not processed in a custom block. Added a test.
Added:
trunk/Template/tests/custom_blocks/cblock.php
trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.in
trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.out
Modified:
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
trunk/Template/tests/regression_test.php
Modified:
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
===================================================================
---
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
2006-08-30 12:43:07 UTC (rev 3420)
+++
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
2006-08-31 08:55:07 UTC (rev 3421)
@@ -193,20 +193,42 @@
if( $def->hasCloseTag )
{
+ $result = array(); // Will contain an array with AST nodes.
+
+ // Write to the custom block output.
$this->outputVariable->push( $this->getUniqueVariableName(
"_ezcTemplate_custom" ) );
- $iniCustom = $this->outputVariable->getInitializationAst();
- $astNode = $type->elements[0]->accept( $this );
+ // Set the output to "".
+ $result[] = $this->outputVariable->getInitializationAst();
+ // execute all the 'children' in the custom block.
+ foreach( $type->elements as $element )
+ {
+ $r = $element->accept( $this );
+ // It could be an array :-(. Should change this one time to a
pseudo node.
+
+ if( is_array( $r ) )
+ {
+ foreach ($r as $a )
+ {
+ $result[] = $a;
+ }
+ }
+ else
+ {
+ $result[] = $r;
+ }
+ }
+
$customBlockOutput = $this->outputVariable->getAst();
$this->outputVariable->pop();
- $b = new ezcTemplateGenericStatementAstNode(
+ $result[] = new ezcTemplateGenericStatementAstNode(
new ezcTemplateConcatAssignmentOperatorAstNode(
$this->outputVariable->getAst(),
new ezcTemplateFunctionCallAstNode( $def->class .
"::".$def->method,
array( $params, $customBlockOutput ) ) ) );
- return array( $iniCustom, $astNode, $b );
+ return $result;
}
else
{
Added: trunk/Template/tests/custom_blocks/cblock.php
===================================================================
--- trunk/Template/tests/custom_blocks/cblock.php 2006-08-30 12:43:07 UTC
(rev 3420)
+++ trunk/Template/tests/custom_blocks/cblock.php 2006-08-31 08:55:07 UTC
(rev 3421)
@@ -0,0 +1,31 @@
+<?php
+
+class cblockTemplateExtension implements ezcTemplateCustomBlock
+{
+ public static function getCustomBlockDefinition( $name )
+ {
+ switch( $name )
+ {
+ case 'cblock':
+ {
+ $def = new ezcTemplateCustomBlockDefinition();
+
+ $def->class = __CLASS__;
+ $def->method = "cblock";
+ $def->hasCloseTag = true;
+ $def->requiredParameters = array();
+
+ return $def;
+ } break;
+ }
+
+ return null;
+ }
+
+ public static function cblock( $parameters, $code )
+ {
+ return print_r( $code, true );
+ }
+}
+
+?>
Property changes on: trunk/Template/tests/custom_blocks/cblock.php
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Template/tests/regression_test.php
===================================================================
--- trunk/Template/tests/regression_test.php 2006-08-30 12:43:07 UTC (rev
3420)
+++ trunk/Template/tests/regression_test.php 2006-08-31 08:55:07 UTC (rev
3421)
@@ -15,6 +15,8 @@
include_once ("custom_blocks/testblocks.php");
include_once ("custom_blocks/brainfuck.php");
include_once ("custom_blocks/links.php");
+include_once ("custom_blocks/cblock.php");
+
class ezcTemplateRegressionTest extends ezcTestCase
{
public $requestRegeneration = true;
@@ -105,6 +107,7 @@
$template->configuration->addExtension( "BrainFuck" );
$template->configuration->addExtension( "TestBlocks" );
$template->configuration->addExtension( "LinksCustomBlock" );
+ $template->configuration->addExtension( "cblockTemplateExtension"
);
if( preg_match("#^(\w+)@(\w+)\..*$#", $base, $match ) )
{
Added: trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.in
===================================================================
--- trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.in
2006-08-30 12:43:07 UTC (rev 3420)
+++ trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.in
2006-08-31 08:55:07 UTC (rev 3421)
@@ -0,0 +1,9 @@
+{cblock}
+
+ Hello
+
+ {foreach array(1,2,3) as $index}
+ {$index}
+ {/foreach}
+
+{/cblock}
Property changes on:
trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.in
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.out
===================================================================
--- trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.out
2006-08-30 12:43:07 UTC (rev 3420)
+++ trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.out
2006-08-31 08:55:07 UTC (rev 3421)
@@ -0,0 +1,7 @@
+
+Hello
+
+1
+2
+3
+
Property changes on:
trunk/Template/tests/regression_tests/custom_blocks/correct/foreach.out
___________________________________________________________________
Name: svn:eol-style
+ native
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components