Skip to content

Commit

Permalink
fix spaceless deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Dec 11, 2024
1 parent 9747837 commit cc14a60
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ jobs:
- description: 'Lowest deps'
php: '8.1'
composer_option: '--prefer-lowest'
env:
SYMFONY_DEPRECATIONS_HELPER: max[self]=0
- description: 'Symfony 5.4'
php: '8.1'
symfony: 5.4.*
- description: 'Symfony 6.4'
php: '8.2'
symfony: 6.4.*
env:
SYMFONY_DEPRECATIONS_HELPER: max[self]=1
- description: 'Dev deps'
Expand Down
2 changes: 1 addition & 1 deletion src/Knp/Menu/Resources/views/knp_menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endmacro %}

{% block compressed_root %}
{% apply spaceless %}
{% apply knp_menu_spaceless %}
{{ block('root') }}
{% endapply %}
{% endblock %}
Expand Down
6 changes: 6 additions & 0 deletions src/Knp/Menu/Twig/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function getFilters(): array

return [
new TwigFilter('knp_menu_as_string', $legacy ? [$this, 'pathAsString'] : [MenuRuntimeExtension::class, 'pathAsString']),
new TwigFilter('knp_menu_spaceless', [$this, 'spaceless'], ['is_safe' => ['html']]),
];
}

Expand Down Expand Up @@ -121,4 +122,9 @@ public function isAncestor(ItemInterface $item, ?int $depth = null): bool

return $this->runtimeExtension->isAncestor($item, $depth);
}

public function spaceless(string $content): string
{
return trim((string) preg_replace('/>\s+</', '><', $content));
}
}
3 changes: 3 additions & 0 deletions tests/Knp/Menu/Tests/Renderer/TwigRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Knp\Menu\MenuItem;
use Knp\Menu\Renderer\RendererInterface;
use Knp\Menu\Renderer\TwigRenderer;
use Knp\Menu\Twig\Helper;
use Knp\Menu\Twig\MenuExtension;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

Expand All @@ -16,6 +18,7 @@ public function createRenderer(MatcherInterface $matcher): RendererInterface
{
$loader = new FilesystemLoader(__DIR__.'/../../../../../src/Knp/Menu/Resources/views');
$environment = new Environment($loader);
$environment->addExtension(new MenuExtension($this->createMock(Helper::class)));

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

0 comments on commit cc14a60

Please sign in to comment.