FEATURE: we need access to settings in theme js

This commit is contained in:
Sam
2018-03-05 15:35:41 +11:00
parent 95555b5ec8
commit 9331b4849d
3 changed files with 56 additions and 1 deletions

View File

@@ -24,10 +24,28 @@ class ThemeField < ActiveRecord::Base
belongs_to :theme
def settings(source)
settings = {}
theme.cached_settings.each do |k, v|
if source.include?("settings.#{k}")
settings[k] = v
end
end
if settings.length > 0
"let settings = #{settings.to_json};"
else
""
end
end
def transpile(es6_source, version)
template = Tilt::ES6ModuleTranspilerTemplate.new {}
wrapped = <<PLUGIN_API_JS
Discourse._registerPluginCode('#{version}', api => {
#{settings(es6_source)}
#{es6_source}
});
PLUGIN_API_JS

View File

@@ -7,6 +7,8 @@ class ThemeSetting < ActiveRecord::Base
after_save do
theme.clear_cached_settings!
theme.remove_from_cache!
theme.theme_fields.update_all(value_baked: nil)
end
def self.types