Module: CodeRay::Plugin

Included in:
Encoders::Encoder, Scanners::Scanner, Styles::Style
Defined in:
vendor/plugins/coderay-0.9.2/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

Instance Method Details

- (Object) helper(*helpers)

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 'vendor/plugins/coderay-0.9.2/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

- (Object) included(mod)



268
269
270
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/plugin.rb', line 268

def included mod
  warn "#{name} should not be included. Use extend."
end

- (Object) plugin_host(host = nil)

The host for this Plugin class.



295
296
297
298
299
300
301
302
# File 'vendor/plugins/coderay-0.9.2/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

- (Object) plugin_id

Returns the pulgin id used by the engine.



329
330
331
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/plugin.rb', line 329

def plugin_id
  name[/\w+$/].downcase
end

- (Object) register_for(*ids)

Register this class for the given langs. Example:

  class MyPlugin < PluginHost::BaseClass
    register_for :my_id
    ...
  end

See PluginHost.register.



280
281
282
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/plugin.rb', line 280

def register_for *ids
  plugin_host.register self, *ids
end

- (Object) title(title = nil)

Returns the title of the plugin, or sets it to the optional argument title.



286
287
288
289
290
291
292
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/helpers/plugin.rb', line 286

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