mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
correct watcher so it handles color scheme changes correctly
This commit is contained in:
parent
bbeb69ddc9
commit
0a67d859d5
6 changed files with 40 additions and 34 deletions
|
@ -19,6 +19,13 @@ class Stylesheet::Manager
|
|||
cache.hash.keys.select{|k| k =~ /theme/}.each{|k|cache.delete(k)}
|
||||
end
|
||||
|
||||
def self.stylesheet_href(target = :desktop, theme_key = :missing)
|
||||
href = stylesheet_link_tag(target, 'all', theme_key)
|
||||
if href
|
||||
href.split(/["']/)[1]
|
||||
end
|
||||
end
|
||||
|
||||
def self.stylesheet_link_tag(target = :desktop, media = 'all', theme_key = :missing)
|
||||
|
||||
target = target.to_sym
|
||||
|
@ -35,8 +42,7 @@ class Stylesheet::Manager
|
|||
@lock.synchronize do
|
||||
builder = self.new(target, theme_key)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
builder.ensure_digestless_file
|
||||
tag = %[<link href="#{builder.stylesheet_path}" media="#{media}" rel="stylesheet" data-target="#{target}" rel="preload"/>]
|
||||
tag = %[<link href="#{builder.stylesheet_path}" media="#{media}" rel="stylesheet" data-target="#{target}"/>]
|
||||
cache[cache_key] = tag
|
||||
|
||||
tag.dup.html_safe
|
||||
|
@ -142,13 +148,6 @@ class Stylesheet::Manager
|
|||
css
|
||||
end
|
||||
|
||||
def ensure_digestless_file
|
||||
# file without digest is only for auto-reloading css in dev env
|
||||
unless Rails.env.production? || (File.exist?(stylesheet_fullpath_no_digest) && File.mtime(stylesheet_fullpath) == File.mtime(stylesheet_fullpath_no_digest))
|
||||
FileUtils.cp(stylesheet_fullpath, stylesheet_fullpath_no_digest)
|
||||
end
|
||||
end
|
||||
|
||||
def self.cache_fullpath
|
||||
"#{Rails.root}/#{CACHE_PATH}"
|
||||
end
|
||||
|
@ -178,15 +177,7 @@ class Stylesheet::Manager
|
|||
end
|
||||
|
||||
def stylesheet_path
|
||||
if Rails.env.development?
|
||||
if @target.to_s =~ /theme/
|
||||
stylesheet_relpath
|
||||
else
|
||||
stylesheet_relpath_no_digest
|
||||
end
|
||||
else
|
||||
stylesheet_cdnpath
|
||||
end
|
||||
stylesheet_cdnpath
|
||||
end
|
||||
|
||||
def root_path
|
||||
|
|
|
@ -52,11 +52,12 @@ module Stylesheet
|
|||
@queue.pop
|
||||
end
|
||||
|
||||
Stylesheet::Manager.cache.clear
|
||||
|
||||
message = ["desktop", "mobile", "admin"].map do |name|
|
||||
{hash: SecureRandom.hex, name: "/stylesheets/#{name}.css"}
|
||||
{target: name, new_href: Stylesheet::Manager.stylesheet_href(name.to_sym) , theme_key: SiteSetting.default_theme_key}
|
||||
end
|
||||
|
||||
Stylesheet::Manager.cache.clear
|
||||
MessageBus.publish '/file-change', message
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue