Replace `use_pack`, `layouts/theme` and `@theme` by new helpers

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
shrike
Claire 2024-04-28 12:08:08 +02:00
parent c3e12a4dfa
commit 7208edbd37
48 changed files with 88 additions and 290 deletions

View File

@ -7,7 +7,6 @@ module Admin
layout 'admin' layout 'admin'
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -19,10 +18,6 @@ module Admin
@body_classes = 'admin' @body_classes = 'admin'
end end
def set_pack
use_pack 'admin'
end
def set_cache_headers def set_cache_headers
response.cache_control.replace(private: true, no_store: true) response.cache_control.replace(private: true, no_store: true)
end end

View File

@ -165,10 +165,7 @@ class ApplicationController < ActionController::Base
def respond_with_error(code) def respond_with_error(code)
respond_to do |format| respond_to do |format|
format.any do format.any { render "errors/#{code}", layout: 'error', status: code, formats: [:html] }
use_pack 'error'
render "errors/#{code}", layout: 'error', status: code, formats: [:html]
end
format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[code] }, status: code } format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[code] }, status: code }
end end
end end
@ -177,10 +174,7 @@ class ApplicationController < ActionController::Base
return unless self_destruct? return unless self_destruct?
respond_to do |format| respond_to do |format|
format.any do format.any { render 'errors/self_destruct', layout: 'auth', status: 410, formats: [:html] }
use_pack 'error'
render 'errors/self_destruct', layout: 'auth', status: 410, formats: [:html]
end
format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[410] }, status: 410 } format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[410] }, status: 410 }
end end
end end

View File

@ -5,7 +5,6 @@ class Auth::ChallengesController < ApplicationController
layout 'auth' layout 'auth'
before_action :set_pack
before_action :authenticate_user! before_action :authenticate_user!
skip_before_action :check_self_destruct! skip_before_action :check_self_destruct!
@ -21,10 +20,4 @@ class Auth::ChallengesController < ApplicationController
render_challenge render_challenge
end end
end end
private
def set_pack
use_pack 'auth'
end
end end

View File

@ -6,7 +6,6 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
layout 'auth' layout 'auth'
before_action :set_body_classes before_action :set_body_classes
before_action :set_pack
before_action :set_confirmation_user!, only: [:show, :confirm_captcha] before_action :set_confirmation_user!, only: [:show, :confirm_captcha]
before_action :redirect_confirmed_user, if: :signed_in_confirmed_user? before_action :redirect_confirmed_user, if: :signed_in_confirmed_user?
@ -66,10 +65,6 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
@confirmation_user.nil? || @confirmation_user.confirmed? @confirmation_user.nil? || @confirmation_user.confirmed?
end end
def set_pack
use_pack 'auth'
end
def redirect_confirmed_user def redirect_confirmed_user
redirect_to(current_user.approved? ? root_path : edit_user_registration_path) redirect_to(current_user.approved? ? root_path : edit_user_registration_path)
end end

View File

@ -3,7 +3,6 @@
class Auth::PasswordsController < Devise::PasswordsController class Auth::PasswordsController < Devise::PasswordsController
skip_before_action :check_self_destruct! skip_before_action :check_self_destruct!
before_action :redirect_invalid_reset_token, only: :edit, unless: :reset_password_token_is_valid? before_action :redirect_invalid_reset_token, only: :edit, unless: :reset_password_token_is_valid?
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
layout 'auth' layout 'auth'
@ -32,8 +31,4 @@ class Auth::PasswordsController < Devise::PasswordsController
def reset_password_token_is_valid? def reset_password_token_is_valid?
resource_class.with_reset_password_token(params[:reset_password_token]).present? resource_class.with_reset_password_token(params[:reset_password_token]).present?
end end
def set_pack
use_pack 'auth'
end
end end

View File

