shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

Spaceless.php (1131B)


      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     public function parse(Twig_Token $token)
     28     {
     29         $lineno = $token->getLine();
     30 
     31         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     32         $body = $this->parser->subparse(array($this, 'decideSpacelessEnd'), true);
     33         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     34 
     35         return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
     36     }
     37 
     38     public function decideSpacelessEnd(Twig_Token $token)
     39     {
     40         return $token->test('endspaceless');
     41     }
     42 
     43     public function getTag()
     44     {
     45         return 'spaceless';
     46     }
     47 }