When using automatic file includes (es6, hbs) from plugins, allow the
asset pipeline to find new and deleted files with deleting the `tmp` folder and restarting the server.
This commit is contained in:
parent
663cd93c6d
commit
e76449d800
|
@ -6,4 +6,16 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
%>
|
||||
|
|
|
@ -4,23 +4,27 @@
|
|||
class DiscoursePluginRegistry
|
||||
|
||||
class << self
|
||||
attr_accessor :javascripts
|
||||
attr_accessor :server_side_javascripts
|
||||
attr_accessor :admin_javascripts
|
||||
attr_accessor :stylesheets
|
||||
attr_accessor :mobile_stylesheets
|
||||
attr_accessor :desktop_stylesheets
|
||||
attr_accessor :sass_variables
|
||||
attr_accessor :handlebars
|
||||
attr_accessor :custom_html
|
||||
attr_accessor :serialized_current_user_fields
|
||||
attr_writer :javascripts
|
||||
attr_writer :server_side_javascripts
|
||||
attr_writer :admin_javascripts
|
||||
attr_writer :stylesheets
|
||||
attr_writer :mobile_stylesheets
|
||||
attr_writer :desktop_stylesheets
|
||||
attr_writer :sass_variables
|
||||
attr_writer :handlebars
|
||||
attr_writer :serialized_current_user_fields
|
||||
|
||||
attr_accessor :custom_html
|
||||
|
||||
# Default accessor values
|
||||
def javascripts
|
||||
@javascripts ||= Set.new
|
||||
end
|
||||
|
||||
def asset_globs
|
||||
@asset_globs ||= Set.new
|
||||
end
|
||||
|
||||
def admin_javascripts
|
||||
@admin_javascripts ||= Set.new
|
||||
end
|
||||
|
@ -68,6 +72,10 @@ class DiscoursePluginRegistry
|
|||
Archetype.register(name, options)
|
||||
end
|
||||
|
||||
def self.register_glob(root, extension)
|
||||
self.asset_globs << [root, extension]
|
||||
end
|
||||
|
||||
def self.register_asset(asset, opts=nil)
|
||||
if asset =~ /\.js$|\.js\.erb$|\.js\.es6$/
|
||||
if opts == :admin
|
||||
|
@ -143,6 +151,7 @@ class DiscoursePluginRegistry
|
|||
desktop_stylesheets.clear
|
||||
sass_variables.clear
|
||||
serialized_current_user_fields
|
||||
asset_globs.clear
|
||||
end
|
||||
|
||||
def self.setup(plugin_class)
|
||||
|
|
|
@ -26,19 +26,10 @@ class Plugin::Instance
|
|||
@color_schemes = []
|
||||
|
||||
if @path
|
||||
|
||||
# Automatically include all ES6 JS files
|
||||
dir = File.dirname(@path)
|
||||
Dir.glob("#{dir}/assets/javascripts/**/*.js.es6") do |f|
|
||||
relative = f.sub("#{dir}/assets/", "")
|
||||
register_asset(relative)
|
||||
end
|
||||
|
||||
# Automatically include all hbs files
|
||||
Dir.glob("#{dir}/assets/javascripts/**/*.hbs") do |f|
|
||||
relative = f.sub("#{dir}/assets/", "")
|
||||
register_asset(relative)
|
||||
end
|
||||
# Automatically include all ES6 JS and hbs files
|
||||
root_path = "#{File.dirname(@path)}/assets/javascripts"
|
||||
DiscoursePluginRegistry.register_glob(root_path, 'js.es6')
|
||||
DiscoursePluginRegistry.register_glob(root_path, 'hbs')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue