mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to app/*
This commit is contained in:
@@ -1,173 +1,172 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ColorScheme < ActiveRecord::Base
|
||||
|
||||
# rubocop:disable Layout/HashAlignment
|
||||
|
||||
CUSTOM_SCHEMES = {
|
||||
'Dark': {
|
||||
"primary" => 'dddddd',
|
||||
"secondary" => '222222',
|
||||
"tertiary" => '0f82af',
|
||||
"quaternary" => 'c14924',
|
||||
"header_background" => '111111',
|
||||
"header_primary" => 'dddddd',
|
||||
"highlight" => 'a87137',
|
||||
"danger" => 'e45735',
|
||||
"success" => '1ca551',
|
||||
"love" => 'fa6c8d'
|
||||
Dark: {
|
||||
"primary" => "dddddd",
|
||||
"secondary" => "222222",
|
||||
"tertiary" => "0f82af",
|
||||
"quaternary" => "c14924",
|
||||
"header_background" => "111111",
|
||||
"header_primary" => "dddddd",
|
||||
"highlight" => "a87137",
|
||||
"danger" => "e45735",
|
||||
"success" => "1ca551",
|
||||
"love" => "fa6c8d",
|
||||
},
|
||||
# By @itsbhanusharma
|
||||
'Neutral': {
|
||||
"primary" => '000000',
|
||||
"secondary" => 'ffffff',
|
||||
"tertiary" => '51839b',
|
||||
"quaternary" => 'b85e48',
|
||||
"header_background" => '333333',
|
||||
"header_primary" => 'f3f3f3',
|
||||
"highlight" => 'ecec70',
|
||||
"danger" => 'b85e48',
|
||||
"success" => '518751',
|
||||
"love" => 'fa6c8d'
|
||||
Neutral: {
|
||||
"primary" => "000000",
|
||||
"secondary" => "ffffff",
|
||||
"tertiary" => "51839b",
|
||||
"quaternary" => "b85e48",
|
||||
"header_background" => "333333",
|
||||
"header_primary" => "f3f3f3",
|
||||
"highlight" => "ecec70",
|
||||
"danger" => "b85e48",
|
||||
"success" => "518751",
|
||||
"love" => "fa6c8d",
|
||||
},
|
||||
# By @Flower_Child
|
||||
'Grey Amber': {
|
||||
"primary" => 'd9d9d9',
|
||||
"secondary" => '3d4147',
|
||||
"tertiary" => 'fdd459',
|
||||
"quaternary" => 'fdd459',
|
||||
"header_background" => '36393e',
|
||||
"header_primary" => 'd9d9d9',
|
||||
"highlight" => 'fdd459',
|
||||
"danger" => 'e45735',
|
||||
"success" => 'fdd459',
|
||||
"love" => 'fdd459'
|
||||
"Grey Amber": {
|
||||
"primary" => "d9d9d9",
|
||||
"secondary" => "3d4147",
|
||||
"tertiary" => "fdd459",
|
||||
"quaternary" => "fdd459",
|
||||
"header_background" => "36393e",
|
||||
"header_primary" => "d9d9d9",
|
||||
"highlight" => "fdd459",
|
||||
"danger" => "e45735",
|
||||
"success" => "fdd459",
|
||||
"love" => "fdd459",
|
||||
},
|
||||
# By @rafafotes
|
||||
'Shades of Blue': {
|
||||
"primary" => '203243',
|
||||
"secondary" => 'eef4f7',
|
||||
"tertiary" => '416376',
|
||||
"quaternary" => '5e99b9',
|
||||
"header_background" => '86bddb',
|
||||
"header_primary" => '203243',
|
||||
"highlight" => '86bddb',
|
||||
"danger" => 'bf3c3c',
|
||||
"success" => '70db82',
|
||||
"love" => 'fc94cb'
|
||||
"Shades of Blue": {
|
||||
"primary" => "203243",
|
||||
"secondary" => "eef4f7",
|
||||
"tertiary" => "416376",
|
||||
"quaternary" => "5e99b9",
|
||||
"header_background" => "86bddb",
|
||||
"header_primary" => "203243",
|
||||
"highlight" => "86bddb",
|
||||
"danger" => "bf3c3c",
|
||||
"success" => "70db82",
|
||||
"love" => "fc94cb",
|
||||
},
|
||||
# By @mikechristopher
|
||||
'Latte': {
|
||||
"primary" => 'f2e5d7',
|
||||
"secondary" => '262322',
|
||||
"tertiary" => 'f7f2ed',
|
||||
"quaternary" => 'd7c9aa',
|
||||
"header_background" => 'd7c9aa',
|
||||
"header_primary" => '262322',
|
||||
"highlight" => 'd7c9aa',
|
||||
"danger" => 'db9584',
|
||||
"success" => '78be78',
|
||||
"love" => '8f6201'
|
||||
Latte: {
|
||||
"primary" => "f2e5d7",
|
||||
"secondary" => "262322",
|
||||
"tertiary" => "f7f2ed",
|
||||
"quaternary" => "d7c9aa",
|
||||
"header_background" => "d7c9aa",
|
||||
"header_primary" => "262322",
|
||||
"highlight" => "d7c9aa",
|
||||
"danger" => "db9584",
|
||||
"success" => "78be78",
|
||||
"love" => "8f6201",
|
||||
},
|
||||
# By @Flower_Child
|
||||
'Summer': {
|
||||
"primary" => '874342',
|
||||
"secondary" => 'fffff4',
|
||||
"tertiary" => 'fe9896',
|
||||
"quaternary" => 'fcc9d0',
|
||||
"header_background" => '96ccbf',
|
||||
"header_primary" => 'fff1e7',
|
||||
"highlight" => 'f3c07f',
|
||||
"danger" => 'cfebdc',
|
||||
"success" => 'fcb4b5',
|
||||
"love" => 'f3c07f'
|
||||
Summer: {
|
||||
"primary" => "874342",
|
||||
"secondary" => "fffff4",
|
||||
"tertiary" => "fe9896",
|
||||
"quaternary" => "fcc9d0",
|
||||
"header_background" => "96ccbf",
|
||||
"header_primary" => "fff1e7",
|
||||
"highlight" => "f3c07f",
|
||||
"danger" => "cfebdc",
|
||||
"success" => "fcb4b5",
|
||||
"love" => "f3c07f",
|
||||
},
|
||||
# By @Flower_Child
|
||||
'Dark Rose': {
|
||||
"primary" => 'ca9cb2',
|
||||
"secondary" => '3a2a37',
|
||||
"tertiary" => 'fdd459',
|
||||
"quaternary" => '7e566a',
|
||||
"header_background" => 'a97189',
|
||||
"header_primary" => 'd9b2bb',
|
||||
"highlight" => '6c3e63',
|
||||
"danger" => '6c3e63',
|
||||
"success" => 'd9b2bb',
|
||||
"love" => 'd9b2bb'
|
||||
"Dark Rose": {
|
||||
"primary" => "ca9cb2",
|
||||
"secondary" => "3a2a37",
|
||||
"tertiary" => "fdd459",
|
||||
"quaternary" => "7e566a",
|
||||
"header_background" => "a97189",
|
||||
"header_primary" => "d9b2bb",
|
||||
"highlight" => "6c3e63",
|
||||
"danger" => "6c3e63",
|
||||
"success" => "d9b2bb",
|
||||
"love" => "d9b2bb",
|
||||
},
|
||||
"WCAG": {
|
||||
"primary" => '000000',
|
||||
"primary-medium" => '696969',
|
||||
"primary-low-mid" => '909090',
|
||||
"secondary" => 'ffffff',
|
||||
"tertiary" => '3369FF',
|
||||
"quaternary" => '3369FF',
|
||||
"header_background" => 'ffffff',
|
||||
"header_primary" => '000000',
|
||||
"highlight" => '3369FF',
|
||||
"highlight-high" => '0036E6',
|
||||
"highlight-medium" => 'e0e9ff',
|
||||
"highlight-low" => 'e0e9ff',
|
||||
"danger" => 'BB1122',
|
||||
"success" => '3d854d',
|
||||
"love" => '9D256B'
|
||||
WCAG: {
|
||||
"primary" => "000000",
|
||||
"primary-medium" => "696969",
|
||||
"primary-low-mid" => "909090",
|
||||
"secondary" => "ffffff",
|
||||
"tertiary" => "3369FF",
|
||||
"quaternary" => "3369FF",
|
||||
"header_background" => "ffffff",
|
||||
"header_primary" => "000000",
|
||||
"highlight" => "3369FF",
|
||||
"highlight-high" => "0036E6",
|
||||
"highlight-medium" => "e0e9ff",
|
||||
"highlight-low" => "e0e9ff",
|
||||
"danger" => "BB1122",
|
||||
"success" => "3d854d",
|
||||
"love" => "9D256B",
|
||||
},
|
||||
"WCAG Dark": {
|
||||
"primary" => 'ffffff',
|
||||
"primary-medium" => '999999',
|
||||
"primary-low-mid" => '888888',
|
||||
"secondary" => '0c0c0c',
|
||||
"tertiary" => '759AFF',
|
||||
"quaternary" => '759AFF',
|
||||
"header_background" => '000000',
|
||||
"header_primary" => 'ffffff',
|
||||
"highlight" => '3369FF',
|
||||
"danger" => 'BB1122',
|
||||
"success" => '3d854d',
|
||||
"love" => '9D256B'
|
||||
"primary" => "ffffff",
|
||||
"primary-medium" => "999999",
|
||||
"primary-low-mid" => "888888",
|
||||
"secondary" => "0c0c0c",
|
||||
"tertiary" => "759AFF",
|
||||
"quaternary" => "759AFF",
|
||||
"header_background" => "000000",
|
||||
"header_primary" => "ffffff",
|
||||
"highlight" => "3369FF",
|
||||
"danger" => "BB1122",
|
||||
"success" => "3d854d",
|
||||
"love" => "9D256B",
|
||||
},
|
||||
# By @zenorocha
|
||||
"Dracula": {
|
||||
Dracula: {
|
||||
"primary_very_low" => "373A47",
|
||||
"primary_low" => "414350",
|
||||
"primary_low_mid" => "8C8D94",
|
||||
"primary_medium" => "A3A4AA",
|
||||
"primary_high" => "CCCCCF",
|
||||
"primary" => 'f2f2f2',
|
||||
"primary-50" => '3F414E',
|
||||
"primary-100" => '535460',
|
||||
"primary-200" => '666972',
|
||||
"primary-300" => '7A7C84',
|
||||
"primary-400" => '8D8F96',
|
||||
"primary-500" => 'A2A3A9',
|
||||
"primary-600" => 'B6B7BC',
|
||||
"primary-700" => 'C7C7C7',
|
||||
"primary-800" => 'DEDFE0',
|
||||
"primary-900" => 'F5F5F5',
|
||||
"primary" => "f2f2f2",
|
||||
"primary-50" => "3F414E",
|
||||
"primary-100" => "535460",
|
||||
"primary-200" => "666972",
|
||||
"primary-300" => "7A7C84",
|
||||
"primary-400" => "8D8F96",
|
||||
"primary-500" => "A2A3A9",
|
||||
"primary-600" => "B6B7BC",
|
||||
"primary-700" => "C7C7C7",
|
||||
"primary-800" => "DEDFE0",
|
||||
"primary-900" => "F5F5F5",
|
||||
"secondary_low" => "CCCCCF",
|
||||
"secondary_medium" => "91939A",
|
||||
"secondary_high" => "6A6C76",
|
||||
"secondary_very_high" => "3D404C",
|
||||
"secondary" => '2d303e',
|
||||
"secondary" => "2d303e",
|
||||
"tertiary_low" => "4A4463",
|
||||
"tertiary_medium" => "6E5D92",
|
||||
"tertiary" => 'bd93f9',
|
||||
"tertiary" => "bd93f9",
|
||||
"tertiary_high" => "9275C1",
|
||||
"quaternary_low" => "6AA8BA",
|
||||
"quaternary" => '8be9fd',
|
||||
"header_background" => '373A47',
|
||||
"header_primary" => 'f2f2f2',
|
||||
"quaternary" => "8be9fd",
|
||||
"header_background" => "373A47",
|
||||
"header_primary" => "f2f2f2",
|
||||
"highlight_low" => "686D55",
|
||||
"highlight_medium" => "52592B",
|
||||
"highlight" => '52592B',
|
||||
"highlight" => "52592B",
|
||||
"highlight_high" => "C0C879",
|
||||
"danger_low" => "957279",
|
||||
"danger" => 'ff5555',
|
||||
"danger" => "ff5555",
|
||||
"success_low" => "386D50",
|
||||
"success_medium" => "44B366",
|
||||
"success" => '50fa7b',
|
||||
"success" => "50fa7b",
|
||||
"love_low" => "6C4667",
|
||||
"love" => 'ff79c6'
|
||||
"love" => "ff79c6",
|
||||
},
|
||||
# By @altercation
|
||||
"Solarized Light": {
|
||||
@@ -176,40 +175,40 @@ class ColorScheme < ActiveRecord::Base
|
||||
"primary_low_mid" => "A4AFA5",
|
||||
"primary_medium" => "7E918C",
|
||||
"primary_high" => "4C6869",
|
||||
"primary" => '002B36',
|
||||
"primary-50" => 'F0EBDA',
|
||||
"primary-100" => 'DAD8CA',
|
||||
"primary-200" => 'B2B9B3',
|
||||
"primary-300" => '839496',
|
||||
"primary-400" => '76898C',
|
||||
"primary-500" => '697F83',
|
||||
"primary-600" => '627A7E',
|
||||
"primary-700" => '556F74',
|
||||
"primary-800" => '415F66',
|
||||
"primary-900" => '21454E',
|
||||
"primary" => "002B36",
|
||||
"primary-50" => "F0EBDA",
|
||||
"primary-100" => "DAD8CA",
|
||||
"primary-200" => "B2B9B3",
|
||||
"primary-300" => "839496",
|
||||
"primary-400" => "76898C",
|
||||
"primary-500" => "697F83",
|
||||
"primary-600" => "627A7E",
|
||||
"primary-700" => "556F74",
|
||||
"primary-800" => "415F66",
|
||||
"primary-900" => "21454E",
|
||||
"secondary_low" => "325458",
|
||||
"secondary_medium" => "6C8280",
|
||||
"secondary_high" => "97A59D",
|
||||
"secondary_very_high" => "E8E6D3",
|
||||
"secondary" => 'FCF6E1',
|
||||
"secondary" => "FCF6E1",
|
||||
"tertiary_low" => "D6E6DE",
|
||||
"tertiary_medium" => "7EBFD7",
|
||||
"tertiary" => '0088cc',
|
||||
"tertiary" => "0088cc",
|
||||
"tertiary_high" => "329ED0",
|
||||
"quaternary" => 'e45735',
|
||||
"header_background" => 'FCF6E1',
|
||||
"header_primary" => '002B36',
|
||||
"quaternary" => "e45735",
|
||||
"header_background" => "FCF6E1",
|
||||
"header_primary" => "002B36",
|
||||
"highlight_low" => "FDF9AD",
|
||||
"highlight_medium" => "E3D0A3",
|
||||
"highlight" => 'F2F481',
|
||||
"highlight" => "F2F481",
|
||||
"highlight_high" => "BCAA7F",
|
||||
"danger_low" => "F8D9C2",
|
||||
"danger" => 'e45735',
|
||||
"danger" => "e45735",
|
||||
"success_low" => "CFE5B9",
|
||||
"success_medium" => "4CB544",
|
||||
"success" => '009900',
|
||||
"success" => "009900",
|
||||
"love_low" => "FCDDD2",
|
||||
"love" => 'fa6c8d'
|
||||
"love" => "fa6c8d",
|
||||
},
|
||||
# By @altercation
|
||||
"Solarized Dark": {
|
||||
@@ -218,65 +217,59 @@ class ColorScheme < ActiveRecord::Base
|
||||
"primary_low_mid" => "798C88",
|
||||
"primary_medium" => "97A59D",
|
||||
"primary_high" => "B5BDB1",
|
||||
"primary" => 'FCF6E1',
|
||||
"primary-50" => '21454E',
|
||||
"primary-100" => '415F66',
|
||||
"primary-200" => '556F74',
|
||||
"primary-300" => '627A7E',
|
||||
"primary-400" => '697F83',
|
||||
"primary-500" => '76898C',
|
||||
"primary-600" => '839496',
|
||||
"primary-700" => 'B2B9B3',
|
||||
"primary-800" => 'DAD8CA',
|
||||
"primary-900" => 'F0EBDA',
|
||||
"primary" => "FCF6E1",
|
||||
"primary-50" => "21454E",
|
||||
"primary-100" => "415F66",
|
||||
"primary-200" => "556F74",
|
||||
"primary-300" => "627A7E",
|
||||
"primary-400" => "697F83",
|
||||
"primary-500" => "76898C",
|
||||
"primary-600" => "839496",
|
||||
"primary-700" => "B2B9B3",
|
||||
"primary-800" => "DAD8CA",
|
||||
"primary-900" => "F0EBDA",
|
||||
"secondary_low" => "B5BDB1",
|
||||
"secondary_medium" => "81938D",
|
||||
"secondary_high" => "4E6A6B",
|
||||
"secondary_very_high" => "143B44",
|
||||
"secondary" => '002B36',
|
||||
"secondary" => "002B36",
|
||||
"tertiary_low" => "003E54",
|
||||
"tertiary_medium" => "00557A",
|
||||
"tertiary" => '0088cc',
|
||||
"tertiary" => "0088cc",
|
||||
"tertiary_high" => "006C9F",
|
||||
"quaternary_low" => "944835",
|
||||
"quaternary" => 'e45735',
|
||||
"header_background" => '002B36',
|
||||
"header_primary" => 'FCF6E1',
|
||||
"quaternary" => "e45735",
|
||||
"header_background" => "002B36",
|
||||
"header_primary" => "FCF6E1",
|
||||
"highlight_low" => "4D6B3D",
|
||||
"highlight_medium" => "464C33",
|
||||
"highlight" => 'F2F481',
|
||||
"highlight" => "F2F481",
|
||||
"highlight_high" => "BFCA47",
|
||||
"danger_low" => "443836",
|
||||
"danger_medium" => "944835",
|
||||
"danger" => 'e45735',
|
||||
"danger" => "e45735",
|
||||
"success_low" => "004C26",
|
||||
"success_medium" => "007313",
|
||||
"success" => '009900',
|
||||
"success" => "009900",
|
||||
"love_low" => "4B3F50",
|
||||
"love" => 'fa6c8d',
|
||||
}
|
||||
"love" => "fa6c8d",
|
||||
},
|
||||
}
|
||||
|
||||
# rubocop:enable Layout/HashAlignment
|
||||
|
||||
LIGHT_THEME_ID = 'Light'
|
||||
LIGHT_THEME_ID = "Light"
|
||||
|
||||
def self.base_color_scheme_colors
|
||||
base_with_hash = []
|
||||
|
||||
base_colors.each do |name, color|
|
||||
base_with_hash << { name: name, hex: "#{color}" }
|
||||
end
|
||||
base_colors.each { |name, color| base_with_hash << { name: name, hex: "#{color}" } }
|
||||
|
||||
list = [
|
||||
{ id: LIGHT_THEME_ID, colors: base_with_hash }
|
||||
]
|
||||
list = [{ id: LIGHT_THEME_ID, colors: base_with_hash }]
|
||||
|
||||
CUSTOM_SCHEMES.each do |k, v|
|
||||
colors = []
|
||||
v.each do |name, color|
|
||||
colors << { name: name, hex: "#{color}" }
|
||||
end
|
||||
v.each { |name, color| colors << { name: name, hex: "#{color}" } }
|
||||
list.push(id: k.to_s, colors: colors)
|
||||
end
|
||||
|
||||
@@ -290,7 +283,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
attr_accessor :is_base
|
||||
attr_accessor :skip_publish
|
||||
|
||||
has_many :color_scheme_colors, -> { order('id ASC') }, dependent: :destroy
|
||||
has_many :color_scheme_colors, -> { order("id ASC") }, dependent: :destroy
|
||||
|
||||
alias_method :colors, :color_scheme_colors
|
||||
|
||||
@@ -303,7 +296,8 @@ class ColorScheme < ActiveRecord::Base
|
||||
validates_associated :color_scheme_colors
|
||||
|
||||
BASE_COLORS_FILE = "#{Rails.root}/app/assets/stylesheets/common/foundation/colors.scss"
|
||||
COLOR_TRANSFORMATION_FILE = "#{Rails.root}/app/assets/stylesheets/common/foundation/color_transformations.scss"
|
||||
COLOR_TRANSFORMATION_FILE =
|
||||
"#{Rails.root}/app/assets/stylesheets/common/foundation/color_transformations.scss"
|
||||
|
||||
@mutex = Mutex.new
|
||||
|
||||
@@ -312,10 +306,12 @@ class ColorScheme < ActiveRecord::Base
|
||||
@mutex.synchronize do
|
||||
return @base_colors if @base_colors
|
||||
base_colors = {}
|
||||
File.readlines(BASE_COLORS_FILE).each do |line|
|
||||
matches = /\$([\w]+):\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})(?:[;]|\s)/.match(line.strip)
|
||||
base_colors[matches[1]] = matches[2] if matches
|
||||
end
|
||||
File
|
||||
.readlines(BASE_COLORS_FILE)
|
||||
.each do |line|
|
||||
matches = /\$([\w]+):\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})(?:[;]|\s)/.match(line.strip)
|
||||
base_colors[matches[1]] = matches[2] if matches
|
||||
end
|
||||
@base_colors = base_colors
|
||||
end
|
||||
@base_colors
|
||||
@@ -326,10 +322,12 @@ class ColorScheme < ActiveRecord::Base
|
||||
@mutex.synchronize do
|
||||
return @transformation_variables if @transformation_variables
|
||||
transformation_variables = []
|
||||
File.readlines(COLOR_TRANSFORMATION_FILE).each do |line|
|
||||
matches = /\$([\w\-_]+):.*/.match(line.strip)
|
||||
transformation_variables.append(matches[1]) if matches
|
||||
end
|
||||
File
|
||||
.readlines(COLOR_TRANSFORMATION_FILE)
|
||||
.each do |line|
|
||||
matches = /\$([\w\-_]+):.*/.match(line.strip)
|
||||
transformation_variables.append(matches[1]) if matches
|
||||
end
|
||||
@transformation_variables = transformation_variables
|
||||
end
|
||||
@transformation_variables
|
||||
@@ -337,7 +335,11 @@ class ColorScheme < ActiveRecord::Base
|
||||
|
||||
def self.base_color_schemes
|
||||
base_color_scheme_colors.map do |hash|
|
||||
scheme = new(name: I18n.t("color_schemes.#{hash[:id].downcase.gsub(' ', '_')}"), base_scheme_id: hash[:id])
|
||||
scheme =
|
||||
new(
|
||||
name: I18n.t("color_schemes.#{hash[:id].downcase.gsub(" ", "_")}"),
|
||||
base_scheme_id: hash[:id],
|
||||
)
|
||||
scheme.colors = hash[:colors].map { |k| { name: k[:name], hex: k[:hex] } }
|
||||
scheme.is_base = true
|
||||
scheme
|
||||
@@ -346,7 +348,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
|
||||
def self.base
|
||||
return @base_color_scheme if @base_color_scheme
|
||||
@base_color_scheme = new(name: I18n.t('color_schemes.base_theme_name'))
|
||||
@base_color_scheme = new(name: I18n.t("color_schemes.base_theme_name"))
|
||||
@base_color_scheme.colors = base_colors.map { |name, hex| { name: name, hex: hex } }
|
||||
@base_color_scheme.is_base = true
|
||||
@base_color_scheme
|
||||
@@ -363,9 +365,10 @@ class ColorScheme < ActiveRecord::Base
|
||||
new_color_scheme.base_scheme_id = params[:base_scheme_id]
|
||||
new_color_scheme.user_selectable = true
|
||||
|
||||
colors = CUSTOM_SCHEMES[params[:base_scheme_id].to_sym]&.map do |name, hex|
|
||||
{ name: name, hex: hex }
|
||||
end if params[:base_scheme_id]
|
||||
colors =
|
||||
CUSTOM_SCHEMES[params[:base_scheme_id].to_sym]&.map do |name, hex|
|
||||
{ name: name, hex: hex }
|
||||
end if params[:base_scheme_id]
|
||||
colors ||= base.colors_hashes
|
||||
|
||||
# Override base values
|
||||
@@ -394,13 +397,17 @@ class ColorScheme < ActiveRecord::Base
|
||||
|
||||
def colors=(arr)
|
||||
@colors_by_name = nil
|
||||
arr.each do |c|
|
||||
self.color_scheme_colors << ColorSchemeColor.new(name: c[:name], hex: c[:hex])
|
||||
end
|
||||
arr.each { |c| self.color_scheme_colors << ColorSchemeColor.new(name: c[:name], hex: c[:hex]) }
|
||||
end
|
||||
|
||||
def colors_by_name
|
||||
@colors_by_name ||= self.colors.inject({}) { |sum, c| sum[c.name] = c; sum; }
|
||||
@colors_by_name ||=
|
||||
self
|
||||
.colors
|
||||
.inject({}) do |sum, c|
|
||||
sum[c.name] = c
|
||||
sum
|
||||
end
|
||||
end
|
||||
|
||||
def clear_colors_cache
|
||||
@@ -408,16 +415,12 @@ class ColorScheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def colors_hashes
|
||||
color_scheme_colors.map do |c|
|
||||
{ name: c.name, hex: c.hex }
|
||||
end
|
||||
color_scheme_colors.map { |c| { name: c.name, hex: c.hex } }
|
||||
end
|
||||
|
||||
def base_colors
|
||||
colors = nil
|
||||
if base_scheme_id && base_scheme_id != "Light"
|
||||
colors = CUSTOM_SCHEMES[base_scheme_id.to_sym]
|
||||
end
|
||||
colors = CUSTOM_SCHEMES[base_scheme_id.to_sym] if base_scheme_id && base_scheme_id != "Light"
|
||||
colors || ColorScheme.base_colors
|
||||
end
|
||||
|
||||
@@ -425,21 +428,15 @@ class ColorScheme < ActiveRecord::Base
|
||||
resolved = ColorScheme.base_colors.dup
|
||||
if base_scheme_id && base_scheme_id != "Light"
|
||||
if scheme = CUSTOM_SCHEMES[base_scheme_id.to_sym]
|
||||
scheme.each do |name, value|
|
||||
resolved[name] = value
|
||||
end
|
||||
scheme.each { |name, value| resolved[name] = value }
|
||||
end
|
||||
end
|
||||
colors.each do |c|
|
||||
resolved[c.name] = c.hex
|
||||
end
|
||||
colors.each { |c| resolved[c.name] = c.hex }
|
||||
resolved
|
||||
end
|
||||
|
||||
def publish_discourse_stylesheet
|
||||
if self.id
|
||||
self.class.publish_discourse_stylesheets!(self.id)
|
||||
end
|
||||
self.class.publish_discourse_stylesheets!(self.id) if self.id
|
||||
end
|
||||
|
||||
def self.publish_discourse_stylesheets!(id = nil)
|
||||
@@ -458,7 +455,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
theme_ids,
|
||||
with_scheme: true,
|
||||
clear_manager_cache: false,
|
||||
all_themes: true
|
||||
all_themes: true,
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -469,9 +466,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def bump_version
|
||||
if self.id
|
||||
self.version += 1
|
||||
end
|
||||
self.version += 1 if self.id
|
||||
end
|
||||
|
||||
def is_dark?
|
||||
@@ -484,7 +479,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def is_wcag?
|
||||
base_scheme_id&.start_with?('WCAG')
|
||||
base_scheme_id&.start_with?("WCAG")
|
||||
end
|
||||
|
||||
# Equivalent to dc-color-brightness() in variables.scss
|
||||
|
||||
Reference in New Issue
Block a user