mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 08:51:52 +08:00
DEV: Backend support for light/dark mode in color palettes (#30893)
We're embarking on a project for overhauling the color palette and theme systems in Discourse. As part of this project, we're making each color palette include light and dark modes instead of the status quo of requiring 2 separate color palettes to implement light and dark modes. This commit is a first step towards that goal; it adds a code path for generating and serving `color_definitions` stylesheets using the built-in dark variant of a color palette. All of this code path is behind a default-off site setting `use_overhauled_theme_color_palette`, so there's no change in behavior unless the setting is enabled. Internal topic: t/141467.
This commit is contained in:
@ -3,11 +3,12 @@
|
||||
class Stylesheet::Manager::Builder
|
||||
attr_reader :theme
|
||||
|
||||
def initialize(target: :desktop, theme: nil, color_scheme: nil, manager:)
|
||||
def initialize(target: :desktop, theme: nil, color_scheme: nil, manager:, dark: false)
|
||||
@target = target
|
||||
@theme = theme
|
||||
@color_scheme = color_scheme
|
||||
@manager = manager
|
||||
@dark = dark
|
||||
end
|
||||
|
||||
def compile(opts = {})
|
||||
@ -46,6 +47,7 @@ class Stylesheet::Manager::Builder
|
||||
source_map_file: source_map_url_relative_from_stylesheet,
|
||||
color_scheme_id: @color_scheme&.id,
|
||||
load_paths: load_paths,
|
||||
dark: @dark,
|
||||
)
|
||||
rescue SassC::SyntaxError, SassC::NotRenderedError => e
|
||||
if Stylesheet::Importer::THEME_TARGETS.include?(@target.to_s)
|
||||
@ -119,13 +121,14 @@ class Stylesheet::Manager::Builder
|
||||
end
|
||||
|
||||
def qualified_target
|
||||
dark_string = @dark ? "_dark" : ""
|
||||
if is_theme?
|
||||
"#{@target}_#{theme&.id}"
|
||||
elsif @color_scheme
|
||||
"#{@target}_#{scheme_slug}_#{@color_scheme&.id}_#{@theme&.id}"
|
||||
"#{@target}_#{scheme_slug}_#{@color_scheme&.id}_#{@theme&.id}#{dark_string}"
|
||||
else
|
||||
scheme_string = theme&.color_scheme ? "_#{theme.color_scheme.id}" : ""
|
||||
"#{@target}#{scheme_string}"
|
||||
"#{@target}#{scheme_string}#{dark_string}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -245,8 +248,9 @@ class Stylesheet::Manager::Builder
|
||||
digest_string = "#{current_hostname}-"
|
||||
if cs
|
||||
theme_color_defs = resolve_baked_field(:common, :color_definitions)
|
||||
dark_string = @dark ? "-dark" : ""
|
||||
digest_string +=
|
||||
"#{RailsMultisite::ConnectionManagement.current_db}-#{cs&.id}-#{cs&.version}-#{theme_color_defs}-#{Stylesheet::Manager.fs_asset_cachebuster}-#{fonts}"
|
||||
"#{RailsMultisite::ConnectionManagement.current_db}-#{cs&.id}-#{cs&.version}-#{theme_color_defs}-#{Stylesheet::Manager.fs_asset_cachebuster}-#{fonts}#{dark_string}"
|
||||
else
|
||||
digest_string += "defaults-#{Stylesheet::Manager.fs_asset_cachebuster}-#{fonts}"
|
||||
|
||||
|
Reference in New Issue
Block a user