mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
This reverts commita53d8d3e61and105634435f. Reverted because the change broke some components. Will be added back in a few days.
This commit is contained in:
@@ -94,38 +94,10 @@ class ThemeField < ActiveRecord::Base
|
||||
node.remove
|
||||
end
|
||||
|
||||
doc.css('script[type="text/discourse-plugin"]').each_with_index do |node, index|
|
||||
version = node['version']
|
||||
next if version.blank?
|
||||
|
||||
initializer_name = "theme-field" +
|
||||
"-#{self.id}" +
|
||||
"-#{Theme.targets[self.target_id]}" +
|
||||
"-#{ThemeField.types[self.type_id]}" +
|
||||
"-script-#{index + 1}"
|
||||
doc.css('script[type="text/discourse-plugin"]').each do |node|
|
||||
next unless node['version'].present?
|
||||
begin
|
||||
js = <<~JS
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { rescueThemeError } from "discourse/lib/utilities";
|
||||
|
||||
const __theme_name__ = #{self.theme.name.to_s.inspect};
|
||||
export default {
|
||||
name: #{initializer_name.inspect},
|
||||
after: "inject-objects",
|
||||
|
||||
initialize() {
|
||||
withPluginApi(#{version.inspect}, (api) => {
|
||||
try {
|
||||
#{node.inner_html}
|
||||
} catch(err) {
|
||||
rescueThemeError(__theme_name__, err, api);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
JS
|
||||
|
||||
js_compiler.append_module(js, "discourse/initializers/#{initializer_name}", include_variables: true)
|
||||
js_compiler.append_plugin_script(node.inner_html, node['version'])
|
||||
rescue ThemeJavascriptCompiler::CompileError => ex
|
||||
errors << ex.message
|
||||
end
|
||||
@@ -160,7 +132,7 @@ class ThemeField < ActiveRecord::Base
|
||||
begin
|
||||
case extension
|
||||
when "js.es6", "js"
|
||||
js_compiler.append_module(content, filename, include_variables: true)
|
||||
js_compiler.append_module(content, filename)
|
||||
when "hbs"
|
||||
js_compiler.append_ember_template(filename.sub("discourse/templates/", ""), content)
|
||||
when "hbr", "raw.hbs"
|
||||
@@ -313,10 +285,6 @@ class ThemeField < ActiveRecord::Base
|
||||
Theme.targets[self.target_id] == :extra_js
|
||||
end
|
||||
|
||||
def js_tests_field?
|
||||
Theme.targets[self.target_id] == :tests_js
|
||||
end
|
||||
|
||||
def basic_scss_field?
|
||||
ThemeField.basic_targets.include?(Theme.targets[self.target_id].to_s) &&
|
||||
ThemeField.scss_fields.include?(self.name)
|
||||
@@ -347,7 +315,7 @@ class ThemeField < ActiveRecord::Base
|
||||
self.error = nil unless self.error.present?
|
||||
self.compiler_version = Theme.compiler_version
|
||||
DB.after_commit { CSP::Extension.clear_theme_extensions_cache! }
|
||||
elsif extra_js_field? || js_tests_field?
|
||||
elsif extra_js_field?
|
||||
self.value_baked, self.error = process_extra_js(self.value)
|
||||
self.error = nil unless self.error.present?
|
||||
self.compiler_version = Theme.compiler_version
|
||||
@@ -454,7 +422,7 @@ class ThemeField < ActiveRecord::Base
|
||||
hash = {}
|
||||
OPTIONS.each do |option|
|
||||
plural = :"#{option}s"
|
||||
hash[option] = @allowed_values[plural][0] if @allowed_values[plural]&.length == 1
|
||||
hash[option] = @allowed_values[plural][0] if @allowed_values[plural] && @allowed_values[plural].length == 1
|
||||
hash[option] = match[option] if hash[option].nil?
|
||||
end
|
||||
hash
|
||||
@@ -489,9 +457,6 @@ class ThemeField < ActiveRecord::Base
|
||||
ThemeFileMatcher.new(regex: /^javascripts\/(?<name>.+)$/,
|
||||
targets: :extra_js, names: nil, types: :js,
|
||||
canonical: -> (h) { "javascripts/#{h[:name]}" }),
|
||||
ThemeFileMatcher.new(regex: /^test\/(?<name>.+)$/,
|
||||
targets: :tests_js, names: nil, types: :js,
|
||||
canonical: -> (h) { "test/#{h[:name]}" }),
|
||||
ThemeFileMatcher.new(regex: /^settings\.ya?ml$/,
|
||||
names: "yaml", types: :yaml, targets: :settings,
|
||||
canonical: -> (h) { "settings.yml" }),
|
||||
|
||||
Reference in New Issue
Block a user