class Textigniter::Plugins
Public Instance Methods
camelcase(phrase)
click to toggle source
# File lib/textigniter/plugins.rb, line 61 def camelcase(phrase) phrase.gsub!(/_/, ' ') phrase.gsub!(/\b\w/){$&.upcase} phrase.gsub!(/ /, '') return phrase end
load_plugins(plugins)
click to toggle source
load the plugins and return a super object
# File lib/textigniter/plugins.rb, line 45 def load_plugins(plugins) # create a hash to store plugins in splugin = Hash.new # iterate through list plugins.each do |plugin| # buld the class name classname = camelcase(File.basename(plugin, '.rb')) # load the class loaded_class = eval("Textigniter::Plugins::#{classname}").new # add it to splugin splugin["#{File.basename(plugin, '.rb')}"] = loaded_class end # return the super plugin return splugin end
parse(h)
click to toggle source
parse through the hash
# File lib/textigniter/plugins.rb, line 4 def parse(h) # create a hash to store processed items @h = Hash.new # require plugins require_plugins(plugins) # load plugins splugin = load_plugins(plugins) # iterate through the hash h.each do |key, value| # check for plugin methods if splugin.has_key?(key) # pass the entire hash to parser # may have to rethink this if speed problems arise @h["#{key}"] = splugin["#{key}"].parse(h) else @h["#{key}"] = value end end # return the hash return @h end
plugins()
click to toggle source
gather a list of textigniter and custom plugins
# File lib/textigniter/plugins.rb, line 27 def plugins # textigniter plugins textigniter_plugins = Dir.glob("#{$gem_path}/textigniter/plugins/**/*.rb") # custom plugins custom_plugins = Dir.glob("#{$twd}/plugins/**/*.rb") # join plugins @plugins = textigniter_plugins | custom_plugins end
require_plugins(plugins)
click to toggle source
require the plugins for use
# File lib/textigniter/plugins.rb, line 37 def require_plugins(plugins) plugins.each do |plugin| # require the plugin require_relative plugin end end