Class: AttributePairGenerator

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/attribute_pair_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_obj = nil) ⇒ AttributePairGenerator

Returns a new instance of AttributePairGenerator.



10
11
12
# File 'lib/attribute_pair_generator.rb', line 10

def initialize(init_obj = nil)
  @obj = init_obj
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



8
9
10
# File 'lib/attribute_pair_generator.rb', line 8

def obj
  @obj
end

#output_bufferObject

Returns the value of attribute output_buffer.



7
8
9
# File 'lib/attribute_pair_generator.rb', line 7

def output_buffer
  @output_buffer
end

Instance Method Details

#checkbox(options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/attribute_pair_generator.rb', line 36

def checkbox(options)
  hidden_tag = hidden_field_tag attribute(options), options[:unchecked_value].nil? ? false : options[:unchecked_value]
  checked_value = options[:checked_value] || true
  is_checked = value(options).to_s == checked_value.to_s
  content = hidden_tag + check_box_tag(attribute(options), checked_value, is_checked, field_options(options))
  render(content, options)
end

#date(options) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/attribute_pair_generator.rb', line 23

def date(options)
  text_field_options = field_options(options)
  ((text_field_options[:class] ||= '') << ' datepicker').strip!

  content = text_field_tag attribute(options), value(options), text_field_options
  render(content, options)
end


14
15
16
17
# File 'lib/attribute_pair_generator.rb', line 14

def link(options)
  content = link_to options[:title], options[:url], options[:field_options]
  render(content, options)
end

#plain_text(options) ⇒ Object



19
20
21
# File 'lib/attribute_pair_generator.rb', line 19

def plain_text(options)
  render(value(options), options)
end

#radio(options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/attribute_pair_generator.rb', line 54

def radio(options)
  content =  :ol, class: 'unstyled' do
    options[:collection].map do |element|
      if element.is_a?(Array)
        value = element[0]
        label = element[1]
      else
        value = label = element
      end
       :li do
        label_tag("#{attribute(options)}_#{value}", radio_button_tag(attribute(options), value || '', value == value(options), field_options(options)) + label, class: 'radio')
      end
    end.flatten.join("").html_safe
  end

  render(content, options)
end

#select(options) ⇒ Object



31
32
33
34
# File 'lib/attribute_pair_generator.rb', line 31

def select(options)
  content = select_tag attribute(options), options_for_select(options[:collection], value(options)), field_options(options, prompt: options[:prompt], include_blank: options[:include_blank])
  render(content, options)
end

#text_area(options) ⇒ Object



49
50
51
52
# File 'lib/attribute_pair_generator.rb', line 49

def text_area(options)
  content = text_area_tag attribute(options), value(options), field_options(options)
  render(content, options)
end

#text_field(options) ⇒ Object



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

def text_field(options)
  content = text_field_tag attribute(options), value(options), field_options(options)
  render(content, options)
end