lib/merb_helpers.rb in merb_helpers-0.4.0 vs lib/merb_helpers.rb in merb_helpers-0.5

- old
+ new

@@ -1,12 +1,35 @@ -# make sure we're running inside Merb -if defined?(Merb::Plugins) +module Merb + + module Helpers + HELPERS_DIR = File.dirname(__FILE__) / 'merb_helpers' + HELPERS_FILES = Dir["#{HELPERS_DIR}/*_helpers.rb"].collect {|h| h.match(/\/(\w+)\.rb/)[1]} + + def self.load_helpers(helpers = HELPERS_FILES) + helpers.each {|h| Kernel.load(File.join(HELPERS_DIR, "#{h}.rb") )} # using load here allows specs to work + end + + def self.load + if Merb::Plugins.config[:merb_helpers] + config = Merb::Plugins.config[:merb_helpers] + raise "With and Without options cannot be used with merb_helpers plugin configuration" if config[:with] && config[:without] + if config[:include] + load_helpers(config[:include]) + elsif config[:exclude] + load_helpers(HELPERS_FILES.reject {|h| config[:exclude].include? h}) + else + # This is in case someone defines an entry in the config, + # but doesn't put in a with or without option + load_helpers + end + else + load_helpers + end - # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it - Merb::Plugins.config[:merb_helpers] = { - :chickens => false - } + Merb::Plugins.add_rakefiles "tasks/merb_tasks" + end + + end - require 'form_model' - require 'form_helpers' - Merb::Plugins.add_rakefiles "merb_helpers/merbtasks" -end +end + +Merb::Helpers.load if defined?(Merb::Plugins) \ No newline at end of file