Skip to content

Commit 328bb43

Browse files
authored
Merge pull request #399 from garak/fix-deprecation
fix spaceless deprecation
2 parents f452411 + 6371b22 commit 328bb43

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,29 @@ jobs:
4242
include:
4343
- description: 'No Symfony specified'
4444
php: '8.1'
45-
max_deprecations: 1
45+
max_deprecations: 0
4646
- description: 'No Symfony specified'
4747
php: '8.2'
48-
max_deprecations: 1
48+
max_deprecations: 0
4949
- description: 'No Symfony specified'
5050
php: '8.3'
51-
max_deprecations: 1
51+
max_deprecations: 0
5252
- description: 'No Symfony specified'
5353
php: '8.4'
54-
max_deprecations: 1
54+
max_deprecations: 0
5555
- description: 'Lowest deps'
5656
php: '8.1'
5757
composer_option: '--prefer-lowest'
5858
max_deprecations: 0
5959
- description: 'Symfony 6'
6060
php: '8.1'
6161
symfony: 6.4.*
62-
max_deprecations: 1
62+
max_deprecations: 0
6363
- description: 'Symfony 7'
6464
php: '8.4'
6565
dev: true
6666
symfony: 7.2.*
67-
max_deprecations: 1
67+
max_deprecations: 0
6868
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
6969
steps:
7070
- name: Checkout

src/Knp/Menu/Resources/views/knp_menu.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% endmacro %}
1010

1111
{% block compressed_root %}
12-
{% apply spaceless %}
12+
{% apply knp_menu_spaceless %}
1313
{{ block('root') }}
1414
{% endapply %}
1515
{% endblock %}

src/Knp/Menu/Twig/MenuExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function getFilters(): array
4343

4444
return [
4545
new TwigFilter('knp_menu_as_string', $legacy ? [$this, 'pathAsString'] : [MenuRuntimeExtension::class, 'pathAsString']),
46+
new TwigFilter('knp_menu_spaceless', [self::class, 'spaceless'], ['is_safe' => ['html']]),
4647
];
4748
}
4849

@@ -121,4 +122,12 @@ public function isAncestor(ItemInterface $item, ?int $depth = null): bool
121122

122123
return $this->runtimeExtension->isAncestor($item, $depth);
123124
}
125+
126+
/**
127+
* @internal
128+
*/
129+
public static function spaceless(string $content): string
130+
{
131+
return trim((string) preg_replace('/>\s+</', '><', $content));
132+
}
124133
}

tests/Knp/Menu/Tests/Renderer/TwigRendererTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Knp\Menu\MenuItem;
88
use Knp\Menu\Renderer\RendererInterface;
99
use Knp\Menu\Renderer\TwigRenderer;
10+
use Knp\Menu\Twig\MenuExtension;
1011
use Twig\Environment;
1112
use Twig\Loader\FilesystemLoader;
1213

@@ -16,6 +17,7 @@ public function createRenderer(MatcherInterface $matcher): RendererInterface
1617
{
1718
$loader = new FilesystemLoader(__DIR__.'/../../../../../src/Knp/Menu/Resources/views');
1819
$environment = new Environment($loader);
20+
$environment->addExtension(new MenuExtension());
1921

2022
return new TwigRenderer($environment, 'knp_menu.html.twig', $matcher, ['compressed' => true]);
2123
}

0 commit comments

Comments
 (0)