e8b2638e2c6e926520827214b318a95dd611af05
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / Spaceless.php
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
12 /**
13  * Remove whitespaces between HTML tags.
14  *
15  * <pre>
16  * {% spaceless %}
17  *      <div>
18  *          <strong>foo</strong>
19  *      </div>
20  * {% endspaceless %}
21  *
22  * {# output will be <div><strong>foo</strong></div> #}
23  * </pre>
24  *
25  * @final
26  */
27 class Twig_TokenParser_Spaceless extends Twig_TokenParser
28 {
29     public function parse(Twig_Token $token)
30     {
31         $lineno = $token->getLine();
32
33         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
34         $body = $this->parser->subparse(array($this, 'decideSpacelessEnd'), true);
35         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
36
37         return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
38     }
39
40     public function decideSpacelessEnd(Twig_Token $token)
41     {
42         return $token->test('endspaceless');
43     }
44
45     public function getTag()
46     {
47         return 'spaceless';
48     }
49 }