From: Fabien Potencier Date: Tue, 25 May 2010 16:11:01 +0000 (+0200) Subject: changed the generated code to match the new coding standards X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d4534e841957680b94a937583d5cab825e5763e9;p=web%2Fkonrad%2Ftwig.git changed the generated code to match the new coding standards --- diff --git a/CHANGELOG b/CHANGELOG index aad80f2..3caf8dd 100644 --- 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) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index eb7fa22..5b7e724 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -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; diff --git a/lib/Twig/Node/Debug.php b/lib/Twig/Node/Debug.php index 2cf3af6..c22d1cc 100644 --- a/lib/Twig/Node/Debug.php +++ b/lib/Twig/Node/Debug.php @@ -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(') ; diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index b1b11b0..f7541ce 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -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() ; diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index 587b5e7..0dc5f60 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -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) ; diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 6237c94..1fbde38 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -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() diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index 85b8593..542f476 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -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() diff --git a/lib/Twig/Node/SandboxPrint.php b/lib/Twig/Node/SandboxPrint.php index a2f98be..d405c1c 100644 --- a/lib/Twig/Node/SandboxPrint.php +++ b/lib/Twig/Node/SandboxPrint.php @@ -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)