@ -9,7 +9,6 @@ class Auth::RegistrationsController < Devise::RegistrationsController
before_action :set_invite, only: [:new, :create] before_action :set_invite, only: [:new, :create]
before_action :check_enabled_registrations, only: [:new, :create] before_action :check_enabled_registrations, only: [:new, :create]
before_action :configure_sign_up_params, only: [:create] before_action :configure_sign_up_params, only: [:create]
before_action :set_pack
before_action :set_sessions, only: [:edit, :update] before_action :set_sessions, only: [:edit, :update]
before_action :set_strikes, only: [:edit, :update] before_action :set_strikes, only: [:edit, :update]
before_action :set_body_classes, only: [:new, :create, :edit, :update] before_action :set_body_classes, only: [:new, :create, :edit, :update]
@ -97,10 +96,6 @@ class Auth::RegistrationsController < Devise::RegistrationsController
private private
def set_pack
use_pack %w(edit update).include?(action_name) ? 'admin' : 'auth'
end
def set_body_classes def set_body_classes
@body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter' @body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter'
end end

View File

@ -12,7 +12,6 @@ class Auth::SessionsController < Devise::SessionsController
skip_before_action :require_functional! skip_before_action :require_functional!
skip_before_action :update_user_sign_in skip_before_action :update_user_sign_in
prepend_before_action :set_pack
prepend_before_action :check_suspicious!, only: [:create] prepend_before_action :check_suspicious!, only: [:create]
include Auth::TwoFactorAuthenticationConcern include Auth::TwoFactorAuthenticationConcern
@ -104,10 +103,6 @@ class Auth::SessionsController < Devise::SessionsController
private private
def set_pack
use_pack 'auth'
end
def set_body_classes def set_body_classes
@body_classes = 'lighter' @body_classes = 'lighter'
end end

View File

@ -3,7 +3,6 @@
class Auth::SetupController < ApplicationController class Auth::SetupController < ApplicationController
layout 'auth' layout 'auth'
before_action :set_pack
before_action :authenticate_user! before_action :authenticate_user!
before_action :require_unconfirmed_or_pending! before_action :require_unconfirmed_or_pending!
before_action :set_body_classes before_action :set_body_classes
@ -43,8 +42,4 @@ class Auth::SetupController < ApplicationController
def user_params def user_params
params.require(:user).permit(:email) params.require(:user).permit(:email)
end end
def set_pack
use_pack 'sign_up'
end
end end

View File

@ -83,8 +83,6 @@ module Auth::TwoFactorAuthenticationConcern
def prompt_for_two_factor(user) def prompt_for_two_factor(user)
register_attempt_in_session(user) register_attempt_in_session(user)
use_pack 'auth'
@body_classes = 'lighter' @body_classes = 'lighter'
@webauthn_enabled = user.webauthn_enabled? @webauthn_enabled = user.webauthn_enabled?
@scheme_type = if user.webauthn_enabled? && user_params[:otp_attempt].blank? @scheme_type = if user.webauthn_enabled? && user_params[:otp_attempt].blank?

View File

@ -3,19 +3,17 @@
module ThemingConcern module ThemingConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
def use_pack(pack_name)
@theme = resolve_pack(Themes.instance.flavour(current_flavour), pack_name)
end
private private
def current_flavour 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 end
def current_skin def current_skin
skins = Themes.instance.skins_for(current_flavour) @current_skin ||= begin
[current_user&.setting_skin, Setting.skin, 'default'].find { |skin| skins.include?(skin) } skins = Themes.instance.skins_for(current_flavour)
[current_user&.setting_skin, Setting.skin, 'default'].find { |skin| skins.include?(skin) }
end
end end
def current_theme def current_theme
@ -23,25 +21,4 @@ module ThemingConcern
# for the sole purpose of pointing to the appropriate stylesheet pack # for the sole purpose of pointing to the appropriate stylesheet pack
"skins/#{current_flavour}/#{current_skin}" "skins/#{current_flavour}/#{current_skin}"
end 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 end

View File

@ -7,7 +7,6 @@ module WebAppControllerConcern
vary_by 'Accept, Accept-Language, Cookie' vary_by 'Accept, Accept-Language, Cookie'
before_action :redirect_unauthenticated_to_permalinks! before_action :redirect_unauthenticated_to_permalinks!
before_action :set_pack
before_action :set_app_body_class before_action :set_app_body_class
end end
@ -37,8 +36,4 @@ module WebAppControllerConcern
end end
end end
end end
def set_pack
use_pack 'application'
end
end end

View File

