added support for macro name in the endmacro tag
authorFabien Potencier <fabien.potencier@gmail.com>
Thu, 17 Feb 2011 12:36:40 +0000 (13:36 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Thu, 17 Feb 2011 12:36:40 +0000 (13:36 +0100)
CHANGELOG
lib/Twig/TokenParser/Macro.php
test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test [new file with mode: 0644]

index 588115a..5f8964d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
index a6e4733..9cc0886 100644 (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);
 
diff --git a/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test b/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test
new file mode 100644 (file)
index 0000000..fa81189
--- /dev/null
@@ -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
+