mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
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
3 changed files with 35 additions and 23 deletions
|
@ -6,4 +6,16 @@ require_asset ("./main_include.js")
|
||||||
DiscoursePluginRegistry.javascripts.each { |js| require_asset(js) }
|
DiscoursePluginRegistry.javascripts.each { |js| require_asset(js) }
|
||||||
DiscoursePluginRegistry.handlebars.each { |hb| require_asset(hb) }
|
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 DiscoursePluginRegistry
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :javascripts
|
attr_writer :javascripts
|
||||||
attr_accessor :server_side_javascripts
|
attr_writer :server_side_javascripts
|
||||||
attr_accessor :admin_javascripts
|
attr_writer :admin_javascripts
|
||||||
attr_accessor :stylesheets
|
attr_writer :stylesheets
|
||||||
attr_accessor :mobile_stylesheets
|
attr_writer :mobile_stylesheets
|
||||||
attr_accessor :desktop_stylesheets
|
attr_writer :desktop_stylesheets
|
||||||
attr_accessor :sass_variables
|
attr_writer :sass_variables
|
||||||
attr_accessor :handlebars
|
attr_writer :handlebars
|
||||||
attr_accessor :custom_html
|
attr_writer :serialized_current_user_fields
|
||||||
attr_accessor :serialized_current_user_fields
|
|
||||||
|
|
||||||
|
attr_accessor :custom_html
|
||||||
|
|
||||||
# Default accessor values
|
# Default accessor values
|
||||||
def javascripts
|
def javascripts
|
||||||
@javascripts ||= Set.new
|
@javascripts ||= Set.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def asset_globs
|
||||||
|
@asset_globs ||= Set.new
|
||||||
|
end
|
||||||
|
|
||||||
def admin_javascripts
|
def admin_javascripts
|
||||||
@admin_javascripts ||= Set.new
|
@admin_javascripts ||= Set.new
|
||||||
end
|
end
|
||||||
|
@ -68,6 +72,10 @@ class DiscoursePluginRegistry
|
||||||
Archetype.register(name, options)
|
Archetype.register(name, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.register_glob(root, extension)
|
||||||
|
self.asset_globs << [root, extension]
|
||||||
|
end
|
||||||
|
|
||||||
def self.register_asset(asset, opts=nil)
|
def self.register_asset(asset, opts=nil)
|
||||||
if asset =~ /\.js$|\.js\.erb$|\.js\.es6$/
|
if asset =~ /\.js$|\.js\.erb$|\.js\.es6$/
|
||||||
if opts == :admin
|
if opts == :admin
|
||||||
|
@ -143,6 +151,7 @@ class DiscoursePluginRegistry
|
||||||
desktop_stylesheets.clear
|
desktop_stylesheets.clear
|
||||||
sass_variables.clear
|
sass_variables.clear
|
||||||
serialized_current_user_fields
|
serialized_current_user_fields
|
||||||
|
asset_globs.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.setup(plugin_class)
|
def self.setup(plugin_class)
|
||||||
|
|
|
@ -26,19 +26,10 @@ class Plugin::Instance
|
||||||
@color_schemes = []
|
@color_schemes = []
|
||||||
|
|
||||||
if @path
|
if @path
|
||||||
|
# Automatically include all ES6 JS and hbs files
|
||||||
# Automatically include all ES6 JS files
|
root_path = "#{File.dirname(@path)}/assets/javascripts"
|
||||||
dir = File.dirname(@path)
|
DiscoursePluginRegistry.register_glob(root_path, 'js.es6')
|
||||||
Dir.glob("#{dir}/assets/javascripts/**/*.js.es6") do |f|
|
DiscoursePluginRegistry.register_glob(root_path, 'hbs')
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue