From 7dbdb05b66e79847245af29ed687d565129db3f1 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Sun, 17 Mar 2024 14:14:11 +0100 Subject: [PATCH] Add custom Twig loader to remove last new line of a file --- packages/guides/resources/config/guides.php | 4 +- .../guides/src/Twig/TrimFilesystemLoader.php | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 packages/guides/src/Twig/TrimFilesystemLoader.php diff --git a/packages/guides/resources/config/guides.php b/packages/guides/resources/config/guides.php index a69251838..e2f4fae0d 100644 --- a/packages/guides/resources/config/guides.php +++ b/packages/guides/resources/config/guides.php @@ -57,6 +57,7 @@ use phpDocumentor\Guides\Twig\EnvironmentBuilder; use phpDocumentor\Guides\Twig\GlobalMenuExtension; use phpDocumentor\Guides\Twig\Theme\ThemeManager; +use phpDocumentor\Guides\Twig\TrimFilesystemLoader; use phpDocumentor\Guides\Twig\TwigTemplateRenderer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Reference; @@ -223,11 +224,12 @@ param('phpdoc.guides.base_template_paths'), ) - ->set(FilesystemLoader::class) + ->set(TrimFilesystemLoader::class) ->arg( '$paths', param('phpdoc.guides.base_template_paths'), ) + ->alias(FilesystemLoader::class, TrimFilesystemLoader::class) ->set(LoadSettingsFromComposer::class) ->tag('event_listener', ['event' => PostProjectNodeCreated::class]) diff --git a/packages/guides/src/Twig/TrimFilesystemLoader.php b/packages/guides/src/Twig/TrimFilesystemLoader.php new file mode 100644 index 000000000..f0e93b1ed --- /dev/null +++ b/packages/guides/src/Twig/TrimFilesystemLoader.php @@ -0,0 +1,41 @@ +getCode()) ?? $source->getCode(), + $source->getName(), + $source->getPath(), + ); + } +}