mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Plugins: Prefix discourse/plugins/PLUGINNAME
for plugin export names.
This commit is contained in:
@ -11,20 +11,6 @@ module ES6ModuleTranspiler
|
||||
@compile_to = target
|
||||
end
|
||||
|
||||
def self.prefix_patterns
|
||||
@prefix_patterns ||= []
|
||||
end
|
||||
|
||||
def self.add_prefix_pattern(pattern, prefix)
|
||||
prefix_patterns << [pattern, prefix]
|
||||
end
|
||||
|
||||
def self.lookup_prefix(path)
|
||||
_, prefix = prefix_patterns.detect {|pattern, prefix| pattern =~ path }
|
||||
|
||||
prefix
|
||||
end
|
||||
|
||||
def self.transform=(transform)
|
||||
@transform = transform
|
||||
end
|
||||
|
@ -83,13 +83,17 @@ module Tilt
|
||||
end
|
||||
|
||||
def module_name(root_path, logical_path)
|
||||
path = ''
|
||||
if prefix = ES6ModuleTranspiler.lookup_prefix(File.join(root_path, logical_path))
|
||||
path = File.join(prefix, logical_path)
|
||||
else
|
||||
path = logical_path
|
||||
path = nil
|
||||
|
||||
# If the resource is a plugin, use the plugin name as a prefix
|
||||
if root_path =~ /(.*\/discourse\/plugins\/[^\/]+)\//
|
||||
plugin_path = "#{Regexp.last_match[1]}/plugin.rb"
|
||||
|
||||
plugin = Discourse.plugins.find {|p| p.path == plugin_path }
|
||||
path = "discourse/plugins/#{plugin.name}/#{logical_path.sub(/javascripts\//, '')}" if plugin
|
||||
end
|
||||
|
||||
path ||= logical_path
|
||||
if ES6ModuleTranspiler.transform
|
||||
path = ES6ModuleTranspiler.transform.call(path)
|
||||
end
|
||||
|
Reference in New Issue
Block a user