@ -9,15 +9,10 @@ class Disputes::BaseController < ApplicationController
before_action :set_body_classes before_action :set_body_classes
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_pack
before_action :set_cache_headers before_action :set_cache_headers
private private
def set_pack
use_pack 'admin'
end
def set_body_classes def set_body_classes
@body_classes = 'admin' @body_classes = 'admin'
end end

View File

@ -6,7 +6,6 @@ class Filters::StatusesController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_filter before_action :set_filter
before_action :set_status_filters before_action :set_status_filters
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -27,10 +26,6 @@ class Filters::StatusesController < ApplicationController
private private
def set_pack
use_pack 'admin'
end
def set_filter def set_filter
@filter = current_account.custom_filters.find(params[:filter_id]) @filter = current_account.custom_filters.find(params[:filter_id])
end end

View File

@ -5,7 +5,6 @@ class FiltersController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_filter, only: [:edit, :update, :destroy] before_action :set_filter, only: [:edit, :update, :destroy]
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -45,10 +44,6 @@ class FiltersController < ApplicationController
private private
def set_pack
use_pack 'settings'
end
def set_filter def set_filter
@filter = current_account.custom_filters.find(params[:id]) @filter = current_account.custom_filters.find(params[:id])
end end

View File

@ -6,7 +6,6 @@ class InvitesController < ApplicationController
layout 'admin' layout 'admin'
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -40,10 +39,6 @@ class InvitesController < ApplicationController
private private
def set_pack
use_pack 'settings'
end
def invites def invites
current_user.invites.order(id: :desc) current_user.invites.order(id: :desc)
end end

View File

@ -10,7 +10,6 @@ class MediaController < ApplicationController
before_action :verify_permitted_status! before_action :verify_permitted_status!
before_action :check_playable, only: :player before_action :check_playable, only: :player
before_action :allow_iframing, only: :player before_action :allow_iframing, only: :player
before_action :set_pack, only: :player
content_security_policy only: :player do |policy| content_security_policy only: :player do |policy|
policy.frame_ancestors(false) policy.frame_ancestors(false)
@ -48,8 +47,4 @@ class MediaController < ApplicationController
def allow_iframing def allow_iframing
response.headers.delete('X-Frame-Options') response.headers.delete('X-Frame-Options')
end end
def set_pack
use_pack 'public'
end
end end

View File

@ -5,7 +5,6 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
before_action :store_current_location before_action :store_current_location
before_action :authenticate_resource_owner! before_action :authenticate_resource_owner!
before_action :set_pack
before_action :set_cache_headers before_action :set_cache_headers
content_security_policy do |p| content_security_policy do |p|
@ -20,10 +19,6 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
store_location_for(:user, request.url) store_location_for(:user, request.url)
end end
def set_pack
use_pack 'auth'
end
def render_success def render_success
if skip_authorization? || (matching_token? && !truthy_param?('force_login')) if skip_authorization? || (matching_token? && !truthy_param?('force_login'))
redirect_or_render authorize_response redirect_or_render authorize_response

View File

@ -5,7 +5,6 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicatio
before_action :store_current_location before_action :store_current_location
before_action :authenticate_resource_owner! before_action :authenticate_resource_owner!
before_action :set_pack
before_action :require_not_suspended!, only: :destroy before_action :require_not_suspended!, only: :destroy
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -31,10 +30,6 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicatio
store_location_for(:user, request.url) store_location_for(:user, request.url)
end end
def set_pack
use_pack 'settings'
end
def require_not_suspended! def require_not_suspended!
forbidden if current_account.unavailable? forbidden if current_account.unavailable?
end end

View File

@ -3,7 +3,6 @@
class Redirect::BaseController < ApplicationController class Redirect::BaseController < ApplicationController
vary_by 'Accept-Language' vary_by 'Accept-Language'
before_action :set_pack
before_action :set_resource before_action :set_resource
before_action :set_app_body_class before_action :set_app_body_class
@ -22,8 +21,4 @@ class Redirect::BaseController < ApplicationController
def set_resource def set_resource
raise NotImplementedError raise NotImplementedError
end end
def set_pack
use_pack 'public'
end
end end

View File

