[TwigBundle] added javascript/javascripts tags
This commit is contained in:
parent
5a09375dc4
commit
28c0329deb
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Framework\TwigBundle\TokenParser;
|
||||||
|
|
||||||
|
use Symfony\Framework\TwigBundle\Node\HelperNode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for the javascripts helper add() method.
|
||||||
|
*
|
||||||
|
* {% javascript 'bundles/blog/css/blog.css' %}
|
||||||
|
*
|
||||||
|
* @package Symfony
|
||||||
|
* @subpackage Framework_TwigBundle
|
||||||
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
|
*/
|
||||||
|
class JavascriptTokenParser extends \Twig_TokenParser
|
||||||
|
{
|
||||||
|
public function parse(\Twig_Token $token)
|
||||||
|
{
|
||||||
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
|
$nodes = array($this->parser->getExpressionParser()->parseExpression());
|
||||||
|
|
||||||
|
if ($stream->test(\Twig_Token::NAME_TYPE, 'with')) {
|
||||||
|
$stream->next();
|
||||||
|
|
||||||
|
$nodes[] = $this->parser->getExpressionParser()->parseExpression();
|
||||||
|
}
|
||||||
|
|
||||||
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
|
return new HelperNode('javascripts', 'add', new \Twig_NodeList($nodes), false, $token->getLine(), $this->getTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTag()
|
||||||
|
{
|
||||||
|
return 'javascripts';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Framework\TwigBundle\TokenParser;
|
||||||
|
|
||||||
|
use Symfony\Framework\TwigBundle\Node\HelperNode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for the javascripts helper output() method.
|
||||||
|
*
|
||||||
|
* {% javascripts %}
|
||||||
|
*
|
||||||
|
* @package Symfony
|
||||||
|
* @subpackage Framework_TwigBundle
|
||||||
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
|
*/
|
||||||
|
class JavascriptsTokenParser extends \Twig_TokenParser
|
||||||
|
{
|
||||||
|
public function parse(\Twig_Token $token)
|
||||||
|
{
|
||||||
|
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
|
return new HelperNode('javascripts', 'render', new \Twig_NodeList(array()), true, $token->getLine(), $this->getTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTag()
|
||||||
|
{
|
||||||
|
return 'javascripts';
|
||||||
|
}
|
||||||
|
}
|
@ -26,19 +26,19 @@ class StylesheetTokenParser extends \Twig_TokenParser
|
|||||||
{
|
{
|
||||||
public function parse(\Twig_Token $token)
|
public function parse(\Twig_Token $token)
|
||||||
{
|
{
|
||||||
$nodes = array();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$lineno = $token->getLine();
|
$nodes = array($this->parser->getExpressionParser()->parseExpression());
|
||||||
$nodes[] = $this->parser->getExpressionParser()->parseExpression();
|
|
||||||
|
if ($stream->test(\Twig_Token::NAME_TYPE, 'with')) {
|
||||||
|
$stream->next();
|
||||||
|
|
||||||
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
|
|
||||||
$this->parser->getStream()->expect(\Twig_Token::NAME_TYPE, 'with');
|
|
||||||
$nodes[] = $this->parser->getExpressionParser()->parseExpression();
|
$nodes[] = $this->parser->getExpressionParser()->parseExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new HelperNode('stylesheets', 'add', new \Twig_NodeList($nodes), false, $lineno, $this->getTag());
|
return new HelperNode('stylesheets', 'add', new \Twig_NodeList($nodes), false, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTag()
|
public function getTag()
|
||||||
|
Reference in New Issue
Block a user