1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 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
12namespace Twig\Node;
13
14use Twig\Compiler;
15
16/**
17 * Represents a spaceless node.
18 *
19 * It removes spaces between HTML tags.
20 *
21 * @author Fabien Potencier <fabien@symfony.com>
22 */
23class SpacelessNode extends Node
24{
25    public function __construct(\Twig_NodeInterface $body, $lineno, $tag = 'spaceless')
26    {
27        parent::__construct(['body' => $body], [], $lineno, $tag);
28    }
29
30    public function compile(Compiler $compiler)
31    {
32        $compiler
33            ->addDebugInfo($this)
34            ->write("ob_start();\n")
35            ->subcompile($this->getNode('body'))
36            ->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
37        ;
38    }
39}
40
41class_alias('Twig\Node\SpacelessNode', 'Twig_Node_Spaceless');
42