mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Add support for plugins to declare ES6 in the admin bundle
This commit is contained in:
parent
2d4729782e
commit
7eb32be4de
4 changed files with 34 additions and 11 deletions
|
@ -2,4 +2,12 @@
|
|||
require_asset("main_include_admin.js")
|
||||
|
||||
DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) }
|
||||
|
||||
DiscoursePluginRegistry.each_globbed_asset(admin: true) do |f, ext|
|
||||
if File.directory?(f)
|
||||
depend_on(f)
|
||||
elsif f.to_s.end_with?(".#{ext}")
|
||||
require_asset(f)
|
||||
end
|
||||
end
|
||||
%>
|
||||
|
|
|
@ -6,15 +6,11 @@ require_asset ("./main_include.js")
|
|||
DiscoursePluginRegistry.javascripts.each { |js| require_asset(js) }
|
||||
DiscoursePluginRegistry.handlebars.each { |hb| require_asset(hb) }
|
||||
|
||||
# Load any glob dependencies
|
||||
DiscoursePluginRegistry.asset_globs.each do |g|
|
||||
root, extension = *g
|
||||
Dir.glob("#{root}/**/*") do |f|
|
||||
if File.directory?(f)
|
||||
depend_on(f)
|
||||
elsif f.to_s.end_with?(".#{extension}")
|
||||
require_asset(f)
|
||||
end
|
||||
DiscoursePluginRegistry.each_globbed_asset do |f, ext|
|
||||
if File.directory?(f)
|
||||
depend_on(f)
|
||||
elsif f.to_s.end_with?(".#{ext}")
|
||||
require_asset(f)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -77,8 +77,22 @@ class DiscoursePluginRegistry
|
|||
Archetype.register(name, options)
|
||||
end
|
||||
|
||||
def self.register_glob(root, extension)
|
||||
self.asset_globs << [root, extension]
|
||||
def self.register_glob(root, extension, options=nil)
|
||||
self.asset_globs << [root, extension, options || {}]
|
||||
end
|
||||
|
||||
def self.each_globbed_asset(each_options=nil)
|
||||
each_options ||= {}
|
||||
|
||||
self.asset_globs.each do |g|
|
||||
root, ext, options = *g
|
||||
|
||||
next if options[:admin] && !each_options[:admin]
|
||||
|
||||
Dir.glob("#{root}/**/*") do |f|
|
||||
yield f, ext
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.register_asset(asset, opts=nil)
|
||||
|
|
|
@ -223,6 +223,10 @@ class Plugin::Instance
|
|||
root_path = "#{File.dirname(@path)}/assets/javascripts"
|
||||
DiscoursePluginRegistry.register_glob(root_path, 'js.es6')
|
||||
DiscoursePluginRegistry.register_glob(root_path, 'hbs')
|
||||
|
||||
admin_path = "#{File.dirname(@path)}/admin/assets/javascripts"
|
||||
DiscoursePluginRegistry.register_glob(admin_path, 'js.es6', admin: true)
|
||||
DiscoursePluginRegistry.register_glob(admin_path, 'hbs', admin: true)
|
||||
end
|
||||
|
||||
self.instance_eval File.read(path), path
|
||||
|
@ -241,6 +245,7 @@ class Plugin::Instance
|
|||
# Automatically include assets
|
||||
Rails.configuration.assets.paths << auto_generated_path
|
||||
Rails.configuration.assets.paths << File.dirname(path) + "/assets"
|
||||
Rails.configuration.assets.paths << File.dirname(path) + "/admin/assets"
|
||||
|
||||
# Automatically include rake tasks
|
||||
Rake.add_rakelib(File.dirname(path) + "/lib/tasks")
|
||||
|
|
Loading…
Reference in a new issue