1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Twig\TokenParser;
13
14use Twig\Node\SpacelessNode;
15use Twig\Token;
16
17/**
18 * Remove whitespaces between HTML tags.
19 *
20 *   {% spaceless %}
21 *      <div>
22 *          <strong>foo</strong>
23 *      </div>
24 *   {% endspaceless %}
25 *   {# output will be <div><strong>foo</strong></div> #}
26 *
27 * @final
28 */
29class SpacelessTokenParser extends AbstractTokenParser
30{
31    public function parse(Token $token)
32    {
33        $lineno = $token->getLine();
34
35        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
36        $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true);
37        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
38
39        return new SpacelessNode($body, $lineno, $this->getTag());
40    }
41
42    public function decideSpacelessEnd(Token $token)
43    {
44        return $token->test('endspaceless');
45    }
46
47    public function getTag()
48    {
49        return 'spaceless';
50    }
51}
52
53class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless');
54