Module: FlavourSaver::Helpers

Defined in:
lib/flavour_saver/helpers.rb

Defined Under Namespace

Classes: Decorator, Defaults

Class Method Summary collapse

Class Method Details

.decorate_with(context, helper_names = [], locals = {}) ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/flavour_saver/helpers.rb', line 123

def decorate_with(context, helper_names=[], locals={})
  helpers = if helper_names.any?
              helper_symbols = helper_names.map(&:to_sym)
              registered_helpers.select { |k,v| helper_symbols.member? k }
            else
              registered_helpers
            end
  helpers = helpers.merge(locals)
  Decorator.new(helpers, context)
end

.deregister_helper(*names) ⇒ Object



113
114
115
116
117
# File 'lib/flavour_saver/helpers.rb', line 113

def deregister_helper(*names)
  names.each do |name|
    registered_helpers.delete(name.to_sym)
  end
end

.register_helper(method, &b) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/flavour_saver/helpers.rb', line 105

def register_helper(method,&b)
  if !method.is_a?(Symbol) && method.respond_to?(:name)
    registered_helpers[method.name.to_sym] = method
  elsif b
    registered_helpers[method.to_sym] = b
  end
end

.registered_helpersObject



101
102
103
# File 'lib/flavour_saver/helpers.rb', line 101

def registered_helpers
  @registered_helpers ||= {}
end

.reset_helpersObject



119
120
121
# File 'lib/flavour_saver/helpers.rb', line 119

def reset_helpers
  @registered_helpers = {}
end