@ -5,7 +5,6 @@ class RelationshipsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_accounts, only: :show before_action :set_accounts, only: :show
before_action :set_pack
before_action :set_relationships, only: :show before_action :set_relationships, only: :show
before_action :set_body_classes before_action :set_body_classes
before_action :set_cache_headers before_action :set_cache_headers
@ -73,10 +72,6 @@ class RelationshipsController < ApplicationController
@body_classes = 'admin' @body_classes = 'admin'
end end
def set_pack
use_pack 'admin'
end
def set_cache_headers def set_cache_headers
response.cache_control.replace(private: true, no_store: true) response.cache_control.replace(private: true, no_store: true)
end end

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class Settings::BaseController < ApplicationController class Settings::BaseController < ApplicationController
before_action :set_pack
layout 'admin' layout 'admin'
before_action :authenticate_user! before_action :authenticate_user!
@ -10,10 +9,6 @@ class Settings::BaseController < ApplicationController
private private
def set_pack
use_pack 'settings'
end
def set_body_classes def set_body_classes
@body_classes = 'admin' @body_classes = 'admin'
end end

View File

@ -7,10 +7,4 @@ class Settings::LoginActivitiesController < Settings::BaseController
def index def index
@login_activities = LoginActivity.where(user: current_user).order(id: :desc).page(params[:page]) @login_activities = LoginActivity.where(user: current_user).order(id: :desc).page(params[:page])
end end
private
def set_pack
use_pack 'settings'
end
end end

View File

@ -85,10 +85,6 @@ module Settings
private private
def set_pack
use_pack 'auth'
end
def redirect_invalid_otp def redirect_invalid_otp
flash[:error] = t('webauthn_credentials.otp_required') flash[:error] = t('webauthn_credentials.otp_required')
redirect_to settings_two_factor_authentication_methods_path redirect_to settings_two_factor_authentication_methods_path

View File

@ -4,17 +4,12 @@ class SharesController < ApplicationController
layout 'modal' layout 'modal'
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_pack
before_action :set_body_classes before_action :set_body_classes
def show; end def show; end
private private
def set_pack
use_pack 'share'
end
def set_body_classes def set_body_classes
@body_classes = 'modal-layout compose-standalone' @body_classes = 'modal-layout compose-standalone'
end end

View File

@ -6,7 +6,6 @@ class StatusesCleanupController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_policy before_action :set_policy
before_action :set_body_classes before_action :set_body_classes
before_action :set_pack
before_action :set_cache_headers before_action :set_cache_headers
def show; end def show; end
@ -27,10 +26,6 @@ class StatusesCleanupController < ApplicationController
private private
def set_pack
use_pack 'settings'
end
def set_policy def set_policy
@policy = current_account.statuses_cleanup_policy || current_account.build_statuses_cleanup_policy(enabled: false) @policy = current_account.statuses_cleanup_policy || current_account.build_statuses_cleanup_policy(enabled: false)
end end

View File

@ -41,7 +41,6 @@ class StatusesController < ApplicationController
end end
def embed def embed
use_pack 'public'
return not_found if @status.hidden? || @status.reblog? return not_found if @status.hidden? || @status.reblog?
expires_in 180, public: true expires_in 180, public: true

View File

@ -233,6 +233,21 @@ module ApplicationHelper
EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s
end end
# glitch-soc addition to handle the multiple flavors
def preload_locale_pack
supported_locales = Themes.instance.flavour(current_flavour)['locales']
preload_pack_asset "locales/#{current_flavour}/#{I18n.locale}-json.js" if supported_locales.include?(I18n.locale.to_s)
end
def flavoured_javascript_pack_tag(pack_name, **options)
javascript_pack_tag("flavours/#{current_flavour}/#{pack_name}", **options)
end
def preload_signed_in_js_packs
preload_files = Themes.instance.flavour(current_flavour)&.fetch('signed_in_preload', nil) || []
safe_join(preload_files.map { |entry| preload_pack_asset entry })
end
private private
def storage_host_var def storage_host_var

View File

