allow apps to give custom admin javascripts

This commit is contained in:
Benjamin Kampmann 2014-03-17 13:19:08 +01:00
parent 2d49374357
commit e63b9b362e
4 changed files with 26 additions and 1 deletions

View file

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

View file

@ -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

View file

@ -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

View file

@ -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')