Module: Presenting::Helpers

Defined in:
lib/presenting/helpers.rb

Instance Method Summary collapse

Instance Method Details

#present(*args, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/presenting/helpers.rb', line 3

def present(*args, &block)
  options = args.length > 1 ? args.extract_options! : {}

  if args.first.is_a? Symbol
    object, presentation = nil, args.first
  else
    object, presentation = args.first, args.second
  end

  if presentation
    klass = "Presentation::#{presentation.to_s.camelcase}".constantize rescue nil
    if klass
      instance = klass.new(options, &block)
      instance.presentable = object
      instance.controller = controller
      instance.render
    elsif respond_to?(method_name = "present_#{presentation}", true)
      send(method_name, object, options)
    else
      raise ArgumentError, "unknown presentation `#{presentation}'"
    end
  elsif object.respond_to?(:loaded?) # AssociationProxy
    present_association(object, options)
  else
    present_by_class(object, options)
  end
end

#present_checkbox_search(field, options = {}) ⇒ Object

presents a checkbox search widget for the given field (a Presentation::FieldSearch::Field, probably)



38
39
40
41
# File 'lib/presenting/helpers.rb', line 38

def present_checkbox_search(field, options = {})
  current_value = (params[:search][field.param][:value] rescue nil)
  check_box_tag options[:name], '1', current_value.to_s == '1'
end

#present_dropdown_search(field, options = {}) ⇒ Object

presents a dropdown/select search widget for the given field (a Presentation::FieldSearch::Field, probably)



44
45
46
47
# File 'lib/presenting/helpers.rb', line 44

def present_dropdown_search(field, options = {})
  current_value = (params[:search][field.param][:value] rescue nil)
  select_tag options[:name], options_for_select(normalize_dropdown_options_to_strings(field.options), current_value)
end

#present_text_search(field, options = {}) ⇒ Object

presents a text search widget for the given field (a Presentation::FieldSearch::Field, probably)



32
33
34
35
# File 'lib/presenting/helpers.rb', line 32

def present_text_search(field, options = {})
  current_value = (params[:search][field.param][:value] rescue nil)
  text_field_tag options[:name], h(current_value)
end