@ -1,32 +1,12 @@
# (REQUIRED) The location of the pack files. # (REQUIRED) The directory which contains the entry point files.
pack: pack_directory: app/javascript/flavours/glitch/packs
admin:
- admin.tsx # (OPTIONAL) Define files to be preloaded when a logged-in user is
- public.tsx # visiting the main web app.
auth: signed_in_preload:
- public.tsx - flavours/glitch/async/compose.js
- two_factor_authentication.js - flavours/glitch/async/home_timeline.js
common: - flavours/glitch/async/notifications.js
filename: common.js
stylesheet: true
error: error.js
application:
filename: application.js
preload:
- flavours/glitch/async/compose
- flavours/glitch/async/home_timeline
- flavours/glitch/async/notifications
inert:
filename: inert.js
stylesheet: true
mailer:
filename: mailer.js
stylesheet: true
public: public.tsx
settings: public.tsx
sign_up: sign_up.js
share: share.jsx
remote_interaction_helper: remote_interaction_helper.ts
# (OPTIONAL) The directory which contains localization files for # (OPTIONAL) The directory which contains localization files for
# the flavour, relative to this directory. The contents of this # the flavour, relative to this directory. The contents of this
@ -40,14 +20,3 @@ inherit_locales: vanilla
# (OPTIONAL) A file to use as the preview screenshot for the flavour, # (OPTIONAL) A file to use as the preview screenshot for the flavour,
# or an array thereof. These are the full path from `app/javascript/`. # or an array thereof. These are the full path from `app/javascript/`.
screenshot: flavours/glitch/images/glitch-preview.png screenshot: flavours/glitch/images/glitch-preview.png
# (OPTIONAL) The directory which contains the pack files.
# Defaults to this directory (`app/javascript/flavour/[flavour]`),
# but in the case of the vanilla Mastodon flavour the pack files are
# somewhere else.
pack_directory: app/javascript/flavours/glitch/packs
# (OPTIONAL) The directory which contains the pack files.
# Defaults to the theme directory (`app/javascript/themes/[theme]`),
# which should be sufficient for like 99% of use-cases lol.
# pack_directory: app/javascript/packs

View File

@ -1,32 +1,12 @@
# (REQUIRED) The location of the pack files inside `pack_directory`. # (REQUIRED) The directory which contains the pack files.
pack: pack_directory: app/javascript/packs
admin:
- admin.tsx # (OPTIONAL) Define files to be preloaded when a logged-in user is
- public.tsx # visiting the main web app.
auth: signed_in_preload:
- public.tsx - features/compose.js
- two_factor_authentication.js - features/home_timeline.js
common: - features/notifications.js
filename: common.js
stylesheet: true
error: error.js
application:
filename: application.js
preload:
- features/compose
- features/home_timeline
- features/notifications
inert:
filename: inert.js
stylesheet: true
mailer:
filename: mailer.js
stylesheet: true
public: public.tsx
settings: public.tsx
sign_up: sign_up.js
share: share.jsx
remote_interaction_helper: remote_interaction_helper.ts
# (OPTIONAL) The directory which contains localization files for # (OPTIONAL) The directory which contains localization files for
# the flavour, relative to this directory. # the flavour, relative to this directory.
@ -35,9 +15,3 @@ locales: ../../mastodon/locales
# (OPTIONAL) A file to use as the preview screenshot for the flavour, # (OPTIONAL) A file to use as the preview screenshot for the flavour,
# or an array thereof. These are the full path from `app/javascript/`. # or an array thereof. These are the full path from `app/javascript/`.
screenshot: images/screenshot.png screenshot: images/screenshot.png
# (OPTIONAL) The directory which contains the pack files.
# Defaults to this directory (`app/javascript/flavour/[flavour]`),
# but in the case of the vanilla Mastodon flavour the pack files are
# somewhere else.
pack_directory: app/javascript/packs

View File

@ -11,7 +11,7 @@ class Themes
Rails.root.glob('app/javascript/flavours/*/theme.yml') do |pathname| Rails.root.glob('app/javascript/flavours/*/theme.yml') do |pathname|
data = YAML.load_file(pathname) data = YAML.load_file(pathname)
next unless data['pack'] next unless data['pack_directory']
dir = pathname.dirname dir = pathname.dirname
name = dir.basename.to_s name = dir.basename.to_s

View File

