Skip to content

Commit

Permalink
Replace use_pack, layouts/theme and @theme by new helpers
Browse files Browse the repository at this point in the history
Packs are now loaded from views, just like upstream, and are
identified by their filenames. The definition of `theme.yml` has
changed as such:
- `pack_directory` is now required
- `pack` is now unused
- `signed_in_preload` has been introduced
  • Loading branch information
ClearlyClaire committed Apr 28, 2024
1 parent c3e12a4 commit 7208edb
Show file tree
Hide file tree
Showing 48 changed files with 88 additions and 290 deletions.
5 changes: 0 additions & 5 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class BaseController < ApplicationController

layout 'admin'

before_action :set_pack
before_action :set_body_classes
before_action :set_cache_headers

Expand All @@ -19,10 +18,6 @@ def set_body_classes
@body_classes = 'admin'
end

def set_pack
use_pack 'admin'
end

def set_cache_headers
response.cache_control.replace(private: true, no_store: true)
end
Expand Down
10 changes: 2 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ def body_class_string

def respond_with_error(code)
respond_to do |format|
format.any do
use_pack 'error'
render "errors/#{code}", layout: 'error', status: code, formats: [:html]
end
format.any { render "errors/#{code}", layout: 'error', status: code, formats: [:html] }
format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[code] }, status: code }
end
end
Expand All @@ -177,10 +174,7 @@ def check_self_destruct!
return unless self_destruct?

respond_to do |format|
format.any do
use_pack 'error'
render 'errors/self_destruct', layout: 'auth', status: 410, formats: [:html]
end
format.any { render 'errors/self_destruct', layout: 'auth', status: 410, formats: [:html] }
format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[410] }, status: 410 }
end
end
Expand Down
7 changes: 0 additions & 7 deletions app/controllers/auth/challenges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Auth::ChallengesController < ApplicationController

layout 'auth'

before_action :set_pack
before_action :authenticate_user!

skip_before_action :check_self_destruct!
Expand All @@ -21,10 +20,4 @@ def create
render_challenge
end
end

private

def set_pack
use_pack 'auth'
end
end
5 changes: 0 additions & 5 deletions app/controllers/auth/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
layout 'auth'

before_action :set_body_classes
before_action :set_pack
before_action :set_confirmation_user!, only: [:show, :confirm_captcha]
before_action :redirect_confirmed_user, if: :signed_in_confirmed_user?

Expand Down Expand Up @@ -66,10 +65,6 @@ def captcha_user_bypass?
@confirmation_user.nil? || @confirmation_user.confirmed?
end

def set_pack
use_pack 'auth'
end

def redirect_confirmed_user
redirect_to(current_user.approved? ? root_path : edit_user_registration_path)
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/auth/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Auth::PasswordsController < Devise::PasswordsController
skip_before_action :check_self_destruct!
before_action :redirect_invalid_reset_token, only: :edit, unless: :reset_password_token_is_valid?
before_action :set_pack
before_action :set_body_classes

layout 'auth'
Expand Down Expand Up @@ -32,8 +31,4 @@ def set_body_classes
def reset_password_token_is_valid?
resource_class.with_reset_password_token(params[:reset_password_token]).present?
end

def set_pack
use_pack 'auth'
end
end
5 changes: 0 additions & 5 deletions app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Auth::RegistrationsController < Devise::RegistrationsController
before_action :set_invite, only: [:new, :create]
before_action :check_enabled_registrations, only: [:new, :create]
before_action :configure_sign_up_params, only: [:create]
before_action :set_pack
before_action :set_sessions, only: [:edit, :update]
before_action :set_strikes, only: [:edit, :update]
before_action :set_body_classes, only: [:new, :create, :edit, :update]
Expand Down Expand Up @@ -97,10 +96,6 @@ def invite_code

private

def set_pack
use_pack %w(edit update).include?(action_name) ? 'admin' : 'auth'
end

def set_body_classes
@body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter'
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Auth::SessionsController < Devise::SessionsController
skip_before_action :require_functional!
skip_before_action :update_user_sign_in

prepend_before_action :set_pack
prepend_before_action :check_suspicious!, only: [:create]

include Auth::TwoFactorAuthenticationConcern
Expand Down Expand Up @@ -104,10 +103,6 @@ def require_no_authentication

private

def set_pack
use_pack 'auth'
end

def set_body_classes
@body_classes = 'lighter'
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/auth/setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Auth::SetupController < ApplicationController
layout 'auth'

before_action :set_pack
before_action :authenticate_user!
before_action :require_unconfirmed_or_pending!
before_action :set_body_classes
Expand Down Expand Up @@ -43,8 +42,4 @@ def set_body_classes
def user_params
params.require(:user).permit(:email)
end

def set_pack
use_pack 'sign_up'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def authenticate_with_two_factor_via_otp(user)
def prompt_for_two_factor(user)
register_attempt_in_session(user)

use_pack 'auth'

@body_classes = 'lighter'
@webauthn_enabled = user.webauthn_enabled?
@scheme_type = if user.webauthn_enabled? && user_params[:otp_attempt].blank?
Expand Down
33 changes: 5 additions & 28 deletions app/controllers/concerns/theming_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,22 @@
module ThemingConcern
extend ActiveSupport::Concern

def use_pack(pack_name)
@theme = resolve_pack(Themes.instance.flavour(current_flavour), pack_name)
end

private

def current_flavour
[current_user&.setting_flavour, Setting.flavour, 'glitch', 'vanilla'].find { |flavour| Themes.instance.flavours.include?(flavour) }
@current_flavour ||= [current_user&.setting_flavour, Setting.flavour, 'glitch', 'vanilla'].find { |flavour| Themes.instance.flavours.include?(flavour) }
end

