From e58084a85f6ccf64325c9af6f71ed7ef030fed65 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 16 Jan 2026 11:00:04 +0100 Subject: [PATCH] Update `theme_color_tags` helper for new theme infrastructure (#37519) --- app/helpers/theme_helper.rb | 15 +++++++-------- app/views/layouts/application.html.haml | 2 +- spec/helpers/theme_helper_spec.rb | 18 +++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/helpers/theme_helper.rb b/app/helpers/theme_helper.rb index 1d642056809..e7655414145 100644 --- a/app/helpers/theme_helper.rb +++ b/app/helpers/theme_helper.rb @@ -28,14 +28,17 @@ module ThemeHelper end end - def theme_color_tags(theme) - if theme == 'system' + def theme_color_tags(color_scheme) + case color_scheme + when 'auto' ''.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[:light], media: '(prefers-color-scheme: light)') end - else - tag.meta name: 'theme-color', content: theme_color_for(theme) + when 'light' + tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:light] + when 'dark' + tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:dark] end end @@ -65,8 +68,4 @@ module ThemeHelper Setting.custom_css&.then { |content| Digest::SHA256.hexdigest(content) } end end - - def theme_color_for(theme) - theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark] - end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0cbd51c85b0..15f1e961ed6 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -21,7 +21,7 @@ %link{ rel: 'mask-icon', href: frontend_asset_path('images/logo-symbol-icon.svg'), color: '#6364FF' }/ %link{ rel: 'manifest', href: manifest_path(format: :json) }/ = javascript_inline_tag 'theme-selection.js' - = theme_color_tags current_theme + = theme_color_tags color_scheme %meta{ name: 'mobile-web-app-capable', content: 'yes' }/ %title= html_title diff --git a/spec/helpers/theme_helper_spec.rb b/spec/helpers/theme_helper_spec.rb index 9eefa01f902..9e8119a7429 100644 --- a/spec/helpers/theme_helper_spec.rb +++ b/spec/helpers/theme_helper_spec.rb @@ -49,12 +49,12 @@ RSpec.describe ThemeHelper do end 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 - 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) .to include( content: have_attributes(value: Themes::THEME_COLORS[:dark]), @@ -68,10 +68,10 @@ RSpec.describe ThemeHelper do end end - context 'when using mastodon-light theme' do - let(:theme) { 'mastodon-light' } + context 'when light color scheme' do + 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) .to include( content: have_attributes(value: Themes::THEME_COLORS[:light]) @@ -79,10 +79,10 @@ RSpec.describe ThemeHelper do end end - context 'when using other theme' do - let(:theme) { 'contrast' } + context 'when using dark color scheme' do + 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) .to include( content: have_attributes(value: Themes::THEME_COLORS[:dark])