Module | Webgen::PluginDefs::ClassMethods |
In: |
lib/webgen/plugin.rb
|
All the methods of this module become class methods in the classes which include the PluginDefs module.
Called when PluginDefs is included in another class. Add this class to plugin data.
# File lib/webgen/plugin.rb, line 52 52: def self.extended( klass ) 53: callcc {|cont| throw :plugin_class_found, [cont, klass]} 54: klass.init_config 55: rescue NameError => e 56: raise "Plugin '#{klass}' managed by no PluginLoader" 57: end
Returns the ancestor classes for the object‘s class which are not base plugins.
# File lib/webgen/plugin.rb, line 112 112: def ancestor_classes 113: ancestors.delete_if {|c| c.instance_of?( Module ) || 114: (c.respond_to?( :config ) && c.config.infos[:is_base_plugin] == true) }[0..-2] 115: end
Returns the configuration structure for the plugin.
# File lib/webgen/plugin.rb, line 70 70: def config 71: @config 72: end
Add a dependency to the plugin, ie. the name of another plugin. Dependencies are instantiated before the plugin gets instantiated. So only add those plugins here that you need to reference/use in the initialize method! The parameters have to be Strings!
# File lib/webgen/plugin.rb, line 96 96: def depends_on( *dep ) 97: dep.each {|d| self.config.dependencies << d} 98: end
Sets general information about the plugin (summary text, description, …). The parameter has to be a Hash. The following fields are recognized:
:name : | The name of the plugin. Should be of the form Namespace/Namespace/name and should contain only alphanumeric characters. |
:summary : | Summary of what the plugin does |
:description : | Extended description of the functionality |
:author : | The author of the plugin |
:instantiate : | Boolean value defining whether an instance of this plugin should be created |
:is_base_plugin : | Boolean value defining whether the plugin class is available from a plugin loader/manager after loading |
# File lib/webgen/plugin.rb, line 89 89: def infos( param ) 90: self.config.infos.update( param ) 91: end
Add subclass to plugin data.
# File lib/webgen/plugin.rb, line 47 47: def inherited( klass ) 48: ClassMethods.extended( klass ) 49: end
Initializes the plugin configuration structure.
# File lib/webgen/plugin.rb, line 60 60: def init_config 61: @config = OpenStruct.new 62: @config.plugin_klass = self 63: @config.params = {} 64: @config.infos = {} 65: @config.infos[:name] = self.name.sub(/^(#<.*?>|Webgen::DEFAULT_WRAPPER_MODULE)::/,'').sub('::','/') 66: @config.dependencies = [] 67: end
Defines a parameter.The parameter can be changed in the configuration file later.
Arguments:
name: | the name of the parameter |
default: | the default value of the parameter |
description: | a small description of the parameter |
# File lib/webgen/plugin.rb, line 106 106: def param( name, default, description ) 107: data = OpenStruct.new( :name => name, :default => default, :description => description ) 108: self.config.params[name] = data 109: end