@ -1,6 +1,8 @@
- content_for :page_title do - content_for :page_title do
= t('auth.login') = t('auth.login')
= flavoured_javascript_pack_tag 'two_factor_authentication', crossorigin: 'anonymous'
- if webauthn_enabled? - if webauthn_enabled?
= render partial: 'auth/sessions/two_factor/webauthn_form', locals: { hidden: @scheme_type != 'webauthn' } = render partial: 'auth/sessions/two_factor/webauthn_form', locals: { hidden: @scheme_type != 'webauthn' }

View File

@ -1,6 +1,8 @@
- content_for :page_title do - content_for :page_title do
= t('auth.setup.title') = t('auth.setup.title')
= flavoured_javascript_pack_tag 'sign_up', crossorigin: 'anonymous'
= simple_form_for(@user, url: auth_setup_path) do |f| = simple_form_for(@user, url: auth_setup_path) do |f|
= render 'auth/shared/progress', stage: 'confirm' = render 'auth/shared/progress', stage: 'confirm'

View File

@ -1,5 +0,0 @@
- if theme && theme[:pack]
- pack_path = "flavours/#{theme[:flavour]}/#{theme[:pack]}"
= javascript_pack_tag pack_path, crossorigin: 'anonymous'
- theme[:preload]&.each do |link|
%link{ href: asset_pack_path("#{link}.js"), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/

View File

@ -1,5 +1,7 @@
- content_for :header_tags do - content_for :header_tags do
= render_initial_state = render_initial_state
= flavoured_javascript_pack_tag 'public', crossorigin: 'anonymous'
= flavoured_javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
- content_for :content do - content_for :content do
.admin-wrapper .admin-wrapper

View File

@ -33,11 +33,7 @@
= stylesheet_pack_tag 'flavours/vanilla/inert', media: 'all', id: 'inert-style' = stylesheet_pack_tag 'flavours/vanilla/inert', media: 'all', id: 'inert-style'
= javascript_pack_tag 'common', crossorigin: 'anonymous' = javascript_pack_tag 'common', crossorigin: 'anonymous'
- if @theme = preload_locale_pack
- if @theme[:supported_locales].include? I18n.locale.to_s
= preload_pack_asset "locales/#{@theme[:flavour]}/#{I18n.locale}-json.js"
- elsif @theme[:supported_locales].include? 'en'
= preload_pack_asset "locales/#{@theme[:flavour]}/en-json.js"
= csrf_meta_tags unless skip_csrf_meta_tags? = csrf_meta_tags unless skip_csrf_meta_tags?
%meta{ name: 'style-nonce', content: request.content_security_policy_nonce } %meta{ name: 'style-nonce', content: request.content_security_policy_nonce }
@ -45,9 +41,6 @@
= yield :header_tags = yield :header_tags
-# These must come after :header_tags to ensure our initial state has been defined.
= render partial: 'layouts/theme', object: @theme
%body{ class: body_classes } %body{ class: body_classes }
= content_for?(:content) ? yield(:content) : yield = content_for?(:content) ? yield(:content) : yield

View File

@ -1,3 +1,6 @@
- content_for :header_tags do
= flavoured_javascript_pack_tag 'public', crossorigin: 'anonymous'
- content_for :content do - content_for :content do
.container-alt .container-alt
.logo-container .logo-container

View File

@ -14,14 +14,9 @@
= stylesheet_pack_tag 'flavours/vanilla/common', media: 'all', crossorigin: 'anonymous' # upstream uses `common` but that's implicitly defined = stylesheet_pack_tag 'flavours/vanilla/common', media: 'all', crossorigin: 'anonymous' # upstream uses `common` but that's implicitly defined
= stylesheet_pack_tag current_theme, media: 'all', crossorigin: 'anonymous' = stylesheet_pack_tag current_theme, media: 'all', crossorigin: 'anonymous'
= javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous' = javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous'
- if @theme = preload_locale_pack
- if @theme[:supported_locales].include? I18n.locale.to_s
= preload_pack_asset "locales/#{@theme[:flavour]}/#{I18n.locale}-json.js"
- elsif @theme[:supported_locales].include? 'en'
= preload_pack_asset "locales/#{@theme[:flavour]}/en-json.js"
= preload_pack_asset "locale/#{I18n.locale}-json.js"
= render_initial_state = render_initial_state
= render partial: 'layouts/theme', object: @theme = flavoured_javascript_pack_tag 'public', integrity: true, crossorigin: 'anonymous'
%body.embed %body.embed
= yield = yield

View File

@ -8,7 +8,7 @@
= stylesheet_pack_tag 'flavours/vanilla/common', media: 'all', crossorigin: 'anonymous' # upstream uses `common` but that's implicitly defined = stylesheet_pack_tag 'flavours/vanilla/common', media: 'all', crossorigin: 'anonymous' # upstream uses `common` but that's implicitly defined
= stylesheet_pack_tag current_theme, media: 'all', crossorigin: 'anonymous' = stylesheet_pack_tag current_theme, media: 'all', crossorigin: 'anonymous'
= javascript_pack_tag 'common', crossorigin: 'anonymous' = javascript_pack_tag 'common', crossorigin: 'anonymous'
= render partial: 'layouts/theme', object: @theme || { pack: 'error', flavour: 'glitch', common: { pack: 'common', flavour: 'glitch', skin: 'default' } } = flavoured_javascript_pack_tag 'error', crossorigin: 'anonymous'
%body.error %body.error
.dialog .dialog
.dialog__illustration .dialog__illustration

View File

@ -1,3 +1,6 @@
- content_for :header_tags do
= flavoured_javascript_pack_tag 'public', crossorigin: 'anonymous'
- content_for :content do - content_for :content do
- if user_signed_in? && !@hide_header - if user_signed_in? && !@hide_header
.account-header .account-header

View File

@ -1,12 +1,6 @@
- content_for :header_tags do - content_for :header_tags do
= render_initial_state = render_initial_state
= javascript_pack_tag 'common', crossorigin: 'anonymous' = flavoured_javascript_pack_tag 'public', crossorigin: 'anonymous'
- if @theme
- if @theme[:supported_locales].include? I18n.locale.to_s
= preload_pack_asset "locales/#{@theme[:flavour]}/#{I18n.locale}-json.js"
- elsif @theme[:supported_locales].include? 'en'
= preload_pack_asset "locales/#{@theme[:flavour]}/en-json.js"
= render partial: 'layouts/theme', object: @theme
:ruby :ruby
meta = @media_attachment.file.meta || {} meta = @media_attachment.file.meta || {}

View File

@ -1,6 +1,9 @@
- content_for :page_title do - content_for :page_title do
= t('settings.relationships') = t('settings.relationships')
- content_for :header_tags do
= flavoured_javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
.filters .filters
.filter-subset .filter-subset
%strong= t 'relationships.relationship' %strong= t 'relationships.relationship'

View File

@ -1,4 +1,4 @@
- content_for :header_tags do - content_for :header_tags do
%meta{ name: 'robots', content: 'noindex' }/ %meta{ name: 'robots', content: 'noindex' }/
= javascript_pack_tag 'flavours/vanilla/remote_interaction_helper', crossorigin: 'anonymous' = flavoured_javascript_pack_tag 'remote_interaction_helper', crossorigin: 'anonymous'

View File

@ -12,3 +12,5 @@
.actions .actions
= f.button :button, t('webauthn_credentials.add'), class: 'js-webauthn', type: :submit = f.button :button, t('webauthn_credentials.add'), class: 'js-webauthn', type: :submit
= flavoured_javascript_pack_tag 'two_factor_authentication', crossorigin: 'anonymous'

View File

@ -1,10 +1,12 @@
- content_for :header_tags do - content_for :header_tags do
- if user_signed_in? - if user_signed_in?
= preload_signed_in_js_packs
%meta{ name: 'initialPath', content: request.path } %meta{ name: 'initialPath', content: request.path }
%meta{ name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key } %meta{ name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key }
= render_initial_state = render_initial_state
= flavoured_javascript_pack_tag 'application', crossorigin: 'anonymous'
.notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } .notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } }
%noscript %noscript

