discourse/db/fixtures/600_themes.rb
Krzysztof Kotlarek a609e3421c
FIX: Allow creating new color palettes based on custom palettes (#34351)
This commit:
- Changes `base_scheme_id`column from string to integer
- Migrate existing color schemes to use new type
- Modifies color palette selection to work with both base and custom
palettes
- Improves translation fallbacks for color scheme names/descriptions


https://github.com/user-attachments/assets/3d8a2fc6-50f7-42d7-840e-6e9dfb0f2474

---------

Co-authored-by: Osama Sayegh <asooomaasoooma90@gmail.com>
2025-08-20 11:58:40 +08:00

35 lines
1.3 KiB
Ruby

# frozen_string_literal: true
theme_exists = Theme.exists?
SystemThemesManager.sync!
# we can not guess what to do if customization already started, so skip it
if !theme_exists
STDERR.puts "> Seeding theme and color schemes"
color_schemes = [
{ name: I18n.t("color_schemes.dark"), base_scheme_name: "Dark" },
{ name: I18n.t("color_schemes.wcag"), base_scheme_name: "WCAG" },
{ name: I18n.t("color_schemes.wcag_dark"), base_scheme_name: "WCAG Dark" },
{ name: I18n.t("color_schemes.dracula"), base_scheme_name: "Dracula" },
{ name: I18n.t("color_schemes.solarized_light"), base_scheme_name: "Solarized Light" },
{ name: I18n.t("color_schemes.solarized_dark"), base_scheme_name: "Solarized Dark" },
]
color_schemes.each do |cs|
scheme =
ColorScheme.find_by(base_scheme_id: ColorScheme::NAMES_TO_ID_MAP[cs[:base_scheme_name]])
scheme ||=
ColorScheme.create_from_base(
name: cs[:name],
via_wizard: true,
base_scheme_id: ColorScheme::NAMES_TO_ID_MAP[cs[:base_scheme_name]],
)
end
Theme.foundation_theme.set_default!
dark_scheme_id = ColorScheme.where(base_scheme_id: ColorScheme::NAMES_TO_ID_MAP["Dark"]).pick(:id)
Theme.foundation_theme.update!(dark_color_scheme_id: dark_scheme_id) if dark_scheme_id.present?
end