FIX: Use CDN for the discourse-internet-explorer

Previously the CDN was skipped because the assets were not in the proper
place to be uploaded.
This commit is contained in:
Robin Ward 2020-01-10 15:06:15 -05:00
parent 687c79ca1c
commit 556d66a97c
2 changed files with 10 additions and 1 deletions

View File

@ -194,6 +194,7 @@ module Discourse
STDERR.puts "Could not activate #{p.metadata.name}, discourse does not meet required version (#{v})" STDERR.puts "Could not activate #{p.metadata.name}, discourse does not meet required version (#{v})"
end end
end end
DiscourseEvent.trigger(:after_plugin_activation)
end end
def self.disabled_plugin_names def self.disabled_plugin_names

View File

@ -11,6 +11,14 @@ hide_plugin if self.respond_to?(:hide_plugin)
register_asset 'stylesheets/ie.scss' register_asset 'stylesheets/ie.scss'
# We can't use register asset for an optional resource. Instead copy it after plugins have
# been activated so it can be uploaded to CDNs.
DiscourseEvent.on(:after_plugin_activation) do ||
polyfill_path = "#{Plugin::Instance.js_path}/#{self.directory_name}-optional.js"
puts polyfill_path
FileUtils.cp("#{Rails.root}/public/plugins/discourse-internet-explorer/js/ie.js", polyfill_path)
end
after_initialize do after_initialize do
# Conditionally load the stylesheet. There is unfortunately no easy way to do this via # Conditionally load the stylesheet. There is unfortunately no easy way to do this via
@ -47,7 +55,7 @@ after_initialize do
# to be loaded before other files # to be loaded before other files
register_html_builder('server:before-script-load') do |controller| register_html_builder('server:before-script-load') do |controller|
if BrowserDetection.browser(controller.request.env['HTTP_USER_AGENT']) == :ie if BrowserDetection.browser(controller.request.env['HTTP_USER_AGENT']) == :ie
path = "#{Discourse.base_uri}/plugins/discourse-internet-explorer/js/ie.js" path = controller.helpers.script_asset_path('plugins/discourse-internet-explorer-optional')
<<~JAVASCRIPT <<~JAVASCRIPT
<script src="#{path}"></script> <script src="#{path}"></script>