mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
better support for multi host in site customization
This commit is contained in:
parent
4b0eec334f
commit
6fb78809c2
@ -106,6 +106,7 @@ footer:after{ content: '#{error}' }"
|
|||||||
|
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
style = self.where(key: key).first
|
style = self.where(key: key).first
|
||||||
|
style.ensure_stylesheet_on_disk!
|
||||||
@cache[key] = style
|
@cache[key] = style
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -140,9 +141,13 @@ footer:after{ content: '#{error}' }"
|
|||||||
Digest::MD5.hexdigest(self.stylesheet)
|
Digest::MD5.hexdigest(self.stylesheet)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache_fullpath
|
||||||
|
"#{Rails.root}/public/#{CACHE_PATH}"
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_stylesheet_on_disk!
|
def ensure_stylesheet_on_disk!
|
||||||
path = stylesheet_fullpath
|
path = stylesheet_fullpath
|
||||||
dir = "#{Rails.root}/public/#{CACHE_PATH}"
|
dir = cache_fullpath
|
||||||
FileUtils.mkdir_p(dir)
|
FileUtils.mkdir_p(dir)
|
||||||
unless File.exists?(path)
|
unless File.exists?(path)
|
||||||
File.open(path, "w") do |f|
|
File.open(path, "w") do |f|
|
||||||
@ -152,23 +157,18 @@ footer:after{ content: '#{error}' }"
|
|||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_filename
|
def stylesheet_filename
|
||||||
file = ""
|
"/#{self.key}.css"
|
||||||
dir = "#{Rails.root}/public/#{CACHE_PATH}"
|
|
||||||
path = dir + file
|
|
||||||
|
|
||||||
"/#{CACHE_PATH}/#{self.key}.css"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_fullpath
|
def stylesheet_fullpath
|
||||||
"#{Rails.root}/public#{self.stylesheet_filename}"
|
"#{self.cache_fullpath}#{self.stylesheet_filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_link_tag
|
def stylesheet_link_tag
|
||||||
return "" unless self.stylesheet.present?
|
return "" unless self.stylesheet.present?
|
||||||
return @stylesheet_link_tag if @stylesheet_link_tag
|
return @stylesheet_link_tag if @stylesheet_link_tag
|
||||||
ensure_stylesheet_on_disk!
|
ensure_stylesheet_on_disk!
|
||||||
@stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"#{self.stylesheet_filename}?#{self.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
@stylesheet_link_tag = "<link class=\"custom-css\" rel=\"stylesheet\" href=\"/#{CACHE_PATH}#{self.stylesheet_filename}?#{self.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -26,6 +26,7 @@ describe SiteCustomization do
|
|||||||
SiteCustomization.enabled_style_key.should be_nil
|
SiteCustomization.enabled_style_key.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'finds the enabled style' do
|
it 'finds the enabled style' do
|
||||||
@customization.enabled = true
|
@customization.enabled = true
|
||||||
@customization.save
|
@customization.save
|
||||||
@ -45,6 +46,16 @@ describe SiteCustomization do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'ensure stylesheet is on disk on first fetch' do
|
||||||
|
c = customization
|
||||||
|
c.remove_from_cache!
|
||||||
|
File.delete(c.stylesheet_fullpath)
|
||||||
|
|
||||||
|
SiteCustomization.custom_stylesheet(c.key)
|
||||||
|
File.exists?(c.stylesheet_fullpath).should == true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it 'should allow me to lookup a filename containing my preview stylesheet' do
|
it 'should allow me to lookup a filename containing my preview stylesheet' do
|
||||||
SiteCustomization.custom_stylesheet(customization.key).should ==
|
SiteCustomization.custom_stylesheet(customization.key).should ==
|
||||||
"<link class=\"custom-css\" rel=\"stylesheet\" href=\"/stylesheet-cache/#{customization.key}.css?#{customization.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
"<link class=\"custom-css\" rel=\"stylesheet\" href=\"/stylesheet-cache/#{customization.key}.css?#{customization.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
||||||
|
Loading…
Reference in New Issue
Block a user