New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple themes #4959
Changes from 7 commits
98fe896
e1e394b
160ceac
f9ad20d
8780db6
8b13827
aa4d7ac
efdf672
3fc70b0
142ac69
b3d0e48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base | |
|
||
helper_method :current_account | ||
helper_method :current_session | ||
helper_method :current_theme | ||
helper_method :single_user_mode? | ||
|
||
rescue_from ActionController::RoutingError, with: :not_found | ||
|
@@ -77,6 +78,13 @@ def current_session | |
@current_session ||= SessionActivation.find_by(session_id: cookies.signed['_session_id']) | ||
end | ||
|
||
def current_theme | ||
if current_account and Themes.instance.names.include? current_account.user.setting_theme | ||
return current_account&.user&.setting_theme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should just be current_user, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should cover most cases and make more sense? return Setting.default_settings['theme'] unless Themes.instance.names.include? current_user&.setting_theme
return current_user.setting_theme |
||
end | ||
Setting.default_settings['theme'] | ||
end | ||
|
||
def cache_collection(raw, klass) | ||
return raw unless klass.respond_to?(:with_includes) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { start } from 'rails-ujs'; | ||
|
||
// import default stylesheet with variables | ||
require('font-awesome/css/font-awesome.css'); | ||
require('mastodon-application-style'); | ||
|
||
require.context('../images/', true); | ||
|
||
start(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'singleton' | ||
require 'yaml' | ||
|
||
class Themes | ||
include Singleton | ||
|
||
def initialize | ||
@conf = YAML.load_file(Rails.root.join('config', 'themes.yml')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't remember if this needs to be frozen or not in modern rails |
||
end | ||
|
||
def names | ||
@conf.keys | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,10 @@ def setting_noindex | |
settings.noindex | ||
end | ||
|
||
def setting_theme | ||
settings.theme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively could do fallback here but that seems less good. |
||
end | ||
|
||
def token_for_app(a) | ||
return nil if a.nil? || a.owner != self | ||
Doorkeeper::AccessToken | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
%meta{ name: 'robots', content: 'noindex' }/ | ||
|
||
= stylesheet_pack_tag 'common', media: 'all' | ||
= stylesheet_pack_tag current_theme, media: 'all' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases, embeds will be seen by non-logged in users. So I think it should be fixed to default theme, and it shouldn't be changed by user preferences. |
||
= javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous' | ||
= javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous' | ||
= javascript_pack_tag 'public', integrity: true, crossorigin: 'anonymous' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default: styles/application.scss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it needs
&.
operator here. If they getsnil
, it is a programming error and should fail rather than returningnil
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with aki, also there is
current_account.user.setting_theme
without&.
in the previous line.