Merge pull request #2136 from ligthyear/plugins-admin-js
Enable Admin-Javascript for plugins
This commit is contained in:
commit
3fb7d0c3f8
|
@ -7,4 +7,6 @@ end
|
|||
|
||||
require_asset("main_include_admin.js")
|
||||
|
||||
DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) }
|
||||
|
||||
%>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -95,7 +95,12 @@ class Plugin::Instance
|
|||
|
||||
def register_asset(file,opts=nil)
|
||||
full_path = File.dirname(path) << "/assets/" << file
|
||||
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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue