diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:40:51 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:40:51 +0200 |
commit | a4565e88edbc8e3bd092a475469769c86a4c350c (patch) | |
tree | a6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /inc/Twig/TokenParser/Spaceless.php | |
parent | f6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff) | |
download | wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip |
add Twig & refactor poche
Diffstat (limited to 'inc/Twig/TokenParser/Spaceless.php')
-rw-r--r-- | inc/Twig/TokenParser/Spaceless.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/inc/Twig/TokenParser/Spaceless.php b/inc/Twig/TokenParser/Spaceless.php new file mode 100644 index 00000000..1e3fa8f3 --- /dev/null +++ b/inc/Twig/TokenParser/Spaceless.php | |||
@@ -0,0 +1,59 @@ | |||
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 | } | ||