Module: CodeRay::Plugin
- Included in:
- Encoders::Encoder, Scanners::Scanner, Styles::Style
- Defined in:
- lib/coderay/helpers/plugin.rb
Overview
Plugin
Plugins have to include this module.
IMPORTANT: Use extend for this module.
See CodeRay::PluginHost for examples.
Instance Attribute Summary collapse
-
#plugin_id ⇒ Object
readonly
Returns the value of attribute plugin_id.
Instance Method Summary collapse
- #aliases ⇒ Object
-
#plugin_host(host = nil) ⇒ Object
The PluginHost for this Plugin class.
-
#register_for(id) ⇒ Object
Register this class for the given
id
. -
#title(title = nil) ⇒ Object
Returns the title of the plugin, or sets it to the optional argument
title
.
Instance Attribute Details
#plugin_id ⇒ Object (readonly)
Returns the value of attribute plugin_id.
231 232 233 |
# File 'lib/coderay/helpers/plugin.rb', line 231 def plugin_id @plugin_id end |
Instance Method Details
#aliases ⇒ Object
265 266 267 268 269 270 |
# File 'lib/coderay/helpers/plugin.rb', line 265 def aliases plugin_host.plugin_hash.inject [] do |aliases, (key, _)| aliases << key if plugin_host[key] == self aliases end end |
#plugin_host(host = nil) ⇒ Object
The PluginHost for this Plugin class.
258 259 260 261 262 263 |
# File 'lib/coderay/helpers/plugin.rb', line 258 def plugin_host host = nil if host.is_a? PluginHost const_set :PLUGIN_HOST, host end self::PLUGIN_HOST end |
#register_for(id) ⇒ Object
Register this class for the given id
.
Example:
class MyPlugin < PluginHost::BaseClass
register_for :my_id
...
end
See PluginHost.register.
242 243 244 245 |
# File 'lib/coderay/helpers/plugin.rb', line 242 def register_for id @plugin_id = id plugin_host.register self, id end |
#title(title = nil) ⇒ Object
Returns the title of the plugin, or sets it to the optional argument title
.
249 250 251 252 253 254 255 |
# File 'lib/coderay/helpers/plugin.rb', line 249 def title title = nil if title @title = title.to_s else @title ||= name[/([^:]+)$/, 1] end end |