diff --git a/app/assets/javascripts/discourse/app/lib/theme-selector.js b/app/assets/javascripts/discourse/app/lib/theme-selector.js index 32326b4a88b..fdc4cb9517d 100644 --- a/app/assets/javascripts/discourse/app/lib/theme-selector.js +++ b/app/assets/javascripts/discourse/app/lib/theme-selector.js @@ -2,7 +2,7 @@ import cookie, { removeCookie } from "discourse/lib/cookie"; import I18n from "I18n"; import deprecated from "discourse-common/lib/deprecated"; -const keySelector = "meta[name=discourse_theme_ids]"; +const keySelector = "meta[name=discourse_theme_id]"; export function currentThemeKey() { // eslint-disable-next-line no-console diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js index 7c78d2d1f50..18f7b80c0fe 100644 --- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js +++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js @@ -34,9 +34,9 @@ function head(buffer, bootstrap) { buffer.push(``); buffer.push(``); } - if (bootstrap.theme_ids) { + if (bootstrap.theme_id) { buffer.push( - `` + `` ); } diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js index 6869f9fbad9..312fd2a82a1 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js @@ -100,7 +100,7 @@ acceptance("User Preferences - Interface", function (needs) { test("shows no default option for light scheme when theme's color scheme is user selectable", async function (assert) { let meta = document.createElement("meta"); - meta.name = "discourse_theme_ids"; + meta.name = "discourse_theme_id"; meta.content = "2"; document.getElementsByTagName("head")[0].appendChild(meta); @@ -128,7 +128,7 @@ acceptance("User Preferences - Interface", function (needs) { await selectKit(".light-color-scheme .select-kit").expand(); assert.equal(count(".light-color-scheme .select-kit .select-kit-row"), 2); - document.querySelector("meta[name='discourse_theme_ids']").remove(); + document.querySelector("meta[name='discourse_theme_id']").remove(); }); }); diff --git a/app/controllers/bootstrap_controller.rb b/app/controllers/bootstrap_controller.rb index 5bb4dc6ddb3..7840dcab3e2 100644 --- a/app/controllers/bootstrap_controller.rb +++ b/app/controllers/bootstrap_controller.rb @@ -51,7 +51,7 @@ class BootstrapController < ApplicationController ).map { |f| script_asset_path(f) } bootstrap = { - theme_ids: [theme_id], + theme_id: theme_id, title: SiteSetting.title, current_homepage: current_homepage, locale_script: locale, diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index 427f2b9203a..df53cf58030 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -47,7 +47,7 @@ class StylesheetsController < ApplicationController theme_id = if target.include?("theme") split_target, theme_id = target.split(/_(-?[0-9]+)/) - Theme.where(id: theme_id).pluck_first(:id) if theme_id.present? + theme_id if theme_id.present? && Theme.exists?(id: theme_id) else split_target, color_scheme_id = target.split(/_(-?[0-9]+)/) Theme.where(color_scheme_id: color_scheme_id).pluck_first(:id) diff --git a/app/models/theme.rb b/app/models/theme.rb index ad5f63be4c5..fe71405f192 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -203,6 +203,7 @@ class Theme < ActiveRecord::Base def self.transform_ids(id) return [] if id.blank? + id = id.to_i get_set_cache "transformed_ids_#{id}" do all_ids = @@ -297,8 +298,7 @@ class Theme < ActiveRecord::Base end def self.lookup_modifier(theme_ids, modifier_name) - theme_ids = [theme_ids] unless Array === theme_ids - theme_ids = transform_ids(theme_ids) + theme_ids = [theme_ids] unless theme_ids.is_a?(Array) get_set_cache("#{theme_ids.join(",")}:modifier:#{modifier_name}:#{Theme.compiler_version}") do ThemeModifierSet.resolve_modifier_for_themes(theme_ids, modifier_name) @@ -350,7 +350,7 @@ class Theme < ActiveRecord::Base end def self.refresh_message_for_targets(targets, theme_ids) - theme_ids = [theme_ids] unless theme_ids === Array + theme_ids = [theme_ids] unless theme_ids.is_a?(Array) targets.each_with_object([]) do |target, data| theme_ids.each do |theme_id| diff --git a/app/views/common/_discourse_publish_stylesheet.html.erb b/app/views/common/_discourse_publish_stylesheet.html.erb index 90fe9a9f9e2..ae48d98f98f 100644 --- a/app/views/common/_discourse_publish_stylesheet.html.erb +++ b/app/views/common/_discourse_publish_stylesheet.html.erb @@ -1,4 +1,4 @@ -<%= discourse_stylesheet_link_tag 'publish', theme_ids: nil %> +<%= discourse_stylesheet_link_tag 'publish', theme_id: nil %> <%- if rtl? %> <%= discourse_stylesheet_link_tag(mobile_view? ? :publish_mobile_rtl : :publish_mobile_rtl) %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 47159a614a5..b5ec502ee61 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,7 +5,7 @@