Extracted default value initializers.
This commit is contained in:
parent
54260fd766
commit
0cf68e2714
|
@ -9,10 +9,21 @@ class DiscoursePluginRegistry
|
|||
attr_accessor :stylesheets
|
||||
end
|
||||
|
||||
def register_js(filename, options={})
|
||||
self.class.javascripts ||= Set.new
|
||||
self.class.server_side_javascripts ||= Set.new
|
||||
# Default accessor values
|
||||
#
|
||||
def self.stylesheets
|
||||
@stylesheets ||= Set.new
|
||||
end
|
||||
|
||||
def self.javascripts
|
||||
@javascripts ||= Set.new
|
||||
end
|
||||
|
||||
def self.server_side_javascripts
|
||||
@server_side_javascripts ||= Set.new
|
||||
end
|
||||
|
||||
def register_js(filename, options={})
|
||||
# If we have a server side option, add that too.
|
||||
self.class.server_side_javascripts << options[:server_side] if options[:server_side].present?
|
||||
|
||||
|
@ -20,12 +31,11 @@ class DiscoursePluginRegistry
|
|||
end
|
||||
|
||||
def register_css(filename)
|
||||
self.class.stylesheets ||= Set.new
|
||||
self.class.stylesheets << filename
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
self.class.stylesheets || Set.new
|
||||
self.class.stylesheets
|
||||
end
|
||||
|
||||
def register_archetype(name, options={})
|
||||
|
@ -33,17 +43,17 @@ class DiscoursePluginRegistry
|
|||
end
|
||||
|
||||
def server_side_javascripts
|
||||
self.class.javascripts || Set.new
|
||||
self.class.javascripts
|
||||
end
|
||||
|
||||
def javascripts
|
||||
self.class.javascripts || Set.new
|
||||
self.class.javascripts
|
||||
end
|
||||
|
||||
def self.clear
|
||||
self.stylesheets = Set.new
|
||||
self.server_side_javascripts = Set.new
|
||||
self.javascripts = Set.new
|
||||
self.stylesheets = nil
|
||||
self.server_side_javascripts = nil
|
||||
self.javascripts = nil
|
||||
end
|
||||
|
||||
def self.setup(plugin_class)
|
||||
|
@ -52,6 +62,4 @@ class DiscoursePluginRegistry
|
|||
plugin.setup
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -4,6 +4,27 @@ require 'discourse_plugin_registry'
|
|||
describe DiscoursePluginRegistry do
|
||||
|
||||
let(:registry) { DiscoursePluginRegistry.new }
|
||||
|
||||
context '#stylesheets' do
|
||||
it 'defaults to an empty Set' do
|
||||
DiscoursePluginRegistry.stylesheets = nil
|
||||
DiscoursePluginRegistry.stylesheets.should == Set.new
|
||||
end
|
||||
end
|
||||
|
||||
context '#javascripts' do
|
||||
it 'defaults to an empty Set' do
|
||||
DiscoursePluginRegistry.javascripts = nil
|
||||
DiscoursePluginRegistry.javascripts.should == Set.new
|
||||
end
|
||||
end
|
||||
|
||||
context '#server_side_javascripts' do
|
||||
it 'defaults to an empty Set' do
|
||||
DiscoursePluginRegistry.server_side_javascripts = nil
|
||||
DiscoursePluginRegistry.server_side_javascripts.should == Set.new
|
||||
end
|
||||
end
|
||||
|
||||
context '.register_css' do
|
||||
before do
|
||||
|
|
Loading…
Reference in New Issue