mirror of https://github.com/mastodon/mastodon.git
Clean up theme_helper style builders
parent
9cc4040308
commit
42cf017a2c
|
@ -3,8 +3,7 @@
|
||||||
module ThemeHelper
|
module ThemeHelper
|
||||||
def theme_style_tags(theme)
|
def theme_style_tags(theme)
|
||||||
if theme == 'system'
|
if theme == 'system'
|
||||||
stylesheet_pack_tag('mastodon-light', media: 'not all and (prefers-color-scheme: dark)', crossorigin: 'anonymous') +
|
system_theme_style_tags
|
||||||
stylesheet_pack_tag('default', media: '(prefers-color-scheme: dark)', crossorigin: 'anonymous')
|
|
||||||
else
|
else
|
||||||
stylesheet_pack_tag theme, media: 'all', crossorigin: 'anonymous'
|
stylesheet_pack_tag theme, media: 'all', crossorigin: 'anonymous'
|
||||||
end
|
end
|
||||||
|
@ -12,8 +11,7 @@ module ThemeHelper
|
||||||
|
|
||||||
def theme_color_tags(theme)
|
def theme_color_tags(theme)
|
||||||
if theme == 'system'
|
if theme == 'system'
|
||||||
tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)') +
|
system_theme_color_tags
|
||||||
tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
|
|
||||||
else
|
else
|
||||||
tag.meta name: 'theme-color', content: theme_color_for(theme)
|
tag.meta name: 'theme-color', content: theme_color_for(theme)
|
||||||
end
|
end
|
||||||
|
@ -21,7 +19,38 @@ module ThemeHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def system_theme_style_tags
|
||||||
|
''.html_safe.tap do |tags|
|
||||||
|
system_default_styles.each do |style|
|
||||||
|
tags << stylesheet_pack_tag(
|
||||||
|
style[:name],
|
||||||
|
crossorigin: 'anonymous',
|
||||||
|
media: style[:media]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def system_theme_color_tags
|
||||||
|
''.html_safe.tap do |tags|
|
||||||
|
%i(dark light).each do |scheme|
|
||||||
|
tags << tag.meta(
|
||||||
|
content: Themes::THEME_COLORS[scheme],
|
||||||
|
media: "(prefers-color-scheme: #{scheme})",
|
||||||
|
name: 'theme-color'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def theme_color_for(theme)
|
def theme_color_for(theme)
|
||||||
theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
|
theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def system_default_styles
|
||||||
|
[
|
||||||
|
{ name: 'mastodon-light', media: 'not all and (prefers-color-scheme: dark)' },
|
||||||
|
{ name: 'default', media: '(prefers-color-scheme: dark)' },
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue