From 33e3eeaec851158289e1a236cfe08a475cc6364a Mon Sep 17 00:00:00 2001 From: Simounet Date: Wed, 29 Jan 2020 22:26:00 +0100 Subject: [PATCH] Load custom.css only if exists --- GNUmakefile | 7 ++----- app/config/services.yml | 1 + src/Wallabag/CoreBundle/Resources/views/base.html.twig | 4 +++- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 10 +++++++++- .../Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | 6 +++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 837f7103..d0894dbb 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,14 +17,14 @@ help: ## Display this help menu clean: ## Clear the application cache rm -rf var/cache/* -install: customcss ## Install wallabag with the latest version +install: ## Install wallabag with the latest version @./scripts/install.sh $(ENV) update: ## Update the wallabag installation to the latest version @./scripts/update.sh $(ENV) dev: ENV=dev -dev: build customcss ## Install the latest dev version +dev: build ## Install the latest dev version @./scripts/dev.sh run: ## Run the wallabag built-in server @@ -34,9 +34,6 @@ build: ## Run webpack @npm install @npm run build:$(ENV) -customcss: - @touch web/custom.css - prepare: clean ## Prepare database for testsuite ifdef DB cp app/config/tests/parameters_test.$(DB).yml app/config/parameters_test.yml diff --git a/app/config/services.yml b/app/config/services.yml index 25bbe5dc..c2c867cf 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -16,6 +16,7 @@ services: - "@security.token_storage" - "%wallabag_core.cache_lifetime%" - "@translator" + - "%kernel.root_dir%" tags: - { name: twig.extension } diff --git a/src/Wallabag/CoreBundle/Resources/views/base.html.twig b/src/Wallabag/CoreBundle/Resources/views/base.html.twig index 496b3fb6..2486172d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/base.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/base.html.twig @@ -44,7 +44,9 @@ {% block css %} {% endblock %} - + {% if asset_file_exists('custom.css') %} + + {% endif %} {% block scripts %} diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 02f17f50..47af3c8e 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -18,14 +18,16 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface private $tagRepository; private $lifeTime; private $translator; + private $rootDir; - public function __construct(EntryRepository $entryRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator) + public function __construct(EntryRepository $entryRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator, string $rootDir) { $this->entryRepository = $entryRepository; $this->tagRepository = $tagRepository; $this->tokenStorage = $tokenStorage; $this->lifeTime = $lifeTime; $this->translator = $translator; + $this->rootDir = $rootDir; } public function getGlobals() @@ -48,6 +50,7 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface new TwigFunction('count_entries', [$this, 'countEntries']), new TwigFunction('count_tags', [$this, 'countTags']), new TwigFunction('display_stats', [$this, 'displayStats']), + new TwigFunction('asset_file_exists', [$this, 'assetFileExists']), ]; } @@ -165,6 +168,11 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface ]); } + public function assetFileExists($name) + { + return file_exists(realpath($this->rootDir . '/../web/' . $name)); + } + public function getName() { return 'wallabag_extension'; diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index 39fcec16..db02cb9c 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -25,7 +25,7 @@ class WallabagExtensionTest extends TestCase ->disableOriginalConstructor() ->getMock(); - $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, ''); $this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); @@ -50,7 +50,7 @@ class WallabagExtensionTest extends TestCase ->disableOriginalConstructor() ->getMock(); - $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, ''); $this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr')); $this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com')); @@ -75,7 +75,7 @@ class WallabagExtensionTest extends TestCase ->disableOriginalConstructor() ->getMock(); - $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, ''); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); -- 2.41.0