Class: BootstrapController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- BootstrapController
- Includes:
- ApplicationHelper
- Defined in:
- app/controllers/bootstrap_controller.rb
Constant Summary
Constants inherited from ApplicationController
ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
Constants included from CanonicalURL::ControllerExtensions
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
-
#index ⇒ Object
This endpoint allows us to produce the data required to start up Discourse via JSON API, so that you don’t have to scrape the HTML for ‘data-*` payloads.
- #plugin_css_for_tests ⇒ Object
Methods included from ApplicationHelper
#add_resource_preload_list, #admin?, #age_words, all_connectors, #allow_plugins?, #allow_third_party_plugins?, #application_logo_dark_url, #application_logo_url, #authentication_data, #body_classes, #build_plugin_html, #can_sign_up?, #category_badge, #client_side_setup_data, #crawlable_meta_data, #crawler_layout?, #current_homepage, #customization_disabled?, #dark_color_scheme?, #dark_scheme_id, #discourse_color_scheme_stylesheets, #discourse_config_environment, #discourse_csrf_tags, #discourse_preload_color_scheme_stylesheets, #discourse_stylesheet_link_tag, #discourse_stylesheet_preload_tag, #discourse_theme_color_meta_tags, #escape_unicode, extra_body_classes, #format_topic_title, #ga_universal_json, #get_absolute_image_url, #google_tag_manager_json, #google_tag_manager_nonce_placeholder, #google_universal_analytics_json, #gsub_emoji_to_unicode, #guardian, #html_classes, #html_lang, #include_crawler_content?, #include_ios_native_app_banner?, #include_splash_screen?, #ios_app_argument, #ios_device?, #is_brotli_req?, #is_gzip_req?, #loading_admin?, #login_path, #manifest_url, #mobile_device?, #mobile_view?, #moderator?, #modern_mobile_device?, #normalized_safe_mode, #preload_script, #preload_script_url, #preloaded_json, #render_sitelinks_search_tag, #replace_plugin_html, #rss_creator, #rtl?, #scheme_id, #script_asset_path, #server_plugin_outlet, #shared_session_key, #short_date, #staff?, #stylesheet_manager, #text_size_class, #theme_id, #theme_js_lookup, #theme_lookup, #theme_translations_lookup, #topic_featured_link_domain, #waving_hand_url, #with_format
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from ConfigurableUrls
#faq_path, #privacy_policy_url, #tos_url
Methods included from CanonicalURL::Helpers
Methods included from CurrentUser
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
Methods inherited from ApplicationController
#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale
Methods included from VaryHeader
Methods included from ReadOnlyMixin
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, included, #staff_writes_only_mode?
Methods included from Hijack
Methods included from JsonError
Methods included from CanonicalURL::ControllerExtensions
#canonical_url, #default_canonical, included
Instance Method Details
#index ⇒ Object
This endpoint allows us to produce the data required to start up Discourse via JSON API, so that you don’t have to scrape the HTML for ‘data-*` payloads
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/bootstrap_controller.rb', line 10 def index locale = script_asset_path("locales/#{I18n.locale}") preload_anonymous_data if current_user current_user.sync_notification_channel_position preload_current_user_data end @stylesheets = [] add_scheme(scheme_id, "all", "light-scheme") add_scheme(dark_scheme_id, "(prefers-color-scheme: dark)", "dark-scheme") if rtl? add_style(mobile_view? ? :mobile_rtl : :desktop_rtl) else add_style(mobile_view? ? :mobile : :desktop) end add_style(rtl? ? :admin_rtl : :admin) if staff? add_style(rtl? ? :wizard_rtl : :wizard) if admin? assets_fake_request = ActionDispatch::Request.new(request.env.dup) assets_for_url = params[:for_url] if assets_for_url path, query = assets_for_url.split("?", 2) assets_fake_request.env["PATH_INFO"] = path assets_fake_request.env["QUERY_STRING"] = query end Discourse .find_plugin_css_assets( include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, mobile_view: mobile_view?, desktop_view: !mobile_view?, request: assets_fake_request, rtl: rtl?, ) .each { |file| add_style(file, plugin: true) } add_style(mobile_view? ? :mobile_theme : :desktop_theme) if theme_id.present? extra_locales = [] if ExtraLocalesController.client_overrides_exist? extra_locales << ExtraLocalesController.url("overrides") end extra_locales << ExtraLocalesController.url("admin") if staff? extra_locales << ExtraLocalesController.url("wizard") if admin? plugin_js = Discourse .find_plugin_js_assets( include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, request: assets_fake_request, ) .map { |f| script_asset_path(f) } plugin_test_js = if Rails.env != "production" script_asset_path("plugin-tests") else [] end bootstrap = { theme_id: theme_id, theme_color: "##{ColorScheme.hex_for_name("header_background", scheme_id)}", title: SiteSetting.title, current_homepage: current_homepage, locale_script: locale, stylesheets: @stylesheets, plugin_js: plugin_js, plugin_test_js: plugin_test_js, setup_data: client_side_setup_data, preloaded: @preloaded, html: create_html, theme_html: create_theme_html, html_classes: html_classes, html_lang: html_lang, login_path: main_app.login_path, authentication_data: authentication_data, } bootstrap[:extra_locales] = extra_locales if extra_locales.present? bootstrap[:csrf_token] = form_authenticity_token if current_user render_json_dump(bootstrap: bootstrap) end |
#plugin_css_for_tests ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/bootstrap_controller.rb', line 101 def plugin_css_for_tests urls = Discourse .find_plugin_css_assets(include_disabled: true, desktop_view: true) .map do |target| details = Stylesheet::Manager.new().stylesheet_details(target, "all") details[0][:new_href] end stylesheet = <<~CSS /* For use in tests only - `@import`s all plugin stylesheets */ #{urls.map { |url| "@import \"#{url}\";" }.join("\n")} CSS render plain: stylesheet, content_type: "text/css" end |