mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Theme settings (2) (#5611)
Allows theme authors to specify custom theme settings for the theme. Centralizes the theme/site settings into a single construct
This commit is contained in:
@@ -39,6 +39,7 @@ module Stylesheet
|
||||
colors.each do |n, hex|
|
||||
contents << "$#{n}: ##{hex} !default;\n"
|
||||
end
|
||||
|
||||
theme&.all_theme_variables&.each do |field|
|
||||
if field.type_id == ThemeField.types[:theme_upload_var]
|
||||
if upload = field.upload
|
||||
@@ -46,11 +47,14 @@ module Stylesheet
|
||||
contents << "$#{field.name}: unquote(\"#{url}\");\n"
|
||||
end
|
||||
else
|
||||
escaped = field.value.gsub('"', "\\22")
|
||||
escaped.gsub!("\n", "\\A")
|
||||
contents << "$#{field.name}: unquote(\"#{escaped}\");\n"
|
||||
contents << to_scss_variable(field.name, field.value)
|
||||
end
|
||||
end
|
||||
|
||||
theme&.included_settings&.each do |name, value|
|
||||
contents << to_scss_variable(name, value)
|
||||
end
|
||||
|
||||
Import.new("theme_variable.scss", source: contents)
|
||||
end
|
||||
|
||||
@@ -132,6 +136,12 @@ COMMENT
|
||||
"body.category-#{category.full_slug} { background-image: url(#{upload_cdn_path(category.uploaded_background.url)}) }\n"
|
||||
end
|
||||
|
||||
def to_scss_variable(name, value)
|
||||
escaped = value.to_s.gsub('"', "\\22")
|
||||
escaped.gsub!("\n", "\\A")
|
||||
"$#{name}: unquote(\"#{escaped}\");\n"
|
||||
end
|
||||
|
||||
def imports(asset, parent_path)
|
||||
if asset[-1] == "*"
|
||||
Dir["#{Stylesheet::ASSET_ROOT}/#{asset}.scss"].map do |path|
|
||||
|
@@ -252,7 +252,11 @@ class Stylesheet::Manager
|
||||
raise "attempting to look up theme digest for invalid field"
|
||||
end
|
||||
|
||||
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s)
|
||||
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s + settings_digest)
|
||||
end
|
||||
|
||||
def settings_digest
|
||||
Digest::SHA1.hexdigest((theme&.included_settings || {}).to_json)
|
||||
end
|
||||
|
||||
def color_scheme_digest
|
||||
|
Reference in New Issue
Block a user