DEV: Live refresh all themes when watching stylesheets (#10337)
This commit is contained in:
parent
3d9eb3e085
commit
e6dbb4fcf5
|
@ -48,16 +48,6 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
layout :set_layout
|
layout :set_layout
|
||||||
|
|
||||||
if Rails.env == "development"
|
|
||||||
after_action :remember_theme_id
|
|
||||||
|
|
||||||
def remember_theme_id
|
|
||||||
if @theme_ids.present? && request.format == "html"
|
|
||||||
Stylesheet::Watcher.theme_id = @theme_ids.first if defined? Stylesheet::Watcher
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_escaped_fragment?
|
def has_escaped_fragment?
|
||||||
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
|
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,15 +4,6 @@ require 'listen'
|
||||||
|
|
||||||
module Stylesheet
|
module Stylesheet
|
||||||
class Watcher
|
class Watcher
|
||||||
REDIS_KEY = "dev_last_used_theme_id"
|
|
||||||
|
|
||||||
def self.theme_id=(v)
|
|
||||||
Discourse.redis.set(REDIS_KEY, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.theme_id
|
|
||||||
(Discourse.redis.get(REDIS_KEY) || SiteSetting.default_theme_id).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.watch(paths = nil)
|
def self.watch(paths = nil)
|
||||||
watcher = new(paths)
|
watcher = new(paths)
|
||||||
|
@ -106,7 +97,11 @@ module Stylesheet
|
||||||
targets = target ? [target] : ["desktop", "mobile", "admin"]
|
targets = target ? [target] : ["desktop", "mobile", "admin"]
|
||||||
Stylesheet::Manager.clear_core_cache!(targets)
|
Stylesheet::Manager.clear_core_cache!(targets)
|
||||||
message = targets.map! do |name|
|
message = targets.map! do |name|
|
||||||
Stylesheet::Manager.stylesheet_data(name.to_sym, Stylesheet::Watcher.theme_id)
|
msgs = []
|
||||||
|
active_themes.each do |theme_id|
|
||||||
|
msgs << Stylesheet::Manager.stylesheet_data(name.to_sym, theme_id)
|
||||||
|
end
|
||||||
|
msgs
|
||||||
end.flatten!
|
end.flatten!
|
||||||
MessageBus.publish '/file-change', message
|
MessageBus.publish '/file-change', message
|
||||||
end
|
end
|
||||||
|
@ -118,7 +113,10 @@ module Stylesheet
|
||||||
targets.push("#{plugin_name}_desktop") if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, :desktop)
|
targets.push("#{plugin_name}_desktop") if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, :desktop)
|
||||||
|
|
||||||
message = targets.map! do |name|
|
message = targets.map! do |name|
|
||||||
Stylesheet::Manager.stylesheet_data(name.to_sym, Stylesheet::Watcher.theme_id)
|
msgs = []
|
||||||
|
active_themes.each do |theme_id|
|
||||||
|
msgs << Stylesheet::Manager.stylesheet_data(name.to_sym, theme_id)
|
||||||
|
end
|
||||||
end.flatten!
|
end.flatten!
|
||||||
MessageBus.publish '/file-change', message
|
MessageBus.publish '/file-change', message
|
||||||
end
|
end
|
||||||
|
@ -144,5 +142,10 @@ module Stylesheet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def active_themes
|
||||||
|
@active_themes ||= Theme.user_selectable.pluck(:id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue