Merge pull request #178 from Retrospring/fix/theme-color
Update theme-color meta value to match the current page's theme
This commit is contained in:
commit
35e8e5f6c1
|
@ -33,7 +33,7 @@ module ThemeHelper
|
|||
theme.attributes.each do |k, v|
|
||||
next unless ATTRIBUTE_MAP.key?(k)
|
||||
|
||||
if k.include? "text"
|
||||
if k.include? 'text'
|
||||
hex = get_hex_color_from_theme_value(v)
|
||||
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
||||
else
|
||||
|
@ -42,11 +42,20 @@ module ThemeHelper
|
|||
end
|
||||
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
||||
|
||||
body += "}"
|
||||
body += '}'
|
||||
|
||||
content_tag(:style, body)
|
||||
end
|
||||
|
||||
def theme_color
|
||||
theme = get_active_theme
|
||||
if theme
|
||||
"##{get_hex_color_from_theme_value(theme.primary_color)}"
|
||||
else
|
||||
'#5e35b1'
|
||||
end
|
||||
end
|
||||
|
||||
def get_active_theme
|
||||
if @user&.theme
|
||||
if user_signed_in?
|
||||
|
@ -64,12 +73,12 @@ module ThemeHelper
|
|||
end
|
||||
|
||||
def get_hex_color_from_theme_value(value)
|
||||
('0000000' + value.to_s(16))[-6, 6]
|
||||
("0000000#{value.to_s(16)}")[-6, 6]
|
||||
end
|
||||
|
||||
def get_decimal_triplet_from_hex(value)
|
||||
hexes = value.split(/(.{2})/).reject { |c| c.empty? }
|
||||
hexes.map(&:hex).join(", ")
|
||||
hexes.map(&:hex).join(', ')
|
||||
end
|
||||
|
||||
def rgb_values_from_hex(value)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%meta{ charset: 'utf-8' }
|
||||
%meta{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }
|
||||
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no' }
|
||||
%meta{ name: 'theme-color', content: '#5e35b1' }
|
||||
%meta{ name: 'theme-color', content: theme_color }
|
||||
%link{ rel: 'apple-touch-icon', href: '/apple-touch-icon-precomposed.png' }
|
||||
%link{ rel: 'icon', href: '/images/favicon/favicon-16.png', sizes: '16x16' }
|
||||
%link{ rel: 'icon', href: '/icon-152.png', sizes: '152x152' }
|
||||
|
|
Loading…
Reference in New Issue