Add site setting to pick dark mode color scheme (#10390)

Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
Penar Musaraj 2020-08-07 08:52:47 -04:00 committed by GitHub
parent b86198198f
commit 9c9aa21726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View 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

View File

@ -1834,6 +1834,8 @@ en:
desktop_category_page_style: "Visual style for the /categories page."
category_colors: "A list of hexadecimal color values allowed for categories."
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_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."

View File

@ -247,7 +247,8 @@ basic:
hidden: true
default_dark_mode_color_scheme_id:
default: -1
hidden: true
type: enum
enum: "ColorSchemeSetting"
client: true
relative_date_duration:
client: true

View File

@ -364,8 +364,10 @@ describe ApplicationHelper do
expect(cs_stylesheets.scan("stylesheets/color_definitions").size).to eq(2)
end
it 'fails gracefully when the dark color scheme ID is set but missing' do
SiteSetting.default_dark_mode_color_scheme_id = -5
it 'handles a missing dark color scheme gracefully' do
scheme = ColorScheme.create!(name: "pyramid")
SiteSetting.default_dark_mode_color_scheme_id = scheme.id
scheme.destroy!
cs_stylesheets = helper.discourse_color_scheme_stylesheets
expect(cs_stylesheets).to include("stylesheets/color_definitions")