diff --git a/app/assets/javascripts/admin.js.erb b/app/assets/javascripts/admin.js.erb index aa336ccd8..3c536f4ca 100644 --- a/app/assets/javascripts/admin.js.erb +++ b/app/assets/javascripts/admin.js.erb @@ -7,4 +7,6 @@ end require_asset("main_include_admin.js") +DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) } + %> diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb index f635e6347..a00d372f6 100644 --- a/lib/discourse_plugin_registry.rb +++ b/lib/discourse_plugin_registry.rb @@ -6,6 +6,7 @@ class DiscoursePluginRegistry class << self attr_accessor :javascripts attr_accessor :server_side_javascripts + attr_accessor :admin_javascripts attr_accessor :stylesheets attr_accessor :handlebars @@ -14,6 +15,10 @@ class DiscoursePluginRegistry @javascripts ||= Set.new end + def admin_javascripts + @admin_javascripts ||= Set.new + end + def server_side_javascripts @server_side_javascripts ||= Set.new end diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 27f274589..3925e5d6d 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -95,7 +95,12 @@ class Plugin::Instance def register_asset(file,opts=nil) full_path = File.dirname(path) << "/assets/" << file - assets << full_path + if opts == :admin + @admin_javascripts ||= [] + @admin_javascripts << full_path + else + assets << full_path + end if opts == :server_side @server_side_javascripts ||= [] @server_side_javascripts << full_path @@ -167,6 +172,12 @@ class Plugin::Instance Rails.configuration.assets.paths << File.dirname(path) + "/assets" end + if @admin_javascripts + @admin_javascripts.each do |js| + DiscoursePluginRegistry.admin_javascripts << js + end + end + if @server_side_javascripts @server_side_javascripts.each do |js| DiscoursePluginRegistry.server_side_javascripts << js diff --git a/spec/components/discourse_plugin_registry_spec.rb b/spec/components/discourse_plugin_registry_spec.rb index 3c44a91c7..c6e26ba23 100644 --- a/spec/components/discourse_plugin_registry_spec.rb +++ b/spec/components/discourse_plugin_registry_spec.rb @@ -26,6 +26,13 @@ describe DiscoursePluginRegistry do end end + context '#admin_javascripts' do + it 'defaults to an empty Set' do + DiscoursePluginRegistry.admin_javascripts = nil + DiscoursePluginRegistry.admin_javascripts.should == Set.new + end + end + context '.register_css' do before do registry.register_css('hello.css')