Class: Textigniter::Plugins
- Inherits:
-
Object
- Object
- Textigniter::Plugins
- Defined in:
- lib/textigniter/plugins.rb
Defined Under Namespace
Classes: Breadcrumbs, CreatedAt, Slug
Instance Method Summary collapse
- #camelcase(phrase) ⇒ Object
-
#load_plugins(plugins) ⇒ Object
load the plugins and return a super object.
-
#parse(h) ⇒ Object
parse through the hash.
-
#plugins ⇒ Object
gather a list of textigniter and custom plugins.
-
#require_plugins(plugins) ⇒ Object
require the plugins for use.
Instance Method Details
#camelcase(phrase) ⇒ Object
61 62 63 64 65 66 |
# 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) ⇒ Object
load the plugins and return a super object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
parse through the hash
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
gather a list of textigniter and custom plugins
27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
require the plugins for use
37 38 39 40 41 42 |
# File 'lib/textigniter/plugins.rb', line 37 def require_plugins(plugins) plugins.each do |plugin| # require the plugin require_relative plugin end end |