added support for macro name in the endmacro tag

This commit is contained in:
Fabien Potencier
2011-02-17 13:36:40 +01:00
parent c08ed75c18
commit c0945a255d
3 changed files with 22 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@
Changes:
* added support for macro name in the endmacro tag
* fixed the "length" filter for numbers
* removed coupling between Twig_Node and Twig_Template
* fixed the ternary operator precedence rule
+7
View File
@@ -27,6 +27,13 @@ class Twig_TokenParser_Macro extends Twig_TokenParser
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$this->parser->pushLocalScope();
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
$value = $this->parser->getStream()->next()->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $lineno);
}
}
$this->parser->popLocalScope();
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
@@ -0,0 +1,14 @@
--TEST--
"macro" tag supports name for endmacro
--TEMPLATE--
{{ _self.foo() }}
{{ _self.bar() }}
{% macro foo() %}foo{% endmacro %}
{% macro bar() %}bar{% endmacro bar %}
--DATA--
return array()
--EXPECT--
foo
bar