mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow themes to specify modifiers in their about.json file (#9097)
There are three modifiers: - serialize_topic_excerpts (boolean) - csp_extensions (array of strings) - svg_icons (array of strings) When multiple themes are active, the values will be combined. The combination method varies based on the setting. CSP/SVG arrays will be combined. serialize_topic_excerpts will use `Enumerable#any`.
This commit is contained in:
@@ -37,6 +37,9 @@ describe RemoteTheme do
|
||||
"love": "#{love_color}",
|
||||
"tertiary-low": "#{tertiary_low_color}"
|
||||
}
|
||||
},
|
||||
"modifiers": {
|
||||
"serialize_topic_excerpts": true
|
||||
}
|
||||
}
|
||||
JSON
|
||||
@@ -85,6 +88,8 @@ describe RemoteTheme do
|
||||
expect(remote.theme_version).to eq("1.0")
|
||||
expect(remote.minimum_discourse_version).to eq("1.0.0")
|
||||
|
||||
expect(@theme.theme_modifier_set.serialize_topic_excerpts).to eq(true)
|
||||
|
||||
expect(@theme.theme_fields.length).to eq(9)
|
||||
|
||||
mapped = Hash[*@theme.theme_fields.map { |f| ["#{f.target_id}-#{f.name}", f.value] }.flatten]
|
||||
|
||||
24
spec/models/theme_modifier_set_spec.rb
Normal file
24
spec/models/theme_modifier_set_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
require 'rails_helper'
|
||||
|
||||
describe ThemeModifierSet do
|
||||
describe "#resolve_modifiers_for_themes" do
|
||||
it "returns nil for unknown modifier" do
|
||||
expect(ThemeModifierSet.resolve_modifier_for_themes([1, 2], :unknown_modifier)).to eq(nil)
|
||||
end
|
||||
|
||||
it "resolves serialize_topic_excerpts correctly" do
|
||||
t1 = Fabricate(:theme)
|
||||
t1.theme_modifier_set.update!(serialize_topic_excerpts: true)
|
||||
t2 = Fabricate(:theme)
|
||||
t2.theme_modifier_set.update!(serialize_topic_excerpts: false)
|
||||
|
||||
expect(ThemeModifierSet.resolve_modifier_for_themes([t1.id, t2.id], :serialize_topic_excerpts)).to eq(true)
|
||||
|
||||
t1 = Fabricate(:theme)
|
||||
t1.theme_modifier_set.update!(serialize_topic_excerpts: nil)
|
||||
|
||||
expect(ThemeModifierSet.resolve_modifier_for_themes([t1.id, t2.id], :serialize_topic_excerpts)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user