Class Webgen::PluginLoader
In: lib/webgen/plugin.rb
Parent: Object
RuntimeError PluginParamNotFound PluginNotFound ConfigurationFileInvalid CmdParse::CommandParser CommandParser DirectoryInfo GalleryStyle WebSiteStyle WebSiteTemplate SipttraStyle Test::Unit::TestCase TestCase PluginTestCase TagTestCase CmdParse::Command ShowCommand CheckCommand UseCommand CreateCommand TSort DependencyHash Hash Comparable Language ::Logger Logger Logger DEFAULT_WRAPPER_MODULE WebSite Qt::MainWindow MainWindow Qt::Dialog NewWebsiteDialog Qt::TextEdit LogWidget ::Rake::TaskLib WebgenTask ConfigurationFile Website PluginManager PluginLoader PluginParamValueNotFound Dummy Color CliUtils PluginDefs lib/webgen/languages.rb lib/webgen/website.rb lib/webgen/gui/common.rb lib/webgen/plugin.rb lib/webgen/test.rb lib/webgen/cli.rb ClassMethods PluginDefs LanguageManager lib/webgen/gui/new_website_dlg.rb lib/webgen/gui/main.rb GUI lib/webgen/rake/webgentask.rb Rake Webgen dot/m_60_1.png

Responsible for loading plugins classes. Each PluginLoader has an array of plugin classes which it loaded. Several methods for loading plugins classes are available.

Methods

Attributes

loaded_files  [R]  The files loaded by this PluginLoader instance.
optional_parts  [R]  The optional parts managed (loaded or not) by this PluginLoader instance.
plugin_classes  [R]  The plugin classes loaded by this PluginLoader instance.

Public Class methods

Creates a new PluginLoader instance. The wrapper_module is used when loading the plugins so that they do not pollute the global namespace.

[Source]

     # File lib/webgen/plugin.rb, line 200
200:     def initialize( wrapper_module = Module.new )
201:       @plugin_classes = []
202:       @loaded_files = []
203:       @wrapper_module = wrapper_module
204:       @optional_parts = {}
205:     end

Public Instance methods

Checks if this PluginLoader has loaded a plugin called name.

[Source]

     # File lib/webgen/plugin.rb, line 250
250:     def has_plugin?( name )
251:       plugin_class_for_name( name ) != nil
252:     end

Loads all plugin classes which get declared in the given block. Be aware that this method does not put the classes into the wrapper module!

[Source]

     # File lib/webgen/plugin.rb, line 235
235:     def load_from_block( &block )
236:       cont, klass = catch( :plugin_class_found ) do
237:         cont, name, options = catch( :load_optional_part ) { yield }
238:         if cont
239:           @optional_parts[name] = options
240:           cont.call
241:         end
242:         nil # return value for catch, means: all classes processed
243:       end
244:       add_plugin_class( klass ) unless klass.nil?
245:       cont.call if cont
246:       sort_out_base_plugins
247:     end

Loads all plugin classes in the given dir and in its subdirectories. Before require is actually called the path is trimmed: if trimpath matches the beginning of the string, trimpath is deleted from it. The loaded classes are wrapped in the wrapper module and won‘t pollute the namespace.

[Source]

     # File lib/webgen/plugin.rb, line 211
211:     def load_from_dir( dir, trimpath = '')
212:       Find.find( dir ) do |file|
213:         trimmedFile = file.gsub(/^#{trimpath}/, '')
214:         Find.prune unless File.directory?( file ) || (/\.rb$/ =~ file)
215:         load_from_file( trimmedFile ) if File.file?( file ) && /\.rb$/ =~ file
216:       end
217:     end

Loads all plugin classes specified in the file.The loaded classes are wrapped in the wrapper module and won‘t pollute the namespace.

[Source]

     # File lib/webgen/plugin.rb, line 221
221:     def load_from_file( file )
222:       load_from_block do
223:         cont, file = catch( :load_plugin_file? ) do
224:           load_plugin( file )
225:           nil
226:         end
227:         do_load_file = !@loaded_files.include?( file ) && !DEFAULT_PLUGIN_LOADER.loaded_files.include?( file ) unless file.nil?
228:         @loaded_files << file unless file.nil? || @loaded_files.include?( file )
229:         cont.call( @wrapper_module, do_load_file ) if cont
230:       end
231:     end

Returns the plugin class called name or nil if it is not found.

[Source]

     # File lib/webgen/plugin.rb, line 255
255:     def plugin_class_for_name( name )
256:       @plugin_classes.find {|p| p.plugin_name == name}
257:     end

Private Instance methods

[Source]

     # File lib/webgen/plugin.rb, line 263
263:     def add_plugin_class( klass )
264:       @plugin_classes << klass
265:     end

[Source]

     # File lib/webgen/plugin.rb, line 267
267:     def sort_out_base_plugins
268:       @plugin_classes.delete_if {|klass| klass.config.infos[:is_base_plugin] == true}
269:     end

[Validate]