Fix lints in ThemeHelper
This commit is contained in:
parent
f35d49e575
commit
921f02c4c9
|
@ -1,27 +1,29 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ThemeHelper
|
module ThemeHelper
|
||||||
ATTRIBUTE_MAP = {
|
ATTRIBUTE_MAP = {
|
||||||
'primary_color' => 'primary',
|
"primary_color" => "primary",
|
||||||
'primary_text' => 'primary-text',
|
"primary_text" => "primary-text",
|
||||||
'danger_color' => 'danger',
|
"danger_color" => "danger",
|
||||||
'danger_text' => 'danger-text',
|
"danger_text" => "danger-text",
|
||||||
'warning_color' => 'warning',
|
"warning_color" => "warning",
|
||||||
'warning_text' => 'warning-text',
|
"warning_text" => "warning-text",
|
||||||
'info_color' => 'info',
|
"info_color" => "info",
|
||||||
'info_text' => 'info-text',
|
"info_text" => "info-text",
|
||||||
'success_color' => 'success',
|
"success_color" => "success",
|
||||||
'success_text' => 'success-text',
|
"success_text" => "success-text",
|
||||||
'dark_color' => 'dark',
|
"dark_color" => "dark",
|
||||||
'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" => "raised-bg",
|
||||||
'raised_accent' => 'raised-accent',
|
"raised_accent" => "raised-accent",
|
||||||
'background_color' => 'background',
|
"background_color" => "background",
|
||||||
'body_text' => 'body-text',
|
"body_text" => "body-text",
|
||||||
'input_color' => 'input-bg',
|
"input_color" => "input-bg",
|
||||||
'input_text' => 'input-text',
|
"input_text" => "input-text",
|
||||||
'input_placeholder' => 'input-placeholder',
|
"input_placeholder" => "input-placeholder",
|
||||||
'muted_text' => 'muted-text'
|
"muted_text" => "muted-text"
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def render_theme
|
def render_theme
|
||||||
|
@ -34,7 +36,7 @@ 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' or k.include? 'placeholder'
|
if k.include?("text") || k.include?("placeholder")
|
||||||
hex = get_hex_color_from_theme_value(v)
|
hex = get_hex_color_from_theme_value(v)
|
||||||
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
||||||
else
|
else
|
||||||
|
@ -43,7 +45,7 @@ module ThemeHelper
|
||||||
end
|
end
|
||||||
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
||||||
|
|
||||||
body += '}'
|
body += "}"
|
||||||
|
|
||||||
content_tag(:style, body)
|
content_tag(:style, body)
|
||||||
end
|
end
|
||||||
|
@ -53,7 +55,7 @@ module ThemeHelper
|
||||||
if theme
|
if theme
|
||||||
theme.theme_color
|
theme.theme_color
|
||||||
else
|
else
|
||||||
'#5e35b1'
|
"#5e35b1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ module ThemeHelper
|
||||||
if theme
|
if theme
|
||||||
theme.mobile_theme_color
|
theme.mobile_theme_color
|
||||||
else
|
else
|
||||||
'#f0edf4'
|
"#f0edf4"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,12 +95,12 @@ module ThemeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_hex_color_from_theme_value(value)
|
def get_hex_color_from_theme_value(value)
|
||||||
("0000000#{value.to_s(16)}")[-6, 6]
|
"0000000#{value.to_s(16)}"[-6, 6]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_decimal_triplet_from_hex(value)
|
def get_decimal_triplet_from_hex(value)
|
||||||
hexes = value.split(/(.{2})/).reject { |c| c.empty? }
|
hexes = value.split(/(.{2})/).reject(&:empty?)
|
||||||
hexes.map(&:hex).join(', ')
|
hexes.map(&:hex).join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def rgb_values_from_hex(value)
|
def rgb_values_from_hex(value)
|
||||||
|
@ -110,10 +112,10 @@ module ThemeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def rgb_to_hex(rgb_values)
|
def rgb_to_hex(rgb_values)
|
||||||
rgb_values.map.with_index { |v, i| v << (2 - i) * 8 }.reduce(&:+).to_s(16)
|
rgb_values.map.with_index { |v, i| v << ((2 - i) * 8) }.reduce(&:+).to_s(16)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lighten(value, amount = 0.25)
|
def lighten(value, amount = 0.25)
|
||||||
rgb_to_hex(rgb_values_from_hex(value).map { |v| [(v + 255 * amount).round, 255].min })
|
rgb_to_hex(rgb_values_from_hex(value).map { |v| [(v + (255 * amount)).round, 255].min })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue