1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of Twig.
|
5
|
*
|
6
|
* (c) 2010 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
|
class Twig_TokenParser_Spaceless extends Twig_TokenParser
|
26
|
{
|
27
|
/**
|
28
|
* Parses a token and returns a node.
|
29
|
*
|
30
|
* @param Twig_Token $token A Twig_Token instance
|
31
|
*
|
32
|
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
33
|
*/
|
34
|
public function parse(Twig_Token $token)
|
35
|
{
|
36
|
$lineno = $token->getLine();
|
37
|
|
38
|
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
39
|
$body = $this->parser->subparse(array($this, 'decideSpacelessEnd'), true);
|
40
|
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
41
|
|
42
|
return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
|
43
|
}
|
44
|
|
45
|
public function decideSpacelessEnd(Twig_Token $token)
|
46
|
{
|
47
|
return $token->test('endspaceless');
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Gets the tag name associated with this token parser.
|
52
|
*
|
53
|
* @return string The tag name
|
54
|
*/
|
55
|
public function getTag()
|
56
|
{
|
57
|
return 'spaceless';
|
58
|
}
|
59
|
}
|