From 3da9b99dbf323ac6b98bafa9f35fb2a27dd82d63 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 16 Sep 2019 14:56:19 +0100 Subject: [PATCH] FIX: Live reload plugin stylesheets when the color scheme changes --- app/models/theme.rb | 1 + .../common/_discourse_stylesheet.html.erb | 2 +- lib/discourse.rb | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index c4bda99cc7a..613af2069dc 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -264,6 +264,7 @@ class Theme < ActiveRecord::Base if with_scheme targets.prepend(:desktop, :mobile, :admin) + targets.append(*Discourse.find_plugin_css_assets(mobile_view: true, desktop_view: true)) Stylesheet::Manager.cache.clear if clear_manager_cache end diff --git a/app/views/common/_discourse_stylesheet.html.erb b/app/views/common/_discourse_stylesheet.html.erb index 690f3a2711b..b6f64114e70 100644 --- a/app/views/common/_discourse_stylesheet.html.erb +++ b/app/views/common/_discourse_stylesheet.html.erb @@ -12,6 +12,6 @@ <%= discourse_stylesheet_link_tag(mobile_view? ? :mobile_theme : :desktop_theme) %> <%- end %> -<%- Discourse.find_plugin_css_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, mobile_view: mobile_view?).each do |file| %> +<%- Discourse.find_plugin_css_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, mobile_view: mobile_view?, desktop_view: !mobile_view?).each do |file| %> <%= discourse_stylesheet_link_tag(file) %> <%- end %> diff --git a/lib/discourse.rb b/lib/discourse.rb index d44f028c71c..ca603be0765 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -217,14 +217,19 @@ module Discourse def self.find_plugin_css_assets(args) plugins = self.find_plugins(args) - assets = plugins.find_all do |plugin| - plugin.css_asset_exists? - end.map { |plugin| plugin.directory_name } + assets = [] - target = args[:mobile_view] ? :mobile : :desktop - assets += plugins.find_all do |plugin| - plugin.css_asset_exists?(target) - end.map { |plugin| "#{plugin.directory_name}_#{target}" } + targets = [nil] + targets << :mobile if args[:mobile_view] + targets << :desktop if args[:desktop_view] + + targets.each do |target| + assets += plugins.find_all do |plugin| + plugin.css_asset_exists?(target) + end.map do |plugin| + target.nil? ? plugin.directory_name : "#{plugin.directory_name}_#{target}" + end + end assets end