/**
* Compiles a node.
*
- * @param Twig_NodeInterface $node The node to compile
+ * @param Twig_NodeInterface $node The node to compile
+ * @param integer $indent The current indentation
*
* @return Twig_Compiler The current compiler instance
*/
- public function compile(Twig_NodeInterface $node)
+ public function compile(Twig_NodeInterface $node, $indentation = 0)
{
$this->lastLine = null;
$this->source = '';
- $this->indentation = 0;
+ $this->indentation = $indentation;
$node->compile($this);
return $this;
}
- public function subcompile(Twig_NodeInterface $node)
+ public function subcompile(Twig_NodeInterface $node, $raw = true)
{
+ if (false === $raw)
+ {
+ $this->addIndentation();
+ }
+
$node->compile($this);
return $this;
{
$strings = func_get_args();
foreach ($strings as $string) {
- $this->source .= str_repeat(' ', $this->indentation * 4).$string;
+ $this->addIndentation();
+ $this->source .= $string;
}
return $this;
}
+ public function addIndentation()
+ {
+ $this->source .= str_repeat(' ', $this->indentation * 4);
+
+ return $this;
+ }
+
/**
* Adds a quoted string to the compiled code.
*
return implode("\n", $repr);
}
+
public function compile($compiler)
{
$compiler->raw('(');
$this->operator($compiler);
- $this->node->compile($compiler);
- $compiler->raw(')');
+ $compiler
+ ->subcompile($this->node)
+ ->raw(')')
+ ;
}
abstract public function operator($compiler);
$compiler->raw(', ');
}
- $compiler
- ->raw('$context[')
- ->string($node->getName())
- ->raw(']')
- ;
+ $compiler->subcompile($node);
}
$compiler->raw(')');
} else {
;
}
- $compiler
- ->write('$context[')
- ->string($this->names->getName())
- ->raw(']')
- ;
+ $compiler->subcompile($this->names, false);
if ($this->capture) {
$compiler->raw(" = ob_get_clean()");