Merge pull request #2136 from ligthyear/plugins-admin-js

Enable Admin-Javascript for plugins
This commit is contained in:
Régis Hanol 2014-03-17 14:33:56 +01:00
commit 3fb7d0c3f8
4 changed files with 26 additions and 1 deletions

View File

@ -7,4 +7,6 @@ end
require_asset("main_include_admin.js") require_asset("main_include_admin.js")
DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) }
%> %>

View File

@ -6,6 +6,7 @@ class DiscoursePluginRegistry
class << self class << self
attr_accessor :javascripts attr_accessor :javascripts
attr_accessor :server_side_javascripts attr_accessor :server_side_javascripts
attr_accessor :admin_javascripts
attr_accessor :stylesheets attr_accessor :stylesheets
attr_accessor :handlebars attr_accessor :handlebars
@ -14,6 +15,10 @@ class DiscoursePluginRegistry
@javascripts ||= Set.new @javascripts ||= Set.new
end end
def admin_javascripts
@admin_javascripts ||= Set.new
end
def server_side_javascripts def server_side_javascripts
@server_side_javascripts ||= Set.new @server_side_javascripts ||= Set.new
end end

View File

@ -95,7 +95,12 @@ class Plugin::Instance
def register_asset(file,opts=nil) def register_asset(file,opts=nil)
full_path = File.dirname(path) << "/assets/" << file 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 if opts == :server_side
@server_side_javascripts ||= [] @server_side_javascripts ||= []
@server_side_javascripts << full_path @server_side_javascripts << full_path
@ -167,6 +172,12 @@ class Plugin::Instance
Rails.configuration.assets.paths << File.dirname(path) + "/assets" Rails.configuration.assets.paths << File.dirname(path) + "/assets"
end end
if @admin_javascripts
@admin_javascripts.each do |js|
DiscoursePluginRegistry.admin_javascripts << js
end
end
if @server_side_javascripts if @server_side_javascripts
@server_side_javascripts.each do |js| @server_side_javascripts.each do |js|
DiscoursePluginRegistry.server_side_javascripts << js DiscoursePluginRegistry.server_side_javascripts << js

View File

@ -26,6 +26,13 @@ describe DiscoursePluginRegistry do
end end
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 context '.register_css' do
before do before do
registry.register_css('hello.css') registry.register_css('hello.css')