mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 05:29:30 +08:00
DEV: Remove child theme settings/variables from parent compilation (#16001)
aa1442fdc3
split theme stylesheets so that every component gets its own stylesheet. Therefore, there is now no need for parent themes to collate the settings/variables of its children during scss compilation.
Technically this is a breaking change for any themes which depend on the settings/variables of their child components. That was never a supported/recommended arrangement, so we don't expect this to cause issues.
This commit is contained in:
parent
c8d956374d
commit
5d6d3fb244
|
@ -470,16 +470,6 @@ class Theme < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_theme_variables
|
|
||||||
fields = {}
|
|
||||||
ids = Theme.transform_ids(id)
|
|
||||||
ThemeField.find_by_theme_ids(ids).where(type_id: ThemeField.theme_var_type_ids).each do |field|
|
|
||||||
next if fields.key?(field.name)
|
|
||||||
fields[field.name] = field
|
|
||||||
end
|
|
||||||
fields.values
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_relative_theme!(kind, theme)
|
def add_relative_theme!(kind, theme)
|
||||||
new_relation = if kind == :child
|
new_relation = if kind == :child
|
||||||
child_theme_relation.new(child_theme_id: theme.id)
|
child_theme_relation.new(child_theme_id: theme.id)
|
||||||
|
@ -559,17 +549,6 @@ class Theme < ActiveRecord::Base
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def included_settings
|
|
||||||
hash = {}
|
|
||||||
|
|
||||||
Theme.where(id: Theme.transform_ids(id)).each do |theme|
|
|
||||||
hash.merge!(theme.build_settings_hash)
|
|
||||||
end
|
|
||||||
|
|
||||||
hash.merge!(self.build_settings_hash)
|
|
||||||
hash
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_setting(setting_name, new_value)
|
def update_setting(setting_name, new_value)
|
||||||
target_setting = settings.find { |setting| setting.name == setting_name }
|
target_setting = settings.find { |setting| setting.name == setting_name }
|
||||||
raise Discourse::NotFound unless target_setting
|
raise Discourse::NotFound unless target_setting
|
||||||
|
@ -654,11 +633,14 @@ class Theme < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def scss_variables
|
def scss_variables
|
||||||
return if all_theme_variables.empty? && included_settings.empty?
|
settings_hash = build_settings_hash
|
||||||
|
theme_variable_fields = var_theme_fields
|
||||||
|
|
||||||
|
return if theme_variable_fields.empty? && settings_hash.empty?
|
||||||
|
|
||||||
contents = +""
|
contents = +""
|
||||||
|
|
||||||
all_theme_variables&.each do |field|
|
theme_variable_fields&.each do |field|
|
||||||
if field.type_id == ThemeField.types[:theme_upload_var]
|
if field.type_id == ThemeField.types[:theme_upload_var]
|
||||||
if upload = field.upload
|
if upload = field.upload
|
||||||
url = upload_cdn_path(upload.url)
|
url = upload_cdn_path(upload.url)
|
||||||
|
@ -669,7 +651,7 @@ class Theme < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
included_settings&.each do |name, value|
|
settings_hash&.each do |name, value|
|
||||||
next if name == "theme_uploads"
|
next if name == "theme_uploads"
|
||||||
contents << to_scss_variable(name, value)
|
contents << to_scss_variable(name, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -565,36 +565,6 @@ HTML
|
||||||
expect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")
|
expect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles child settings correctly' do
|
|
||||||
Theme.destroy_all
|
|
||||||
|
|
||||||
expect(included_settings(theme.id)).to eq("{}")
|
|
||||||
|
|
||||||
theme.set_field(target: :settings, name: "yaml", value: "boolean_setting: true")
|
|
||||||
theme.save!
|
|
||||||
expect(included_settings(theme.id)).to match(/\"boolean_setting\":true/)
|
|
||||||
|
|
||||||
theme.settings.first.value = "false"
|
|
||||||
theme.save!
|
|
||||||
expect(included_settings(theme.id)).to match(/\"boolean_setting\":false/)
|
|
||||||
|
|
||||||
child.set_field(target: :settings, name: "yaml", value: "integer_setting: 54")
|
|
||||||
|
|
||||||
child.save!
|
|
||||||
theme.add_relative_theme!(:child, child)
|
|
||||||
|
|
||||||
json = included_settings(theme.id)
|
|
||||||
expect(json).to match(/\"boolean_setting\":false/)
|
|
||||||
expect(json).to match(/\"integer_setting\":54/)
|
|
||||||
|
|
||||||
expect(included_settings(child.id)).to eq("{\"integer_setting\":54}")
|
|
||||||
|
|
||||||
child.destroy!
|
|
||||||
json = included_settings(theme.id)
|
|
||||||
expect(json).not_to match(/\"integer_setting\":54/)
|
|
||||||
expect(json).to match(/\"boolean_setting\":false/)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "convert_settings" do
|
describe "convert_settings" do
|
||||||
|
|
||||||
it 'can migrate a list field to a string field with json schema' do
|
it 'can migrate a list field to a string field with json schema' do
|
||||||
|
|
|
@ -650,7 +650,7 @@ describe Admin::ThemesController do
|
||||||
expect(response.parsed_body["bg"]).to eq("green")
|
expect(response.parsed_body["bg"]).to eq("green")
|
||||||
|
|
||||||
theme.reload
|
theme.reload
|
||||||
expect(theme.included_settings[:bg]).to eq("green")
|
expect(theme.cached_settings[:bg]).to eq("green")
|
||||||
user_history = UserHistory.last
|
user_history = UserHistory.last
|
||||||
|
|
||||||
expect(user_history.action).to eq(
|
expect(user_history.action).to eq(
|
||||||
|
@ -663,7 +663,7 @@ describe Admin::ThemesController do
|
||||||
theme.reload
|
theme.reload
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(theme.included_settings[:bg]).to eq("")
|
expect(theme.cached_settings[:bg]).to eq("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user