changed as to = for the set tag and removed the need for as in short-notation of...
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 9 Jun 2010 06:20:51 +0000 (08:20 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 9 Jun 2010 06:20:51 +0000 (08:20 +0200)
CHANGELOG
doc/02-Twig-for-Template-Designers.markdown
lib/Twig/Lexer.php
lib/Twig/TokenParser/Block.php
lib/Twig/TokenParser/Set.php
test/fixtures/expressions/array.test
test/fixtures/tags/block/basic.test
test/fixtures/tags/for/inner_variables.test
test/fixtures/tags/set/basic.test
test/fixtures/tags/set/capture.test [new file with mode: 0644]
test/fixtures/tags/set/expression.test

index 045848b..f357805 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,7 +1,7 @@
 * 0.9.7-DEV
 
 Backward incompatibilities:
- * added a 'as' string to the block tag short notation ({% block title "Title" %} must now be {% block title as "Title" %})
+ * changed 'as' to '=' for the set tag ({% set title as "Title" %} must now be {% set title = "Title" %})
  * removed the sandboxed attribute of the include tag (use the new sandbox tag instead)
  * refactored the Node system (if you have custom nodes, you will have to update them to use the new API)
 
index 34be297..79fe666 100644 (file)
@@ -311,7 +311,7 @@ following constructs do the same:
 -
 
     [twig]
-    {% block title as page_title|title %}
+    {% block title page_title|title %}
 
 Import Context Behavior
 -----------------------
@@ -603,15 +603,15 @@ Inside code blocks you can also assign values to variables. Assignments use
 the `set` tag and can have multiple targets:
 
     [twig]
-    {% set foo as 'foo' %}
+    {% set foo = 'foo' %}
 
-    {% set foo as [1, 2] %}
+    {% set foo = [1, 2] %}
 
-    {% set foo as ['foo': 'bar] %}
+    {% set foo = ['foo': 'bar] %}
 
-    {% set foo as 'foo' ~ 'bar' %}
+    {% set foo = 'foo' ~ 'bar' %}
 
-    {% set foo, bar as 'foo', 'bar' %}
+    {% set foo, bar = 'foo', 'bar' %}
 
 The `set` tag can also be used to 'capture' chunks of HTML (new in Twig
 0.9.6):
index dc995a4..f1c304b 100644 (file)
@@ -36,7 +36,7 @@ class Twig_Lexer implements Twig_LexerInterface
     const REGEX_NAME     = '/[A-Za-z_][A-Za-z0-9_]*/A';
     const REGEX_NUMBER   = '/[0-9]+(?:\.[0-9]+)?/A';
     const REGEX_STRING   = '/(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/Asm';
-    const REGEX_OPERATOR = '/<=? | >=? | [!=]= | \/\/ | \.\. | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax';
+    const REGEX_OPERATOR = '/<=? | >=? | [!=]= | = | \/\/ | \.\. | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax';
 
     public function __construct(Twig_Environment $env = null, array $options = array())
     {
index 1d2f846..ab80c3e 100644 (file)
@@ -40,8 +40,6 @@ class Twig_TokenParser_Block extends Twig_TokenParser
                 }
             }
         } else {
-            $stream->expect(Twig_Token::NAME_TYPE, 'as');
-
             $body = new Twig_Node(array(
                 new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
             ));
index 05a565d..25731c7 100644 (file)
@@ -24,7 +24,7 @@ class Twig_TokenParser_Set extends Twig_TokenParser
         $names = $this->parser->getExpressionParser()->parseAssignmentExpression();
 
         $capture = false;
-        if ($stream->test(Twig_Token::NAME_TYPE, 'as')) {
+        if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) {
             $stream->next();
             list(, $values) = $this->parser->getExpressionParser()->parseMultitargetExpression();
 
index 3ebdeaa..32f9fe2 100644 (file)
@@ -10,7 +10,7 @@ Twig supports array notation
 {{ [1, 'foo': 'bar']|keys|join(',') }}
 
 {# nested arrays #}
-{% set a as [1, 2, [1, 2], 'foo': ['foo': 'bar']] %}
+{% set a = [1, 2, [1, 2], 'foo': ['foo': 'bar']] %}
 {{ a[2]|join(',') }}
 {{ a["foo"]|join(',') }}
 
index ecb7210..360dcf0 100644 (file)
@@ -2,7 +2,7 @@
 "block" tag
 --TEMPLATE--
 {% block title1 %}FOO{% endblock %}
-{% block title2 as foo|lower %}
+{% block title2 foo|lower %}
 --TEMPLATE(foo.twig)--
 {% block content %}{% endblock %}
 --DATA--
index 3e9ad56..49fb9ca 100644 (file)
@@ -3,7 +3,7 @@
 --TEMPLATE--
 {% for i in 1..2 %}
   {% for j in 0..2 %}
-    {{k}}{% set k as k+1 %} {{ loop.parent.loop.index }}
+    {{k}}{% set k = k+1 %} {{ loop.parent.loop.index }}
   {% endfor %}
 {% endfor %}
 --DATA--
index 9c6fbd1..75ad6d3 100644 (file)
@@ -1,11 +1,11 @@
 --TEST--
 "set" tag
 --TEMPLATE--
-{% set foo as 'foo' %}
+{% set foo = 'foo' %}
 
 {{ foo }}
 
-{% set foo, bar as 'foo', 'bar' %}
+{% set foo, bar = 'foo', 'bar' %}
 
 {{ foo }}{{ bar }}
 --DATA--
diff --git a/test/fixtures/tags/set/capture.test b/test/fixtures/tags/set/capture.test
new file mode 100644 (file)
index 0000000..4408ca8
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+"set" tag block capture
+--TEMPLATE--
+{% set foo %}foo{% endset %}
+
+{{ foo }}
+--DATA--
+return array()
+--EXPECT--
+foo
index 462d33c..8ff434a 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 "set" tag
 --TEMPLATE--
-{% set foo, bar as 'foo' ~ 'bar', 'bar' ~ 'foo' %}
+{% set foo, bar = 'foo' ~ 'bar', 'bar' ~ 'foo' %}
 
 {{ foo }}
 {{ bar }}