lib/merb_helpers.rb in merb_helpers-0.9.3 vs lib/merb_helpers.rb in merb_helpers-0.9.4

- old
+ new

@@ -1,42 +1,39 @@ 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 + @@helpers_dir = File.dirname(__FILE__) / 'merb_helpers' + @@helpers_files = Dir["#{@@helpers_dir}/*_helpers.rb"].collect {|h| h.match(/\/(\w+)\.rb/)[1]} + def self.load - require HELPERS_DIR + '/time_dsl' - require HELPERS_DIR + '/ordinalize' - # TODO remove with and without and only allow 2 options: - # config[:load] - # if defined then load the modules passed along - # otherwise load everything + require @@helpers_dir + '/time_dsl' + require @@helpers_dir + '/ordinalize' + require @@helpers_dir + '/core_ext' 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] + raise "With and Without options have been deprecated" if config[:with] || config[:without] + + if config[:include] && !config[:include].empty? 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 end + # Load only specific helpers instead of loading all the helpers + def self.load_helpers(helpers = @@helpers_files) + helpers.each {|helper| Kernel.load(File.join(@@helpers_dir, "#{helper}.rb") )} # using load here allows specs to work + end + end end -Merb::BootLoader.before_app_loads do - Merb::Helpers.load -end \ No newline at end of file +Merb::Helpers.load