Skip to content

Commit

Permalink
Merge pull request #399 from garak/fix-deprecation
Browse files Browse the repository at this point in the history
fix spaceless deprecation
  • Loading branch information
garak authored Feb 28, 2025
2 parents f452411 + 6371b22 commit 328bb43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ jobs:
include:
- description: 'No Symfony specified'
php: '8.1'
max_deprecations: 1
max_deprecations: 0
- description: 'No Symfony specified'
php: '8.2'
max_deprecations: 1
max_deprecations: 0
- description: 'No Symfony specified'
php: '8.3'
max_deprecations: 1
max_deprecations: 0
- description: 'No Symfony specified'
php: '8.4'
max_deprecations: 1
max_deprecations: 0
- description: 'Lowest deps'
php: '8.1'
composer_option: '--prefer-lowest'
max_deprecations: 0
- description: 'Symfony 6'
php: '8.1'
symfony: 6.4.*
max_deprecations: 1
max_deprecations: 0
- description: 'Symfony 7'
php: '8.4'
dev: true
symfony: 7.2.*
max_deprecations: 1
max_deprecations: 0
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- name: Checkout
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
9 changes: 9 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', [self::class, 'spaceless'], ['is_safe' => ['html']]),
];
}

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

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

/**
* @internal
*/
public static function spaceless(string $content): string
{
return trim((string) preg_replace('/>\s+</', '><', $content));
}
}
2 changes: 2 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,7 @@
use Knp\Menu\MenuItem;
use Knp\Menu\Renderer\RendererInterface;
use Knp\Menu\Renderer\TwigRenderer;
use Knp\Menu\Twig\MenuExtension;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

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

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

0 comments on commit 328bb43

Please sign in to comment.