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

Instance Method Summary collapse

Instance Attribute Details

#plugin_idObject (readonly)

Returns the value of attribute plugin_id.



240
241
242
# File 'lib/coderay/helpers/plugin.rb', line 240

def plugin_id
  @plugin_id
end

Instance Method Details

#aliasesObject



274
275
276
277
278
279
280
# File 'lib/coderay/helpers/plugin.rb', line 274

def aliases
  plugin_host.load_plugin_map
  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.



267
268
269
270
271
272
# File 'lib/coderay/helpers/plugin.rb', line 267

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.



251
252
253
254
# File 'lib/coderay/helpers/plugin.rb', line 251

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.



258
259
260
261
262
263
264
# File 'lib/coderay/helpers/plugin.rb', line 258

def title title = nil
  if title
    @title = title.to_s
  else
    @title ||= name[/([^:]+)$/, 1]
  end
end