mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-28 00:51:48 +01:00
Add support for theme helper mapping specifying multiple target values
This commit is contained in:
parent
430cfa1a38
commit
07a13d39da
1 changed files with 19 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
module ThemeHelper
|
module ThemeHelper
|
||||||
ATTRIBUTE_MAP = {
|
ATTRIBUTE_MAP = {
|
||||||
"primary_color" => "primary",
|
"primary_color" => %w[primary primary-rgb],
|
||||||
"primary_text" => "primary-text",
|
"primary_text" => "primary-text",
|
||||||
"danger_color" => "danger",
|
"danger_color" => "danger",
|
||||||
"danger_text" => "danger-text",
|
"danger_text" => "danger-text",
|
||||||
|
@ -16,8 +16,8 @@ module ThemeHelper
|
||||||
"dark_text" => "dark-text",
|
"dark_text" => "dark-text",
|
||||||
"light_color" => "light",
|
"light_color" => "light",
|
||||||
"light_text" => "light-text",
|
"light_text" => "light-text",
|
||||||
"raised_background" => "raised-bg",
|
"raised_background" => %w[raised-bg raised-bg-rgb],
|
||||||
"raised_accent" => "raised-accent",
|
"raised_accent" => %w[raised-accent raised-accent-rgb],
|
||||||
"background_color" => "background",
|
"background_color" => "background",
|
||||||
"body_text" => "body-text",
|
"body_text" => "body-text",
|
||||||
"input_color" => "input-bg",
|
"input_color" => "input-bg",
|
||||||
|
@ -36,20 +36,29 @@ module ThemeHelper
|
||||||
theme.attributes.each do |k, v|
|
theme.attributes.each do |k, v|
|
||||||
next unless ATTRIBUTE_MAP.key?(k)
|
next unless ATTRIBUTE_MAP.key?(k)
|
||||||
|
|
||||||
if k.include?("text") || k.include?("placeholder")
|
if ATTRIBUTE_MAP[k].is_a?(Array)
|
||||||
hex = get_hex_color_from_theme_value(v)
|
ATTRIBUTE_MAP[k].each do |var|
|
||||||
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
body += "\t--#{var}: #{get_color_for_key(var, v)};\n"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
body += "\t--#{ATTRIBUTE_MAP[k]}: ##{get_hex_color_from_theme_value(v)};\n"
|
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_color_for_key(ATTRIBUTE_MAP[k], v)};\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n}"
|
||||||
|
|
||||||
body += "}"
|
|
||||||
|
|
||||||
content_tag(:style, body)
|
content_tag(:style, body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_color_for_key(key, color)
|
||||||
|
hex = get_hex_color_from_theme_value(color)
|
||||||
|
|
||||||
|
if key.include?("text") || key.include?("placeholder") || key.include?("rgb")
|
||||||
|
get_decimal_triplet_from_hex(hex)
|
||||||
|
else
|
||||||
|
"##{hex}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def theme_color
|
def theme_color
|
||||||
theme = get_active_theme
|
theme = get_active_theme
|
||||||
if theme
|
if theme
|
||||||
|
|
Loading…
Reference in a new issue