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.
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.
304 305 306 307 308 |
# File 'lib/coderay/helpers/plugin.rb', line 304 def helper *helpers for helper in helpers self::PLUGIN_HOST.require_helper plugin_id, helper.to_s 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.
285 286 287 288 289 290 291 292 |
# File 'lib/coderay/helpers/plugin.rb', line 285 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.
311 312 313 |
# File 'lib/coderay/helpers/plugin.rb', line 311 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 |