Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: treat theme_uploads as settings in JavaScript

Sam Saffron719a93c312b9
diff --git a/app/models/theme.rb b/app/models/theme.rb
index d5d855434be..a307d3ac05a 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -430,6 +430,16 @@ class Theme < ActiveRecord::Base
self.settings.each do |setting|
hash[setting.name] = setting.value
end
+
+ theme_uploads = {}
+ theme_fields
+ .joins(:upload)
+ .where(type_id: ThemeField.types[:theme_upload_var]).each do |field|
+
+ theme_uploads[field.name] = field.upload.url
+ end
+ hash['theme_uploads'] = theme_uploads if theme_uploads.present?
+
hash
end
end
diff --git a/lib/stylesheet/importer.rb b/lib/stylesheet/importer.rb
index 7258a99978f..d06b4dbf0d7 100644
--- a/lib/stylesheet/importer.rb
+++ b/lib/stylesheet/importer.rb
@@ -63,6 +63,7 @@ module Stylesheet
end
theme&.included_settings&.each do |name, value|
+ next if name == "theme_uploads"
contents << to_scss_variable(name, value)
end
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index d760a5fc207..fb47cfb50df 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -546,6 +546,18 @@ HTML
expect(messages.first.data.map { |d| d[:target] }).to contain_exactly(:admin, :desktop, :desktop_theme, :mobile, :mobile_theme)
end
+ it 'includes theme_uploads in settings' do
+ Theme.destroy_all
+
+ upload = Fabricate(:upload)
+ theme.set_field(type: :theme_upload_var, target: :common, name: "bob", upload_id: upload.id)
+ theme.save!
+
+ json = JSON.parse(cached_settings(theme.id))
+
+ expect(json["theme_uploads"]["bob"]).to eq(upload.url)
+ end
+
it 'handles settings cache correctly' do
Theme.destroy_all