0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/app/controllers/bootstrap_controller.rb
David Taylor 4ddf066a65
DEV: Use Rails to render site-settings for qunit tests (#37105)
Duplicating our site-setting parsing/serializing logic in a broccoli
plugin is not ideal. We already rely on the Rails server being available
during qunit runs, so serving the site-settings from there makes more
sense. This change will also help with the Vite migration work.
2026-01-14 12:25:12 +00:00

45 lines
1.3 KiB
Ruby
Vendored

# frozen_string_literal: true
class BootstrapController < ApplicationController
skip_before_action :redirect_to_login_if_required, :check_xhr
protect_from_forgery except: :site_settings_for_tests
def site_settings_for_tests
site_settings_json = SiteSetting.client_settings_json_uncached(return_defaults: true)
theme_site_settings_json = SiteSetting.theme_site_settings_json_uncached(nil)
render plain: <<~JS, content_type: "application/javascript"
window.CLIENT_SITE_SETTINGS_WITH_DEFAULTS = {
...#{site_settings_json},
...#{theme_site_settings_json}
};
JS
end
def plugin_css_for_tests
targets = Discourse.find_plugin_css_assets(include_disabled: true, desktop_view: true)
render_css_for_tests(targets)
end
def core_css_for_tests
targets = %w[color_definitions common desktop admin]
render_css_for_tests(targets)
end
private
def render_css_for_tests(targets)
urls =
targets.map do |target|
details = Stylesheet::Manager.new().stylesheet_details(target, "all")
details[0][:new_href]
end
stylesheet = <<~CSS
/* For use in tests only */
#{urls.map { |url| "@import \"#{url}\";" }.join("\n")}
CSS
render plain: stylesheet, content_type: "text/css"
end
end