mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 07:31:54 +08:00
Do not load javascripts for disabled plugins (#5103)
* Do not load javascript for disabled plugins * Appease rubocop
This commit is contained in:

committed by
Régis Hanol

parent
8463b676df
commit
a14ab48829
31
lib/discourse_wrap_plugin_js.rb
Normal file
31
lib/discourse_wrap_plugin_js.rb
Normal file
@ -0,0 +1,31 @@
|
||||
class DiscourseWrapPluginJS
|
||||
def initialize(options = {}, &block)
|
||||
end
|
||||
|
||||
def self.instance
|
||||
@instance ||= new
|
||||
end
|
||||
|
||||
def self.call(input)
|
||||
instance.call(input)
|
||||
end
|
||||
|
||||
# Add stuff around javascript
|
||||
def call(input)
|
||||
path = input[:environment].context_class.new(input).pathname.to_s
|
||||
data = input[:data]
|
||||
|
||||
# Only apply to plugin paths
|
||||
return data unless (path =~ /\/plugins\//)
|
||||
|
||||
# Find the folder name of the plugin
|
||||
folder_name = path[/\/plugins\/(\S+?)\//, 1]
|
||||
|
||||
# Lookup plugin name
|
||||
plugin = Discourse.plugins.find { |p| p.path =~ /\/plugins\/#{folder_name}\// }
|
||||
plugin_name = plugin.name
|
||||
|
||||
"Discourse._registerPluginScriptDefinition('#{plugin_name}', function(){#{data}}); \n"
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user