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
|
2014-03-17 08:19:08 -04:00
|
|
|
attr_accessor :admin_javascripts
|
2013-02-05 14:16:51 -05:00
|
|
|
attr_accessor :stylesheets
|
2014-04-07 10:33:35 -04:00
|
|
|
attr_accessor :mobile_stylesheets
|
2014-04-25 04:26:37 -04:00
|
|
|
attr_accessor :desktop_stylesheets
|
|
|
|
attr_accessor :sass_variables
|
2013-12-31 10:40:45 -05:00
|
|
|
attr_accessor :handlebars
|
2014-06-04 21:39:33 -04:00
|
|
|
attr_accessor :custom_html
|
2014-06-10 21:57:22 -04:00
|
|
|
attr_accessor :serialized_current_user_fields
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-08-01 01:59:57 -04:00
|
|
|
# Default accessor values
|
|
|
|
def javascripts
|
|
|
|
@javascripts ||= Set.new
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2014-03-17 08:19:08 -04:00
|
|
|
def admin_javascripts
|
|
|
|
@admin_javascripts ||= Set.new
|
|
|
|
end
|
|
|
|
|
2013-08-01 01:59:57 -04:00
|
|
|
def server_side_javascripts
|
|
|
|
@server_side_javascripts ||= Set.new
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-11-19 10:42:28 -05:00
|
|
|
def stylesheets
|
|
|
|
@stylesheets ||= Set.new
|
|
|
|
end
|
2013-12-31 10:40:45 -05:00
|
|
|
|
2014-04-07 10:33:35 -04:00
|
|
|
def mobile_stylesheets
|
|
|
|
@mobile_stylesheets ||= Set.new
|
|
|
|
end
|
2014-04-25 04:26:37 -04:00
|
|
|
|
|
|
|
def desktop_stylesheets
|
|
|
|
@desktop_stylesheets ||= Set.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def sass_variables
|
|
|
|
@sass_variables ||= Set.new
|
|
|
|
end
|
|
|
|
|
2013-12-31 10:40:45 -05:00
|
|
|
def handlebars
|
|
|
|
@handlebars ||= Set.new
|
|
|
|
end
|
2014-06-10 21:57:22 -04:00
|
|
|
|
|
|
|
def serialized_current_user_fields
|
|
|
|
@serialized_current_user_fields ||= Set.new
|
|
|
|
end
|
2013-11-19 10:42:28 -05:00
|
|
|
end
|
2013-08-01 01:59:57 -04:00
|
|
|
|
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
|
|
|
|
|
2013-11-19 10:42:28 -05:00
|
|
|
def javascripts
|
2013-02-08 02:56:12 -05:00
|
|
|
self.class.javascripts
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-11-19 10:42:28 -05:00
|
|
|
def server_side_javascripts
|
|
|
|
self.class.server_side_javascripts
|
|
|
|
end
|
|
|
|
|
|
|
|
def stylesheets
|
|
|
|
self.class.stylesheets
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-04-07 10:33:35 -04:00
|
|
|
def mobile_stylesheets
|
|
|
|
self.class.mobile_stylesheets
|
|
|
|
end
|
|
|
|
|
2014-04-25 04:26:37 -04:00
|
|
|
def desktop_stylesheets
|
|
|
|
self.class.desktop_stylesheets
|
|
|
|
end
|
|
|
|
|
|
|
|
def sass_variables
|
|
|
|
self.class.sass_variables
|
|
|
|
end
|
|
|
|
|
2013-12-31 10:40:45 -05:00
|
|
|
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
|
2013-11-19 10:42:28 -05:00
|
|
|
self.server_side_javascripts = nil
|
|
|
|
self.stylesheets = nil
|
2014-04-07 10:33:35 -04:00
|
|
|
self.mobile_stylesheets = nil
|
2014-04-25 04:26:37 -04:00
|
|
|
self.desktop_stylesheets = nil
|
|
|
|
self.sass_variables = nil
|
2013-12-31 10:40:45 -05:00
|
|
|
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
|