def current_skin
skins = Themes.instance.skins_for(current_flavour)
[current_user&.setting_skin, Setting.skin, 'default'].find { |skin| skins.include?(skin) }
@current_skin ||= begin
skins = Themes.instance.skins_for(current_flavour)
[current_user&.setting_skin, Setting.skin, 'default'].find { |skin| skins.include?(skin) }
end
end

def current_theme
# NOTE: this is slightly different from upstream, as it's a derived value used
# for the sole purpose of pointing to the appropriate stylesheet pack
"skins/#{current_flavour}/#{current_skin}"
end

def resolve_pack(data, pack_name)
pack_data = {
flavour: data['name'],
pack: nil,
preload: nil,
supported_locales: data['locales'],
}
return pack_data unless data['pack'].is_a?(Hash) && data['pack'][pack_name].present?

pack_data[:pack] = pack_name
return pack_data unless data['pack'][pack_name].is_a?(Hash)

pack_data[:pack] = nil unless data['pack'][pack_name]['filename']

preloads = data['pack'][pack_name]['preload']
pack_data[:preload] = [preloads] if preloads.is_a?(String)
pack_data[:preload] = preloads if preloads.is_a?(Array)

pack_data
end
end
5 changes: 0 additions & 5 deletions app/controllers/concerns/web_app_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module WebAppControllerConcern
vary_by 'Accept, Accept-Language, Cookie'

before_action :redirect_unauthenticated_to_permalinks!
before_action :set_pack
before_action :set_app_body_class
end

Expand Down Expand Up @@ -37,8 +36,4 @@ def redirect_unauthenticated_to_permalinks!
end
end
end

def set_pack
use_pack 'application'
end
end
5 changes: 0 additions & 5 deletions app/controllers/disputes/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ class Disputes::BaseController < ApplicationController

before_action :set_body_classes
before_action :authenticate_user!
before_action :set_pack
before_action :set_cache_headers

private

def set_pack
use_pack 'admin'
end

def set_body_classes
@body_classes = 'admin'
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/filters/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Filters::StatusesController < ApplicationController
before_action :authenticate_user!
before_action :set_filter
before_action :set_status_filters
before_action :set_pack
before_action :set_body_classes
before_action :set_cache_headers

Expand All @@ -27,10 +26,6 @@ def batch

private

def set_pack
use_pack 'admin'
end

def set_filter
@filter = current_account.custom_filters.find(params[:filter_id])
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/filters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class FiltersController < ApplicationController

before_action :authenticate_user!
before_action :set_filter, only: [:edit, :update, :destroy]
before_action :set_pack
before_action :set_body_classes
before_action :set_cache_headers

Expand Down Expand Up @@ -45,10 +44,6 @@ def destroy

private

def set_pack
use_pack 'settings'
end

def set_filter
@filter = current_account.custom_filters.find(params[:id])
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/invites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class InvitesController < ApplicationController
layout 'admin'

before_action :authenticate_user!
before_action :set_pack
before_action :set_body_classes
before_action :set_cache_headers

Expand Down Expand Up @@ -40,10 +39,6 @@ def destroy

private

def set_pack
use_pack 'settings'
end

def invites
current_user.invites.order(id: :desc)
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class MediaController < ApplicationController
before_action :verify_permitted_status!
before_action :check_playable, only: :player
before_action :allow_iframing, only: :player
before_action :set_pack, only: :player

content_security_policy only: :player do |policy|
policy.frame_ancestors(false)
Expand Down Expand Up @@ -48,8 +47,4 @@ def check_playable
def allow_iframing
response.headers.delete('X-Frame-Options')
end

def set_pack
use_pack 'public'
end
end
5 changes: 0 additions & 5 deletions app/controllers/oauth/authorizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController

before_action :store_current_location
before_action :authenticate_resource_owner!
before_action :set_pack
before_action :set_cache_headers

content_security_policy do |p|
Expand All @@ -20,10 +19,6 @@ def store_current_location
store_location_for(:user, request.url)
end

def set_pack
use_pack 'auth'
end

def render_success
if skip_authorization? || (matching_token? && !truthy_param?('force_login'))
redirect_or_render authorize_response
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/oauth/authorized_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicatio

before_action :store_current_location
before_action :authenticate_resource_owner!
before_action :set_pack
before_action :require_not_suspended!, only: :destroy
before_action :set_body_classes
before_action :set_cache_headers
Expand All @@ -31,10 +30,6 @@ def store_current_location
store_location_for(:user, request.url)
end

def set_pack
use_pack 'settings'
end

def require_not_suspended!
forbidden if current_account.unavailable?
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/redirect/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Redirect::BaseController < ApplicationController
vary_by 'Accept-Language'

before_action :set_pack
before_action :set_resource
before_action :set_app_body_class

Expand All @@ -22,8 +21,4 @@ def set_app_body_class
def set_resource
raise NotImplementedError
end

def set_pack
use_pack 'public'
end
end
5 changes: 0 additions & 5 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class RelationshipsController < ApplicationController

before_action :authenticate_user!
before_action :set_accounts, only: :show
before_action :set_pack
before_action :set_relationships, only: :show
before_action :set_body_classes
before_action :set_cache_headers
Expand Down Expand Up @@ -73,10 +72,6 @@ def set_body_classes
@body_classes = 'admin'
end

def set_pack
use_pack 'admin'
end

def set_cache_headers
response.cache_control.replace(private: true, no_store: true)
end
Expand Down
Loading

0 comments on commit 7208edb

Please sign in to comment.