Spaceless.php 863 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2010 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Represents a spaceless node.
  12. *
  13. * It removes spaces between HTML tags.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class Twig_Node_Spaceless extends Twig_Node
  18. {
  19. public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless')
  20. {
  21. parent::__construct(array('body' => $body), array(), $lineno, $tag);
  22. }
  23. public function compile(Twig_Compiler $compiler)
  24. {
  25. $compiler
  26. ->addDebugInfo($this)
  27. ->write("ob_start();\n")
  28. ->subcompile($this->getNode('body'))
  29. ->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
  30. ;
  31. }
  32. }