Update theme_color_tags helper for new theme infrastructure (#37519)
This commit is contained in:
parent
be00db4fa3
commit
e58084a85f
@ -28,14 +28,17 @@ module ThemeHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_color_tags(theme)
|
def theme_color_tags(color_scheme)
|
||||||
if theme == 'system'
|
case color_scheme
|
||||||
|
when 'auto'
|
||||||
''.html_safe.tap do |tags|
|
''.html_safe.tap do |tags|
|
||||||
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)')
|
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)')
|
||||||
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
|
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
|
||||||
end
|
end
|
||||||
else
|
when 'light'
|
||||||
tag.meta name: 'theme-color', content: theme_color_for(theme)
|
tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:light]
|
||||||
|
when 'dark'
|
||||||
|
tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:dark]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,8 +68,4 @@ module ThemeHelper
|
|||||||
Setting.custom_css&.then { |content| Digest::SHA256.hexdigest(content) }
|
Setting.custom_css&.then { |content| Digest::SHA256.hexdigest(content) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_color_for(theme)
|
|
||||||
theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
%link{ rel: 'mask-icon', href: frontend_asset_path('images/logo-symbol-icon.svg'), color: '#6364FF' }/
|
%link{ rel: 'mask-icon', href: frontend_asset_path('images/logo-symbol-icon.svg'), color: '#6364FF' }/
|
||||||
%link{ rel: 'manifest', href: manifest_path(format: :json) }/
|
%link{ rel: 'manifest', href: manifest_path(format: :json) }/
|
||||||
= javascript_inline_tag 'theme-selection.js'
|
= javascript_inline_tag 'theme-selection.js'
|
||||||
= theme_color_tags current_theme
|
= theme_color_tags color_scheme
|
||||||
%meta{ name: 'mobile-web-app-capable', content: 'yes' }/
|
%meta{ name: 'mobile-web-app-capable', content: 'yes' }/
|
||||||
|
|
||||||
%title= html_title
|
%title= html_title
|
||||||
|
|||||||
@ -49,12 +49,12 @@ RSpec.describe ThemeHelper do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'theme_color_tags' do
|
describe 'theme_color_tags' do
|
||||||
let(:result) { helper.theme_color_tags(theme) }
|
let(:result) { helper.theme_color_tags(color_scheme) }
|
||||||
|
|
||||||
context 'when using system theme' do
|
context 'when using system theme' do
|
||||||
let(:theme) { 'system' }
|
let(:color_scheme) { 'auto' }
|
||||||
|
|
||||||
it 'returns the mastodon-light and default stylesheets with correct color schemes' do
|
it 'returns both color schemes with appropriate media queries' do
|
||||||
expect(html_theme_colors.first.attributes.symbolize_keys)
|
expect(html_theme_colors.first.attributes.symbolize_keys)
|
||||||
.to include(
|
.to include(
|
||||||
content: have_attributes(value: Themes::THEME_COLORS[:dark]),
|
content: have_attributes(value: Themes::THEME_COLORS[:dark]),
|
||||||
@ -68,10 +68,10 @@ RSpec.describe ThemeHelper do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when using mastodon-light theme' do
|
context 'when light color scheme' do
|
||||||
let(:theme) { 'mastodon-light' }
|
let(:color_scheme) { 'light' }
|
||||||
|
|
||||||
it 'returns the theme stylesheet without color scheme information' do
|
it 'returns the light color' do
|
||||||
expect(html_theme_colors.first.attributes.symbolize_keys)
|
expect(html_theme_colors.first.attributes.symbolize_keys)
|
||||||
.to include(
|
.to include(
|
||||||
content: have_attributes(value: Themes::THEME_COLORS[:light])
|
content: have_attributes(value: Themes::THEME_COLORS[:light])
|
||||||
@ -79,10 +79,10 @@ RSpec.describe ThemeHelper do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when using other theme' do
|
context 'when using dark color scheme' do
|
||||||
let(:theme) { 'contrast' }
|
let(:color_scheme) { 'dark' }
|
||||||
|
|
||||||
it 'returns the theme stylesheet without color scheme information' do
|
it 'returns the dark color' do
|
||||||
expect(html_theme_colors.first.attributes.symbolize_keys)
|
expect(html_theme_colors.first.attributes.symbolize_keys)
|
||||||
.to include(
|
.to include(
|
||||||
content: have_attributes(value: Themes::THEME_COLORS[:dark])
|
content: have_attributes(value: Themes::THEME_COLORS[:dark])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user