mirror of
https://github.com/twigphp/Twig.git
synced 2026-11-10 03:49:46 +00:00
removed the spaceless tag
This commit is contained in:
@@ -62,7 +62,6 @@ use Twig\TokenParser\ImportTokenParser;
|
||||
use Twig\TokenParser\IncludeTokenParser;
|
||||
use Twig\TokenParser\MacroTokenParser;
|
||||
use Twig\TokenParser\SetTokenParser;
|
||||
use Twig\TokenParser\SpacelessTokenParser;
|
||||
use Twig\TokenParser\UseTokenParser;
|
||||
use Twig\TokenParser\WithTokenParser;
|
||||
use Twig\TwigFilter;
|
||||
@@ -184,7 +183,6 @@ final class CoreExtension extends AbstractExtension
|
||||
new ImportTokenParser(),
|
||||
new FromTokenParser(),
|
||||
new SetTokenParser(),
|
||||
new SpacelessTokenParser(),
|
||||
new FlushTokenParser(),
|
||||
new DoTokenParser(),
|
||||
new EmbedTokenParser(),
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
|
||||
/**
|
||||
* Represents a spaceless node.
|
||||
*
|
||||
* It removes spaces between HTML tags.
|
||||
*
|
||||
* @deprecated since Twig 2.7, to be removed in 3.0
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class SpacelessNode extends Node implements NodeOutputInterface
|
||||
{
|
||||
public function __construct(Node $body, int $lineno, string $tag = 'spaceless')
|
||||
{
|
||||
parent::__construct(['body' => $body], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("ob_start();\n")
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -23,7 +23,6 @@ use Twig\Node\Node;
|
||||
use Twig\Node\NodeCaptureInterface;
|
||||
use Twig\Node\NodeOutputInterface;
|
||||
use Twig\Node\PrintNode;
|
||||
use Twig\Node\SpacelessNode;
|
||||
use Twig\Node\TextNode;
|
||||
use Twig\TokenParser\TokenParserInterface;
|
||||
|
||||
@@ -341,8 +340,7 @@ class Parser
|
||||
if (
|
||||
($node instanceof TextNode && !ctype_space($node->getAttribute('data')))
|
||||
||
|
||||
// the "&& !$node instanceof SpacelessNode" part of the condition must be removed in 3.0
|
||||
(!$node instanceof TextNode && !$node instanceof BlockReferenceNode && ($node instanceof NodeOutputInterface && !$node instanceof SpacelessNode))
|
||||
(!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface)
|
||||
) {
|
||||
if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) {
|
||||
$t = substr($node->getAttribute('data'), 3);
|
||||
@@ -361,11 +359,6 @@ class Parser
|
||||
return $node;
|
||||
}
|
||||
|
||||
// to be removed completely in Twig 3.0
|
||||
if (!$nested && $node instanceof SpacelessNode) {
|
||||
@trigger_error(sprintf('Using the spaceless tag at the root level of a child template in "%s" at line %d is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// "block" tags that are not captured (see above) are only used for defining
|
||||
// the content of the block. In such a case, nesting it does not work as
|
||||
// expected as the definition is not part of the default template code flow.
|
||||
@@ -376,8 +369,7 @@ class Parser
|
||||
return;
|
||||
}
|
||||
|
||||
// the "&& !$node instanceof SpacelessNode" part of the condition must be removed in 3.0
|
||||
if ($node instanceof NodeOutputInterface && !$node instanceof SpacelessNode) {
|
||||
if ($node instanceof NodeOutputInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\SpacelessNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Remove whitespaces between HTML tags.
|
||||
*
|
||||
* {% spaceless %}
|
||||
* <div>
|
||||
* <strong>foo</strong>
|
||||
* </div>
|
||||
* {% endspaceless %}
|
||||
* {# output will be <div><strong>foo</strong></div> #}
|
||||
*
|
||||
* @deprecated since Twig 2.7, to be removed in 3.0 (use the spaceless filter instead)
|
||||
*/
|
||||
final class SpacelessTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
@trigger_error('The spaceless tag is deprecated since Twig 2.7, use the spaceless filter instead.', E_USER_DEPRECATED);
|
||||
|
||||
$lineno = $token->getLine();
|
||||
|
||||
$this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
|
||||
$body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true);
|
||||
$this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
|
||||
|
||||
return new SpacelessNode($body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideSpacelessEnd(Token $token)
|
||||
{
|
||||
return $token->test('endspaceless');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'spaceless';
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
--TEST--
|
||||
capturing "block" tag
|
||||
--DEPRECATION--
|
||||
The spaceless tag is deprecated since Twig 2.7, use the spaceless filter instead.
|
||||
--TEMPLATE--
|
||||
{% set foo %}{% block foo %}FOO{% endblock %}{% endset %}
|
||||
{{ foo }}
|
||||
{% spaceless %}
|
||||
{% block bar %}
|
||||
<h1>
|
||||
<b>Title</b>
|
||||
</h1>
|
||||
{% endblock %}
|
||||
{% endspaceless %}
|
||||
|
||||
{{ block('bar') }}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
FOO
|
||||
<h1><b>Title</b></h1>
|
||||
<h1>
|
||||
<b>Title</b>
|
||||
</h1>
|
||||
@@ -1,23 +0,0 @@
|
||||
--TEST--
|
||||
"spaceless" tag in the root level of a child template
|
||||
--DEPRECATION--
|
||||
The spaceless tag is deprecated since Twig 2.7, use the spaceless filter instead.
|
||||
Using the spaceless tag at the root level of a child template in "index.twig" at line 3 is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.
|
||||
Nesting a block definition under a non-capturing node in "index.twig" at line 4 is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.
|
||||
--TEMPLATE--
|
||||
{% extends "layout.twig" %}
|
||||
{% spaceless %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
<b>Title</b>
|
||||
</h1>
|
||||
{% endblock %}
|
||||
{% endspaceless %}
|
||||
--TEMPLATE(layout.twig)--
|
||||
{% block content %}FOO{% endblock %}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
<h1>
|
||||
<b>Title</b>
|
||||
</h1>
|
||||
@@ -1,14 +0,0 @@
|
||||
--TEST--
|
||||
"spaceless" tag removes whites between HTML tags
|
||||
--DEPRECATION--
|
||||
The spaceless tag is deprecated since Twig 2.7, use the spaceless filter instead.
|
||||
--TEMPLATE--
|
||||
{% spaceless %}
|
||||
|
||||
<div> <div> foo </div> </div>
|
||||
|
||||
{% endspaceless %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
<div><div> foo </div></div>
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\SpacelessNode;
|
||||
use Twig\Node\TextNode;
|
||||
use Twig\Test\NodeTestCase;
|
||||
|
||||
class Twig_Tests_Node_SpacelessTest extends NodeTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$body = new Node([new TextNode('<div> <div> foo </div> </div>', 1)]);
|
||||
$node = new SpacelessNode($body, 1);
|
||||
|
||||
$this->assertEquals($body, $node->getNode('body'));
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$body = new Node([new TextNode('<div> <div> foo </div> </div>', 1)]);
|
||||
$node = new SpacelessNode($body, 1);
|
||||
|
||||
return [
|
||||
[$node, <<<EOF
|
||||
// line 1
|
||||
ob_start();
|
||||
echo "<div> <div> foo </div> </div>";
|
||||
echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));
|
||||
EOF
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user