changed the generated code to match the new coding standards
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 25 May 2010 16:11:01 +0000 (18:11 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 25 May 2010 16:11:01 +0000 (18:11 +0200)
CHANGELOG
lib/Twig/Compiler.php
lib/Twig/Node/Debug.php
lib/Twig/Node/For.php
lib/Twig/Node/If.php
lib/Twig/Node/Import.php
lib/Twig/Node/Include.php
lib/Twig/Node/SandboxPrint.php

index aad80f2..3caf8dd 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@
 Backward incompatibilities:
  * The short notation of the `block` tag changed.
 
+ * changed the generated code to match the new coding standards
  * fixed sandbox mode (__toString() method check was not enforced if called implicitly from a simple statement like {{ article }})
  * added a 'as' string to the block tag short notation ({% block title "Title" %} must now be {% block title as "Title" %})
  * added an exception when a child template has a non-empty body (as it is always ignored when rendering)
index eb7fa22..5b7e724 100644 (file)
@@ -97,7 +97,7 @@ class Twig_Compiler implements Twig_CompilerInterface
     {
         $strings = func_get_args();
         foreach ($strings as $string) {
-            $this->source .= str_repeat(' ', $this->indentation * 2).$string;
+            $this->source .= str_repeat(' ', $this->indentation * 4).$string;
         }
 
         return $this;
index 2cf3af6..c22d1cc 100644 (file)
@@ -16,7 +16,7 @@ class Twig_Node_Debug extends Twig_Node
         $compiler->addDebugInfo($this);
 
         $compiler
-            ->write("if (\$this->env->isDebug())\n", "{\n")
+            ->write("if (\$this->env->isDebug()) {\n")
             ->indent()
             ->write('var_export(')
         ;
index b1b11b0..f7541ce 100644 (file)
@@ -94,8 +94,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface
             ->repr($loopVars[0])
             ->raw("] => \$context[")
             ->repr($loopVars[1])
-            ->raw("])\n")
-            ->write("{\n")
+            ->raw("]) {\n")
             ->indent()
         ;
 
index 587b5e7..0dc5f60 100644 (file)
@@ -81,7 +81,7 @@ class Twig_Node_If extends Twig_Node implements Twig_NodeListInterface
             if ($idx++) {
                 $compiler
                     ->outdent()
-                    ->write("}\n", "elseif (")
+                    ->write("} elseif (")
                 ;
             } else {
                 $compiler
@@ -91,8 +91,7 @@ class Twig_Node_If extends Twig_Node implements Twig_NodeListInterface
 
             $compiler
                 ->subcompile($test[0])
-                ->raw(")\n")
-                ->write("{\n")
+                ->raw(") {\n")
                 ->indent()
                 ->subcompile($test[1])
             ;
@@ -100,7 +99,7 @@ class Twig_Node_If extends Twig_Node implements Twig_NodeListInterface
         if (!is_null($this->else)) {
             $compiler
                 ->outdent()
-                ->write("}\n", "else\n", "{\n")
+                ->write("} else {\n")
                 ->indent()
                 ->subcompile($this->else)
             ;
index 6237c94..1fbde38 100644 (file)
@@ -42,8 +42,7 @@ class Twig_Node_Import extends Twig_Node
             ->raw(");\n\n")
             ->write("if (!class_exists(")
             ->string($compiler->getTemplateClass($this->macro).'_Macro')
-            ->raw("))\n")
-            ->write("{\n")
+            ->raw(")) {\n")
             ->indent()
             ->write(sprintf("throw new InvalidArgumentException('There is no defined macros in template \"%s\".');\n", $this->macro))
             ->outdent()
index 85b8593..542f476 100644 (file)
@@ -104,7 +104,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeListInterface
 
         if ($this->sandboxed) {
             $compiler
-                ->write("if (!\$alreadySandboxed)\n", "{\n")
+                ->write("if (!\$alreadySandboxed) {\n")
                 ->indent()
                 ->write("\$sandbox->disableSandbox();\n")
                 ->outdent()
index a2f98be..d405c1c 100644 (file)
@@ -29,8 +29,7 @@ class Twig_Node_SandboxPrint extends Twig_Node_Print
             ->addDebugInfo($this)
             ->write('if ($this->env->hasExtension(\'sandbox\') && is_object(')
             ->subcompile($this->expr)
-            ->raw('))'."\n")
-            ->write('{'."\n")
+            ->raw(')) {'."\n")
             ->indent()
             ->write('$this->env->getExtension(\'sandbox\')->checkMethodAllowed(')
             ->subcompile($this->expr)