discourse/lib/discourse_plugin_registry.rb

74 lines
1.4 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05: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
attr_accessor :handlebars
2013-02-05 14:16:51 -05:00
# Default accessor values
def javascripts
@javascripts ||= Set.new
end
2013-02-25 11:42:20 -05:00
def server_side_javascripts
@server_side_javascripts ||= Set.new
end
2013-02-05 14:16:51 -05:00
def stylesheets
@stylesheets ||= Set.new
end
def handlebars
@handlebars ||= Set.new
end
end
2013-02-08 02:56:12 -05:00
def register_js(filename, options={})
2013-02-05 14:16:51 -05: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 register_archetype(name, options={})
Archetype.register(name, options)
end
def javascripts
2013-02-08 02:56:12 -05:00
self.class.javascripts
2013-02-05 14:16:51 -05:00
end
def server_side_javascripts
self.class.server_side_javascripts
end
def stylesheets
self.class.stylesheets
2013-02-05 14:16:51 -05:00
end
def handlebars
self.class.handlebars
end
2013-02-05 14:16:51 -05:00
def self.clear
2013-02-08 02:56:12 -05:00
self.javascripts = nil
self.server_side_javascripts = nil
self.stylesheets = nil
self.handlebars = nil
2013-02-05 14:16:51 -05:00
end
2013-02-25 11:42:20 -05:00
def self.setup(plugin_class)
2013-02-05 14:16:51 -05:00
registry = DiscoursePluginRegistry.new
plugin = plugin_class.new(registry)
plugin.setup
end
end