Spaceless.php 996B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. * @package twig
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class Twig_Node_Spaceless extends Twig_Node
  19. {
  20. public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless')
  21. {
  22. parent::__construct(array('body' => $body), array(), $lineno, $tag);
  23. }
  24. /**
  25. * Compiles the node to PHP.
  26. *
  27. * @param Twig_Compiler A Twig_Compiler instance
  28. */
  29. public function compile(Twig_Compiler $compiler)
  30. {
  31. $compiler
  32. ->addDebugInfo($this)
  33. ->write("ob_start();\n")
  34. ->subcompile($this->getNode('body'))
  35. ->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
  36. ;
  37. }
  38. }