FEATURE: backend support for user-selectable components

* FEATURE: backend support for user-selectable components

* fix problems with previewing default theme

* rename preview_key => preview_theme_id

* omit default theme from child themes dropdown and try a different fix

* cache & freeze stylesheets arrays
This commit is contained in:
Osama Sayegh
2018-08-08 07:46:34 +03:00
committed by Sam
parent aafff740d2
commit 0b7ed8ffaf
53 changed files with 737 additions and 355 deletions

View File

@ -1,27 +1,26 @@
class ThemesController < ::ApplicationController
def assets
theme_id = params[:id].to_i
theme_ids = params[:ids].to_s.split("-").map(&:to_i)
if params[:id] == "default"
theme_id = nil
if params[:ids] == "default"
theme_ids = nil
else
raise Discourse::NotFound unless Theme.where(id: theme_id).exists?
raise Discourse::NotFound unless guardian.allow_themes?(theme_ids)
end
object = [:mobile, :desktop, :desktop_theme, :mobile_theme].map do |target|
link = Stylesheet::Manager.stylesheet_link_tag(target, 'all', params[:id])
if link
href = link.split(/["']/)[1]
if Rails.env.development?
href << (href.include?("?") ? "&" : "?")
href << SecureRandom.hex
end
{
target: target,
url: href
}
targets = view_context.mobile_view? ? [:mobile, :mobile_theme] : [:desktop, :desktop_theme]
targets << :admin if guardian.is_staff?
object = targets.map do |target|
Stylesheet::Manager.stylesheet_data(target, theme_ids).map do |hash|
return hash unless Rails.env.development?
dup_hash = hash.dup
dup_hash[:new_href] << (dup_hash[:new_href].include?("?") ? "&" : "?")
dup_hash[:new_href] << SecureRandom.hex
dup_hash
end
end.compact
end.flatten
render json: object.as_json
end