mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add site setting to pick dark mode color scheme (#10390)
Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
17
app/models/color_scheme_setting.rb
Normal file
17
app/models/color_scheme_setting.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ColorSchemeSetting < EnumSiteSetting
|
||||||
|
|
||||||
|
def self.valid_value?(val)
|
||||||
|
val == -1 || ColorScheme.find_by_id(val)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.values
|
||||||
|
values = [{ name: I18n.t("site_settings.dark_mode_none"), value: -1 }]
|
||||||
|
ColorScheme.all.map do |c|
|
||||||
|
values << { name: c.name, value: c.id }
|
||||||
|
end
|
||||||
|
values
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1834,6 +1834,8 @@ en:
|
|||||||
desktop_category_page_style: "Visual style for the /categories page."
|
desktop_category_page_style: "Visual style for the /categories page."
|
||||||
category_colors: "A list of hexadecimal color values allowed for categories."
|
category_colors: "A list of hexadecimal color values allowed for categories."
|
||||||
category_style: "Visual style for category badges."
|
category_style: "Visual style for category badges."
|
||||||
|
default_dark_mode_color_scheme_id: "The color scheme used when in dark mode."
|
||||||
|
dark_mode_none: "None"
|
||||||
|
|
||||||
max_image_size_kb: "The maximum image upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well. Images larger than this and smaller than client_max_body_size will be resized to fit on upload."
|
max_image_size_kb: "The maximum image upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well. Images larger than this and smaller than client_max_body_size will be resized to fit on upload."
|
||||||
max_attachment_size_kb: "The maximum attachment files upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well."
|
max_attachment_size_kb: "The maximum attachment files upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well."
|
||||||
|
|||||||
@@ -247,7 +247,8 @@ basic:
|
|||||||
hidden: true
|
hidden: true
|
||||||
default_dark_mode_color_scheme_id:
|
default_dark_mode_color_scheme_id:
|
||||||
default: -1
|
default: -1
|
||||||
hidden: true
|
type: enum
|
||||||
|
enum: "ColorSchemeSetting"
|
||||||
client: true
|
client: true
|
||||||
relative_date_duration:
|
relative_date_duration:
|
||||||
client: true
|
client: true
|
||||||
|
|||||||
@@ -364,8 +364,10 @@ describe ApplicationHelper do
|
|||||||
expect(cs_stylesheets.scan("stylesheets/color_definitions").size).to eq(2)
|
expect(cs_stylesheets.scan("stylesheets/color_definitions").size).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails gracefully when the dark color scheme ID is set but missing' do
|
it 'handles a missing dark color scheme gracefully' do
|
||||||
SiteSetting.default_dark_mode_color_scheme_id = -5
|
scheme = ColorScheme.create!(name: "pyramid")
|
||||||
|
SiteSetting.default_dark_mode_color_scheme_id = scheme.id
|
||||||
|
scheme.destroy!
|
||||||
cs_stylesheets = helper.discourse_color_scheme_stylesheets
|
cs_stylesheets = helper.discourse_color_scheme_stylesheets
|
||||||
|
|
||||||
expect(cs_stylesheets).to include("stylesheets/color_definitions")
|
expect(cs_stylesheets).to include("stylesheets/color_definitions")
|
||||||
|
|||||||
Reference in New Issue
Block a user