[TwigBundle] updated the bundle to work with the latest Twig version

This commit is contained in:
Fabien Potencier 2010-06-03 08:42:22 +02:00
parent d05cec8a39
commit 12328a1bcb
7 changed files with 22 additions and 56 deletions

View File

@ -17,71 +17,37 @@ namespace Symfony\Framework\TwigBundle\Node;
* @subpackage Framework_TwigBundle
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class HelperNode extends \Twig_Node implements \Twig_NodeListInterface
class HelperNode extends \Twig_Node
{
protected $name;
protected $method;
protected $arguments;
protected $echo;
public function __construct($name, $method, \Twig_NodeList $arguments, $echo, $lineno, $tag = null)
public function __construct($name, $method, \Twig_Node $arguments = null, $echo, $lineno, $tag = null)
{
parent::__construct($lineno, $tag);
$this->name = $name;
$this->method = $method;
$this->arguments = $arguments;
$this->echo = $echo;
}
public function __toString()
{
return get_class($this).'('.$this->arguments.')';
}
public function getNodes()
{
return array($this->arguments);
}
public function setNodes(array $nodes)
{
$this->arguments = $nodes[0];
parent::__construct(array('arguments' => $arguments), array('name' => $name, 'method' => $method, 'echo' => $echo), $lineno, $tag);
}
public function compile($compiler)
{
$compiler->addDebugInfo($this);
$compiler
->addDebugInfo($this)
->write('')
;
if ($this->echo) {
if ($this['echo']) {
$compiler->raw('echo ');
}
$compiler->write('$context[\'_view\']->'.$this->name.'->'.$this->method.'(');
$compiler->raw('$context[\'_view\']->'.$this['name'].'->'.$this['method'].'(');
$count = count($this->arguments->getNodes());
foreach ($this->arguments->getNodes() as $i => $node) {
$compiler->subcompile($node);
if (null !== $this->arguments) {
$count = count($this->arguments);
foreach ($this->arguments as $i => $node) {
$compiler->subcompile($node);
if ($i !== $count - 1) {
$compiler->raw(', ');
if ($i !== $count - 1) {
$compiler->raw(', ');
}
}
}
$compiler->raw(");\n");
}
public function getName()
{
return $this->name;
}
public function getMethod()
{
return $this->method;
}
public function getArguments()
{
return $this->arguments;
}
}

View File

@ -38,7 +38,7 @@ class JavascriptTokenParser extends \Twig_TokenParser
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('javascripts', 'add', new \Twig_NodeList($nodes), false, $token->getLine(), $this->getTag());
return new HelperNode('javascripts', 'add', new \Twig_Node($nodes), false, $token->getLine(), $this->getTag());
}
public function getTag()

View File

@ -28,7 +28,7 @@ class JavascriptsTokenParser extends \Twig_TokenParser
{
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('javascripts', 'render', new \Twig_NodeList(array()), true, $token->getLine(), $this->getTag());
return new HelperNode('javascripts', 'render', null, true, $token->getLine(), $this->getTag());
}
public function getTag()

View File

@ -38,7 +38,7 @@ class RenderTokenParser extends \Twig_TokenParser
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('actions', 'render', new \Twig_NodeList($nodes), true, $lineno, $this->getTag());
return new HelperNode('actions', 'render', new \Twig_Node($nodes), true, $lineno, $this->getTag());
}
public function getTag()

View File

@ -38,7 +38,7 @@ class RouteTokenParser extends \Twig_TokenParser
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('router', 'generate', new \Twig_NodeList($nodes), true, $lineno, $this->getTag());
return new HelperNode('router', 'generate', new \Twig_Node($nodes), true, $lineno, $this->getTag());
}
public function getTag()

View File

@ -38,7 +38,7 @@ class StylesheetTokenParser extends \Twig_TokenParser
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('stylesheets', 'add', new \Twig_NodeList($nodes), false, $token->getLine(), $this->getTag());
return new HelperNode('stylesheets', 'add', new \Twig_Node($nodes), false, $token->getLine(), $this->getTag());
}
public function getTag()

View File

@ -28,7 +28,7 @@ class StylesheetsTokenParser extends \Twig_TokenParser
{
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new HelperNode('stylesheets', 'render', new \Twig_NodeList(array()), true, $token->getLine(), $this->getTag());
return new HelperNode('stylesheets', 'render', null, true, $token->getLine(), $this->getTag());
}
public function getTag()