Sha256: 6417ac8f6760c3b9692dfc1eb7697f0db08abbfe7b804aac2a5adbf19a271a80

Contents?: true

Size: 811 Bytes

Versions: 4

Compression:

Stored size: 811 Bytes

Contents

module 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

4 entries across 4 versions & 1 rubygems

Version Path
cells-3.5.2 lib/cell/active_helper.rb
cells-3.5.1 lib/cell/active_helper.rb
cells-3.5.0 lib/cell/active_helper.rb
cells-3.5.0.beta2 lib/cell/active_helper.rb