Author: rb
Date: Thu Aug 2 14:30:27 2007
New Revision: 5807
Log:
- Made the TemplateObject available in CustomBlocks. Thanks to Felix Weis for
the patch.
Added:
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.in
(with props)
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.out
(with props)
Modified:
trunk/Template/ChangeLog
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
trunk/Template/src/structs/custom_block_definition.php
trunk/Template/src/structs/custom_function_definition.php
trunk/Template/tests/custom_blocks/testblocks.php
Modified: trunk/Template/ChangeLog
==============================================================================
--- trunk/Template/ChangeLog [iso-8859-1] (original)
+++ trunk/Template/ChangeLog [iso-8859-1] Thu Aug 2 14:30:27 2007
@@ -1,3 +1,6 @@
+- Made the TemplateObject available in CustomBlocks. Thanks to Felix Weis for
+ the patch.
+
1.2 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
[iso-8859-1] (original)
+++
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
[iso-8859-1] Thu Aug 2 14:30:27 2007
@@ -679,10 +679,16 @@
$customBlockOutput = $this->outputVariable->getAst();
$this->outputVariable->pop();
+ $functionParameters = array( $params, $customBlockOutput );
+ if ( isset($def->sendTemplateObject) && $def->sendTemplateObject )
+ {
+ array_unshift ( $functionParameters, new
ezcTemplateVariableAstNode("this->template"));
+ }
+
$result[] = new ezcTemplateGenericStatementAstNode(
new ezcTemplateConcatAssignmentOperatorAstNode(
$this->outputVariable->getAst(),
new ezcTemplateFunctionCallAstNode( $class . $def->method,
- array( $params, $customBlockOutput ) ) ) );
+ $functionParameters ) ) );
return $result;
}
@@ -718,11 +724,18 @@
// And assign it to the output.
return $this->assignToOutput( new
ezcTemplateLiteralAstNode($r) );
}
+
+
+ $functionParameters = array( $params );
+ if ( isset($def->sendTemplateObject) && $def->sendTemplateObject )
+ {
+ array_unshift ( $functionParameters, new
ezcTemplateVariableAstNode("this->template"));
+ }
return new ezcTemplateGenericStatementAstNode(
new ezcTemplateConcatAssignmentOperatorAstNode(
$this->outputVariable->getAst(),
new ezcTemplateFunctionCallAstNode( $class .$def->method,
- array( $params ) ) ) );
+ $functionParameters ) ) );
}
}
Modified: trunk/Template/src/structs/custom_block_definition.php
==============================================================================
--- trunk/Template/src/structs/custom_block_definition.php [iso-8859-1]
(original)
+++ trunk/Template/src/structs/custom_block_definition.php [iso-8859-1] Thu Aug
2 14:30:27 2007
@@ -113,5 +113,13 @@
public $isStatic = false;
+
+ /**
+ * Whether or not the Template object is available in the custom block.
+ *
+ * @var bool
+ */
+ public $sendTemplateObject = false;
+
}
?>
Modified: trunk/Template/src/structs/custom_function_definition.php
==============================================================================
--- trunk/Template/src/structs/custom_function_definition.php [iso-8859-1]
(original)
+++ trunk/Template/src/structs/custom_function_definition.php [iso-8859-1] Thu
Aug 2 14:30:27 2007
@@ -84,9 +84,10 @@
*/
public $parameters = array();
-
/**
+ * Whether or not the Template object is available in the custom function.
*
+ * @var bool
*/
public $sendTemplateObject = false;
}
Modified: trunk/Template/tests/custom_blocks/testblocks.php
==============================================================================
--- trunk/Template/tests/custom_blocks/testblocks.php [iso-8859-1] (original)
+++ trunk/Template/tests/custom_blocks/testblocks.php [iso-8859-1] Thu Aug 2
14:30:27 2007
@@ -345,6 +345,27 @@
$def->hasCloseTag = true;
$def->requiredParameters = array("variable");
return $def;
+
+
+ case "template_object_no_close":
+ $def = new ezcTemplateCustomBlockDefinition();
+ $def->class = __CLASS__;
+ $def->method = "templateObject";
+ $def->hasCloseTag = false;
+ $def->requiredParameters = array("required");
+ $def->sendTemplateObject = true;
+ return $def;
+
+
+ case "template_object_close":
+ $def = new ezcTemplateCustomBlockDefinition();
+ $def->class = __CLASS__;
+ $def->method = "templateObject";
+ $def->hasCloseTag = true;
+ $def->requiredParameters = array("required");
+ $def->sendTemplateObject = true;
+ return $def;
+
}
}
@@ -360,6 +381,14 @@
var_dump($source);
}
+
+ public static function templateObject( $template, $parameters, $source =
null)
+ {
+ $out = get_class($template->usedConfiguration) . "\n";
+ $out .= print_r( $parameters, true ) . "\n";
+ $out .= $source;
+ return $out;
+ }
}
Added:
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.in
==============================================================================
---
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.in
(added)
+++
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.in
[iso-8859-1] Thu Aug 2 14:30:27 2007
@@ -1,0 +1,6 @@
+{template_object_no_close required="hello"}
+
+
+{template_object_close required="world"}
+Hi
+{/template_object_close}
Propchange:
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.in
------------------------------------------------------------------------------
svn:eol-style = native
Added:
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.out
==============================================================================
---
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.out
(added)
+++
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.out
[iso-8859-1] Thu Aug 2 14:30:27 2007
@@ -1,0 +1,15 @@
+ezcTemplateConfiguration
+Array
+(
+ [required] => hello
+)
+
+
+
+ezcTemplateConfiguration
+Array
+(
+ [required] => world
+)
+
+Hi
Propchange:
trunk/Template/tests/regression_tests/custom_blocks/correct/template_object.out
------------------------------------------------------------------------------
svn:eol-style = native
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components