Author: Raymond Bosman Date: 2007-02-02 14:20:33 +0100 (Fri, 02 Feb 2007) New Revision: 4624
Log: - Added caching callbacks. - Added static custom blocks. Added: trunk/Template/tests/regression_tests/custom_blocks/correct/static.in trunk/Template/tests/regression_tests/custom_blocks/correct/static.out Modified: trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php trunk/Template/src/structs/custom_block_definition.php trunk/Template/src/template.php trunk/Template/tests/cache_test.php trunk/Template/tests/custom_blocks/testblocks.php trunk/Template/tests/suite.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 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -586,6 +586,11 @@ $params->value[] = $value->accept($this); } + if( $def->hasCloseTag && $def->isStatic ) + { + throw new ezcTemplateParserException($type->source, $type->startCursor, $type->startCursor, "The *static* CustomBlock cannot have a open and close tag."); + } + if ( $def->hasCloseTag ) { $result = array(); // Will contain an array with AST nodes. @@ -627,7 +632,31 @@ } else { - return new ezcTemplateGenericStatementAstNode( + // If static. + if( $def->isStatic ) + { + $p = array(); + + // Check whether all values are static. + for( $i = 0; $i < sizeof( $params->value ); $i++) + { + if( !($params->value[$i] instanceof ezcTemplateLiteralAstNode ) ) + { + throw new ezcTemplateParserException($type->source, $type->startCursor, $type->startCursor, "The *static* CustomBlock needs static parameters."); + } + + $p[$params->keys[$i]->value] = $params->value[$i]->value; + + } + + // call the method. + $r = call_user_func_array( array($def->class, $def->method), array($p) ); + + // And assign it to the output. + return $this->assignToOutput( new ezcTemplateLiteralAstNode($r) ); + } + + return new ezcTemplateGenericStatementAstNode( new ezcTemplateConcatAssignmentOperatorAstNode( $this->outputVariable->getAst(), new ezcTemplateFunctionCallAstNode( $def->class . "::".$def->method, array( $params ) ) ) ); Modified: trunk/Template/src/structs/custom_block_definition.php =================================================================== --- trunk/Template/src/structs/custom_block_definition.php 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/src/structs/custom_block_definition.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -109,5 +109,8 @@ * @var array(string) */ public $requiredParameters = array(); + + + public $isStatic = false; } ?> Modified: trunk/Template/src/template.php =================================================================== --- trunk/Template/src/template.php 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/src/template.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -341,13 +341,13 @@ { $this->configuration->cacheManager->includeTemplate( $this->properties["stream"]); } - } // execute compiled code here throw new ezcTemplateInternalException( "Compilation or execution failed" ); } + /** * Creates the directory $path if it does not exist. * Modified: trunk/Template/tests/cache_test.php =================================================================== --- trunk/Template/tests/cache_test.php 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/tests/cache_test.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -138,16 +138,15 @@ { $t = new ezcTemplate( ); $t->send->number = 22; - $t->process( "cache_dynamic_var_declare.tpl"); + $out = $t->process( "cache_dynamic_var_declare.tpl"); - /* - $this->assertEquals( "\n[2]\n[Bernard Black]\n[Nr 2]\n[Bernard Black]\n[Nr 3]\n[4]\n[Bernard Black]\n", $out ); + $this->assertEquals( "\n[22]\n6\n", $out); $t->send->user = new TestUser( "Guybrush", "Threepwood", 10 ); $out = $t->process( "cache_dynamic_advanced.tpl"); - $this->assertEquals( "\n[2]\n[Bernard Black]\n[Nr 2]\n[Guybrush Threepwood]\n[Nr 3]\n[13]\n[Guybrush Threepwood]\n", $out ); - */ + $this->assertEquals( "\n[2]\n[Guybrush Threepwood]\n[Nr 2]\n[Guybrush Threepwood]\n[Nr 3]\n[13]\n[Guybrush Threepwood]\n", $out ); + } // Declare a variable under the first dynamic block. Modified: trunk/Template/tests/custom_blocks/testblocks.php =================================================================== --- trunk/Template/tests/custom_blocks/testblocks.php 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/tests/custom_blocks/testblocks.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -172,6 +172,86 @@ $def->requiredParameters = array(); $def->optionalParameters = array("bla"); return $def; + +//////////////////////////// + + case "static_opt_parameter": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = ""; + $def->requiredParameters = array(); + $def->optionalParameters = array("optional"); + $def->isStatic = true; + return $def; + + case "static_req_parameter": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = ""; + $def->requiredParameters = array("required"); + $def->optionalParameters = array(); + $def->isStatic = true; + return $def; + + case "static_req_opt_parameter": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = ""; + $def->requiredParameters = array("required"); + $def->optionalParameters = array("optional"); + $def->isStatic = true; + return $def; + + case "static_req_startexpression": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = "start_expression"; + $def->requiredParameters = array("start_expression"); + $def->optionalParameters = array(); + $def->isStatic = true; + return $def; + + case "static_opt_startexpression": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = "start_expression"; + $def->requiredParameters = array(); + $def->optionalParameters = array("start_expression"); + $def->isStatic = true; + return $def; + + case "static_incorrect_startexpression": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = "start_expresssion"; + $def->requiredParameters = array(); + $def->optionalParameters = array("bla"); + $def->isStatic = true; + return $def; + + + case "static_req_opt_parameter": + $def = new ezcTemplateCustomBlockDefinition(); + $def->class = __CLASS__; + $def->method = "reflectParameters"; + $def->hasCloseTag = false; + $def->startExpressionName = ""; + $def->requiredParameters = array("required"); + $def->optionalParameters = array("optional"); + $def->isStatic = true; + return $def; } } Added: trunk/Template/tests/regression_tests/custom_blocks/correct/static.in =================================================================== --- trunk/Template/tests/regression_tests/custom_blocks/correct/static.in 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/tests/regression_tests/custom_blocks/correct/static.in 2007-02-02 13:20:33 UTC (rev 4624) @@ -0,0 +1,15 @@ +{static_opt_parameter} + +{static_opt_parameter optional="bla"} + +{static_req_parameter required="haha"} + +{static_req_opt_parameter required="haha"} + +{static_req_opt_parameter required="haha" optional="bla"} + +{static_req_startexpression "Bla"} + +{static_opt_startexpression "Bla"} + +{static_opt_startexpression} Property changes on: trunk/Template/tests/regression_tests/custom_blocks/correct/static.in ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/Template/tests/regression_tests/custom_blocks/correct/static.out =================================================================== --- trunk/Template/tests/regression_tests/custom_blocks/correct/static.out 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/tests/regression_tests/custom_blocks/correct/static.out 2007-02-02 13:20:33 UTC (rev 4624) @@ -0,0 +1,38 @@ +Array +( +) + +Array +( + [optional] => bla +) + +Array +( + [required] => haha +) + +Array +( + [required] => haha +) + +Array +( + [required] => haha + [optional] => bla +) + +Array +( + [start_expression] => Bla +) + +Array +( + [start_expression] => Bla +) + +Array +( +) Property changes on: trunk/Template/tests/regression_tests/custom_blocks/correct/static.out ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/Template/tests/suite.php =================================================================== --- trunk/Template/tests/suite.php 2007-02-02 10:49:36 UTC (rev 4623) +++ trunk/Template/tests/suite.php 2007-02-02 13:20:33 UTC (rev 4624) @@ -50,8 +50,7 @@ $this->setName( "Template" ); $this->addTest( ezcTemplateRegressionTest::suite() ); - // Caching is disabled. Check also parsers/source_to_tst/cache.php - //$this->addTest( ezcTemplateCacheTest::suite() ); + $this->addTest( ezcTemplateCacheTest::suite() ); $this->addTest( ezcTemplateParserTest::suite() ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components