Class | Object |
In: |
lib/webgen/gui/main.rb
lib/webgen/plugin.rb |
Parent: | Object |
# File lib/webgen/gui/main.rb, line 16 16: def self.set_logger( logger, set_it = false ) 17: @@logger = logger if set_it 18: end
Used to load optional parts. You have to specify a unique name for the optional part and options with some information about it. The following keys can be used:
:needed_gems : | an array of Rubygem‘s gem names that are required for the part |
:error_msg : | error message that should be displayed if the part can‘t be loaded |
:info : | information about what the part does |
# File lib/webgen/plugin.rb, line 171 171: def load_optional_part( name, options = {} ) 172: options[:loaded] = true 173: begin 174: yield 175: rescue LoadError => e 176: options[:loaded] = false 177: options[:error_msg] ||= e.message 178: end 179: callcc {|cont| throw :load_optional_part, [cont, name, options]} 180: end
This method should be used instead of require when loading a plugin file.
# File lib/webgen/plugin.rb, line 151 151: def load_plugin( file ) 152: file = file + '.rb' unless /\.rb$/ =~ file 153: wrapper, do_load = callcc {|cont| throw :load_plugin_file?, [cont, file]} 154: 155: realfile = file 156: if /^(\/|\w:)/ !~ realfile 157: $:.each do |path| 158: realfile = File.join( path, file ) 159: break if File.exists?( realfile ) 160: end 161: end 162: 163: wrapper.module_eval( File.read( realfile ), file, 1 ) if do_load 164: end