]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Load custom.css only if exists 4272/head
authorSimounet <contact@simounet.net>
Wed, 29 Jan 2020 21:26:00 +0000 (22:26 +0100)
committerSimounet <contact@simounet.net>
Fri, 7 Feb 2020 12:21:48 +0000 (13:21 +0100)
GNUmakefile
app/config/services.yml
src/Wallabag/CoreBundle/Resources/views/base.html.twig
src/Wallabag/CoreBundle/Twig/WallabagExtension.php
tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php

index 837f7103fd94cdeb6d0ae880384d680aa8c2fb2d..d0894dbbf85c9637120e47e0a4d22ae3f1db0f9a 100755 (executable)
@@ -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
index 25bbe5dc007d4e4fc11c01c11e2aed42a059c2c2..c2c867cf04dde5dc88749bf9b79172403c214a79 100644 (file)
@@ -16,6 +16,7 @@ services:
             - "@security.token_storage"
             - "%wallabag_core.cache_lifetime%"
             - "@translator"
+            - "%kernel.root_dir%"
         tags:
             - { name: twig.extension }
 
index 496b3fb6b652f283ef6e54f066edf0b0b3c2f41a..2486172d5f6be810376cab683ecd0bb6248e3d29 100644 (file)
@@ -44,7 +44,9 @@
 
             {% block css %}
             {% endblock %}
-            <link rel="stylesheet" href="{{ asset('custom.css') }}">
+            {% if asset_file_exists('custom.css') %}
+                <link rel="stylesheet" href="{{ asset('custom.css') }}">
+            {% endif %}
             {% block scripts %}
             <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
             <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
index 02f17f50a58b52b2dc5d0b6c2af765e58506ecef..47af3c8ec69afb6028bd5b08f05a488b5af5c2a5 100644 (file)
@@ -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';
index 39fcec16549de127b15a7c12779569efda59632f..db02cb9cf18992f1f63c66216e98899ace8a7e52 100644 (file)
@@ -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'));