Sha256: 7687736ae138a789b0c81d2ef66939c4e7a66b5b18595070c787c9969811905a

Contents?: true

Size: 836 Bytes

Versions: 8

Compression:

Stored size: 836 Bytes

Contents

module Cells::Cell::ActiveHelper
  
  def self.included(base)
    base.extend ClassMethods
    
    base.class_inheritable_array :active_helpers
    base.active_helpers = []
  end
  
  module ClassMethods    
    # The passed helpers will be imported in the view and thus be available in
    # your template.
    #
    # Example:
    #   class BassistCell < Cell::Base
    #     active_helper SlappingHelper
    #
    # The helper file usually resides in +app/active_helpers/+, baby.
    def active_helper(*classes)
      active_helpers.push(*classes).uniq!
    end
  end
  
  def import_active_helpers_into(view)
    return if self.class.active_helpers.blank?
    
    # We simply assume if somebody's using #active_helper, it is already
    # required.
    view.extend ::ActiveHelper
    view.use *self.class.active_helpers
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cells-3.3.10 lib/cells/cell/active_helper.rb
cells-3.3.9 lib/cells/cell/active_helper.rb
cells-3.3.8 lib/cells/cell/active_helper.rb
cells-3.3.7 lib/cells/cell/active_helper.rb
cells-3.3.6 lib/cells/cell/active_helper.rb
cells-3.3.5 lib/cells/cell/active_helper.rb
cells-3.3.4 lib/cells/cell/active_helper.rb
cells-3.3.3 lib/cells/cell/active_helper.rb