View File

@ -1,4 +1,5 @@
- content_for :header_tags do - content_for :header_tags do
= render_initial_state = render_initial_state
= flavoured_javascript_pack_tag 'share', crossorigin: 'anonymous'
#mastodon-compose{ data: { props: Oj.dump(default_props) } } #mastodon-compose{ data: { props: Oj.dump(default_props) } }

View File

@ -14,18 +14,15 @@ const skinFiles = glob.sync('app/javascript/skins/*/*');
const flavours = {}; const flavours = {};
flavourFiles.forEach((flavourFile) => { flavourFiles.forEach((flavourFile) => {
const data = load(readFileSync(flavourFile), 'utf8'); const { locales, inherit_locales, pack_directory } = load(readFileSync(flavourFile), 'utf8');
data.name = basename(dirname(flavourFile));
data.skin = {}; flavours[basename(dirname(flavourFile))] = {
if (!data.pack_directory) { name: basename(dirname(flavourFile)),
data.pack_directory = dirname(flavourFile); locales: locales ? join(dirname(flavourFile), locales) : null,
} inherit_locales,
if (data.locales) { pack_directory: pack_directory,
data.locales = join(dirname(flavourFile), data.locales); skin: {},
} };
if (data.pack && typeof data.pack === 'object') {
flavours[data.name] = data;
}
}); });
skinFiles.forEach((skinFile) => { skinFiles.forEach((skinFile) => {

View File

@ -1,36 +1,26 @@
// Note: You must restart bin/webpack-dev-server for changes to take effect // Note: You must restart bin/webpack-dev-server for changes to take effect
const { resolve } = require('path'); const { basename, dirname, join, relative, resolve } = require('path');
const CircularDependencyPlugin = require('circular-dependency-plugin'); const CircularDependencyPlugin = require('circular-dependency-plugin');
const { sync } = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const extname = require('path-complete-extname');
const webpack = require('webpack'); const webpack = require('webpack');
const AssetsManifestPlugin = require('webpack-assets-manifest'); const AssetsManifestPlugin = require('webpack-assets-manifest');
const { env, settings, flavours, output } = require('./configuration'); const { env, settings, flavours, output } = require('./configuration');
const rules = require('./rules'); const rules = require('./rules');
function reducePacks (data, into = {}) { const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
if (!data.pack) return into;
for (const entry in data.pack) { function reduceFlavourPacks(data, into = {}) {
const pack = data.pack[entry]; const packPaths = sync(join(data.pack_directory, extensionGlob));
if (!pack) continue;
let packFiles = []; packPaths.forEach((entry) => {
if (typeof pack === 'string') const namespace = relative(join(data.pack_directory), dirname(entry));
packFiles = [pack]; into[`flavours/${data.name}/${join(namespace, basename(entry, extname(entry)))}`] = resolve(entry);
else if (Array.isArray(pack)) });
packFiles = pack;
else
packFiles = [pack.filename];
if (packFiles) {
into[`flavours/${data.name}/${entry}`] = packFiles.map(packFile => resolve(data.pack_directory, packFile));
}
}
if (!data.name) return into;
for (const skinName in data.skin) { for (const skinName in data.skin) {
const skin = data.skin[skinName]; const skin = data.skin[skinName];
@ -43,7 +33,7 @@ function reducePacks (data, into = {}) {
} }
const entries = Object.assign( const entries = Object.assign(
Object.values(flavours).reduce((map, data) => reducePacks(data, map), {}), Object.values(flavours).reduce((map, data) => reduceFlavourPacks(data, map), {}),
); );

View File

@ -4,7 +4,7 @@ require 'rails_helper'
describe 'statuses/show.html.haml', :without_verify_partial_doubles do describe 'statuses/show.html.haml', :without_verify_partial_doubles do
before do before do
allow(view).to receive_messages(api_oembed_url: '', site_title: 'example site', site_hostname: 'example.com', full_asset_url: '//asset.host/image.svg', current_account: nil, single_user_mode?: false) allow(view).to receive_messages(api_oembed_url: '', site_title: 'example site', site_hostname: 'example.com', full_asset_url: '//asset.host/image.svg', current_flavour: 'glitch', current_account: nil, single_user_mode?: false)
allow(view).to receive(:local_time) allow(view).to receive(:local_time)
allow(view).to receive(:local_time_ago) allow(view).to receive(:local_time_ago)
assign(:instance_presenter, InstancePresenter.new) assign(:instance_presenter, InstancePresenter.new)