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