Class: DiscoursePlugin
- Inherits:
-
Object
- Object
- DiscoursePlugin
- Defined in:
- lib/discourse_plugin/discourse_plugin.rb,
lib/discourse_plugin/version.rb
Overview
A basic plugin for Discourse. Meant to be extended and filled in. Most work is delegated to a registry.
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
-
.include_mixins ⇒ Object
Loads and mixes in the plugin’s mixins into the host app’s classes.
-
.mixins ⇒ Object
Find the modules defined in the plugin with “Mixin” in their name.
Instance Method Summary collapse
-
#initialize(registry) ⇒ DiscoursePlugin
constructor
A new instance of DiscoursePlugin.
- #listen_for(event_name) ⇒ Object
- #register_archetype(name, options = {}) ⇒ Object
- #register_css(file) ⇒ Object
- #register_js(file, opts = {}) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(registry) ⇒ DiscoursePlugin
Returns a new instance of DiscoursePlugin.
8 9 10 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 8 def initialize(registry) @registry = registry end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 6 def registry @registry end |
Class Method Details
.include_mixins ⇒ Object
Loads and mixes in the plugin’s mixins into the host app’s classes. A mixin named “UserMixin” will be included into the “User” class.
18 19 20 21 22 23 24 25 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 18 def self.include_mixins mixins.each do |mixin| original_class = mixin.to_s.demodulize.sub("Mixin", "") dependency_file_name = original_class.underscore require_dependency(dependency_file_name) original_class.constantize.send(:include, mixin) end end |
.mixins ⇒ Object
Find the modules defined in the plugin with “Mixin” in their name.
28 29 30 31 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 28 def self.mixins constants.map { |const_name| const_get(const_name) } .select { |const| const.class == Module && const.name["Mixin"] } end |
Instance Method Details
#listen_for(event_name) ⇒ Object
45 46 47 48 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 45 def listen_for(event_name) return unless self.respond_to?(event_name) DiscourseEvent.on(event_name, &self.method(event_name)) end |
#register_archetype(name, options = {}) ⇒ Object
41 42 43 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 41 def register_archetype(name, ={}) @registry.register_archetype(name, ) end |
#register_css(file) ⇒ Object
37 38 39 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 37 def register_css(file) @registry.register_css(file) end |
#register_js(file, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 33 def register_js(file, opts={}) @registry.register_js(file, opts) end |
#setup ⇒ Object
12 13 14 |
# File 'lib/discourse_plugin/discourse_plugin.rb', line 12 def setup # Initialize the plugin here end |