winter/modules/cms/twig/DefaultTokenParser.php

42 lines
1.0 KiB
PHP

<?php namespace Cms\Twig;
use Twig\Token as TwigToken;
use Twig\TokenParser\AbstractTokenParser as TwigTokenParser;
/**
* Parser for the `{% default %}` Twig tag.
*
* {% put head %}
* <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"/>
* {% default %}
* {% endput %}
*
* @package october\cms
* @author Alexey Bobkov, Samuel Georges
*/
class DefaultTokenParser extends TwigTokenParser
{
/**
* Parses a token and returns a node.
*
* @param TwigToken $token A TwigToken instance
* @return Twig\Node\Node A Twig\Node\Node instance
*/
public function parse(TwigToken $token)
{
$stream = $this->parser->getStream();
$stream->expect(TwigToken::BLOCK_END_TYPE);
return new DefaultNode($token->getLine(), $this->getTag());
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'default';
}
}