| Module | CodeRay::Plugin |
| In: |
lib/coderay/helpers/plugin.rb
|
Plugins have to include this module. IMPORTANT: use extend for this module. Example: see PluginHost.
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'
# File lib/coderay/helpers/plugin.rb, line 318
318: def helper *helpers
319: for helper in helpers
320: if helper.is_a?(String) && helper[/\//]
321: self::PLUGIN_HOST.require_helper $`, $'
322: else
323: self::PLUGIN_HOST.require_helper plugin_id, helper.to_s
324: end
325: end
326: end
# File lib/coderay/helpers/plugin.rb, line 268
268: def included mod
269: warn "#{name} should not be included. Use extend."
270: end
The host for this Plugin class.
# File lib/coderay/helpers/plugin.rb, line 295
295: def plugin_host host = nil
296: if host and not host.is_a? PluginHost
297: raise ArgumentError,
298: "PluginHost expected, but #{host.class} given."
299: end
300: self.const_set :PLUGIN_HOST, host if host
301: self::PLUGIN_HOST
302: end
Returns the pulgin id used by the engine.
# File lib/coderay/helpers/plugin.rb, line 329
329: def plugin_id
330: name[/\w+$/].downcase
331: end
Register this class for the given langs. Example:
class MyPlugin < PluginHost::BaseClass
register_for :my_id
...
end
See PluginHost.register.
# File lib/coderay/helpers/plugin.rb, line 280
280: def register_for *ids
281: plugin_host.register self, *ids
282: end