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.
Example: see PluginHost.
Instance Method Summary collapse
-
#helper(*helpers) ⇒ Object
Require some helper files.
- #included(mod) ⇒ Object
-
#plugin_host(host = nil) ⇒ Object
The host for this Plugin class.
-
#plugin_id ⇒ Object
Returns the pulgin id used by the engine.
-
#register_for(*ids) ⇒ Object
Register this class for the given langs.
-
#title(title = nil) ⇒ Object
Returns the title of the plugin, or sets it to the optional argument
title
.
Instance Method Details
#helper(*helpers) ⇒ Object
Require some helper files.
Example:
class MyPlugin < PluginHost::BaseClass
register_for :my_id
helper :my_helper
The above example loads the file myplugin/my_helper.rb relative to the file in which MyPlugin was defined.
You can also load a helper from a different plugin:
helper 'other_plugin/helper_name'
318 319 320 321 322 323 324 325 326 |
# File 'lib/coderay/helpers/plugin.rb', line 318 def helper *helpers for helper in helpers if helper.is_a?(String) && helper[/\//] self::PLUGIN_HOST.require_helper $`, $' else self::PLUGIN_HOST.require_helper plugin_id, helper.to_s end end end |
#included(mod) ⇒ Object
268 269 270 |
# File 'lib/coderay/helpers/plugin.rb', line 268 def included mod warn "#{name} should not be included. Use extend." end |
#plugin_host(host = nil) ⇒ Object
The host for this Plugin class.
295 296 297 298 299 300 301 302 |
# File 'lib/coderay/helpers/plugin.rb', line 295 def plugin_host host = nil if host and not host.is_a? PluginHost raise ArgumentError, "PluginHost expected, but #{host.class} given." end self.const_set :PLUGIN_HOST, host if host self::PLUGIN_HOST end |
#plugin_id ⇒ Object
Returns the pulgin id used by the engine.
329 330 331 |
# File 'lib/coderay/helpers/plugin.rb', line 329 def plugin_id name[/\w+$/].downcase end |
#register_for(*ids) ⇒ Object
Register this class for the given langs. Example:
class MyPlugin < PluginHost::BaseClass
register_for :my_id
...
end
See PluginHost.register.
280 281 282 |
# File 'lib/coderay/helpers/plugin.rb', line 280 def register_for *ids plugin_host.register self, *ids end |
#title(title = nil) ⇒ Object
Returns the title of the plugin, or sets it to the optional argument title
.
286 287 288 289 290 291 292 |
# File 'lib/coderay/helpers/plugin.rb', line 286 def title title = nil if title @title = title.to_s else @title ||= name[/([^:]+)$/, 1] end end |