Changeset 1037

Show
Ignore:
Timestamp:
11/23/07 02:32:45 (1 year ago)
Author:
luke.sutt..@gmail.com
Message:

merb_helpers: Add configuration to the plugin. Users can now specify which set of helpers they wish to load using the plugins.yml config file. Also tidy up the location of files to be consistent with other gems and add a tasks dir for rake tasks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/merb_helpers/README

    r710 r1037  
    22================= 
    33 
    4 A plugin for the Merb framework that provides .... 
     4A plugin for the Merb Web framework that provides different view helpers. 
     5 
     6To use this plugin in merb in your app 
     7 
     8config/dependencies.rb 
     9 
     10#... 
     11 
     12dependency "merb_helpers" 
     13 
     14#... 
     15 
     16By default all modules of merb_helpers are loaded and are available to your merb app. 
     17 
     18You can selectively include/exclude modules from this list to keep you app lean if you like.  
     19The inclusions/exclusions are relative to all modules.   
     20 
     21:include: will only include the specified modules. 
     22 
     23:exclude: will include all except the specified modules. 
     24 
     25Do not use :include: and :exclude: options at the same time or an error will be raised. 
     26 
     27To set this up in config/plugins.yml 
     28 
     29To Include specified helpers 
     30 
     31:merb_helpers: 
     32  :include: - date_time_helpers 
     33            - form_helpers 
     34 
     35 
     36To Exclude specified helpers 
     37 
     38:merb_helpers: 
     39  :exclude: - date_time_helpers 
     40            - form_helpers 
  • plugins/merb_helpers/lib/merb_helpers.rb

    r710 r1037  
    1 # make sure we're running inside Merb 
    2 if defined?(Merb::Plugins) 
     1module Merb 
     2   
     3  module Helpers 
     4    HELPERS_DIR   = File.join(File.dirname(__FILE__), 'merb_helpers') 
     5    HELPERS_FILES = Dir["#{HELPERS_DIR}/*_helpers.rb"].collect {|h| h.match(/\/(\w+)\.rb/)[1]} 
     6       
     7    def self.load_helpers(helpers = HELPERS_FILES) 
     8      helpers.each {|h| Kernel.load(File.join(HELPERS_DIR, "#{h}.rb") )} # using load here allows specs to work 
     9    end 
     10     
     11    def self.load 
     12      if Merb::Plugins.config[:merb_helpers] 
     13        config = Merb::Plugins.config[:merb_helpers] 
     14        raise "With and Without options cannot be used with merb_helpers plugin configuration" if config[:with] && config[:without] 
     15        if config[:include] 
     16          load_helpers(config[:include]) 
     17        elsif config[:exclude] 
     18          load_helpers(HELPERS_FILES.reject {|h| config[:exclude].include? h}) 
     19        else 
     20          # This is in case someone defines an entry in the config, 
     21          # but doesn't put in a with or without option 
     22          load_helpers 
     23        end 
     24      else 
     25        load_helpers 
     26      end 
    327 
    4   # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it 
    5   Merb::Plugins.config[:merb_helpers] = { 
    6     :chickens => false 
    7   } 
     28      Merb::Plugins.add_rakefiles "tasks/merb_tasks" 
     29    end 
     30     
     31  end 
    832   
    9   require 'form_model' 
    10   require 'form_helpers' 
    11   Merb::Plugins.add_rakefiles "merb_helpers/merbtasks" 
    1233end 
     34 
     35Merb::Helpers.load if defined?(Merb::Plugins)