2013-02-05 13:16:51 -06:00
|
|
|
#
|
|
|
|
# A class that handles interaction between a plugin and the Discourse App.
|
|
|
|
#
|
|
|
|
class DiscoursePluginRegistry
|
|
|
|
|
|
|
|
class << self
|
|
|
|
attr_accessor :javascripts
|
|
|
|
attr_accessor :server_side_javascripts
|
|
|
|
attr_accessor :stylesheets
|
|
|
|
end
|
|
|
|
|
2013-02-08 01:56:12 -06:00
|
|
|
# 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
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2013-02-08 01:56:12 -06:00
|
|
|
def register_js(filename, options={})
|
2013-02-05 13:16:51 -06:00
|
|
|
# If we have a server side option, add that too.
|
|
|
|
self.class.server_side_javascripts << options[:server_side] if options[:server_side].present?
|
|
|
|
|
|
|
|
self.class.javascripts << filename
|
|
|
|
end
|
|
|
|
|
|
|
|
def register_css(filename)
|
|
|
|
self.class.stylesheets << filename
|
|
|
|
end
|
|
|
|
|
|
|
|
def stylesheets
|
2013-02-08 01:56:12 -06:00
|
|
|
self.class.stylesheets
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def register_archetype(name, options={})
|
|
|
|
Archetype.register(name, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_side_javascripts
|
2013-02-08 01:56:12 -06:00
|
|
|
self.class.javascripts
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def javascripts
|
2013-02-08 01:56:12 -06:00
|
|
|
self.class.javascripts
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.clear
|
2013-02-08 01:56:12 -06:00
|
|
|
self.stylesheets = nil
|
|
|
|
self.server_side_javascripts = nil
|
|
|
|
self.javascripts = nil
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.setup(plugin_class)
|
|
|
|
registry = DiscoursePluginRegistry.new
|
|
|
|
plugin = plugin_class.new(registry)
|
|
|
|
plugin.setup
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|