Class: SidebarField::RadioField

Inherits:
SidebarField show all
Defined in:
lib/sidebar_field.rb

Instance Attribute Summary

Attributes inherited from SidebarField

#default, #key, #options

Instance Method Summary collapse

Methods inherited from SidebarField

build, #canonicalize, class_for, #current_value, #initialize, #input_name, #label, #label_html, #line_html

Constructor Details

This class inherits a constructor from SidebarField

Instance Method Details

#input_html(sidebar) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sidebar_field.rb', line 62

def input_html(sidebar)
  choices = options[:choices].map do |choice|
    value = value_for(choice)
    radio_button = radio_button_tag(input_name(sidebar),
                                    value,
                                    value == current_value(sidebar),
                                    options)
    ("div", ("label", radio_button + label_for(choice)),
                class: "radio")
  end
  safe_join(choices)
end

#label_for(choice) ⇒ Object



75
76
77
# File 'lib/sidebar_field.rb', line 75

def label_for(choice)
  choice.is_a?(Array) ? choice.last : choice.to_s.humanize
end

#value_for(choice) ⇒ Object



79
80
81
# File 'lib/sidebar_field.rb', line 79

def value_for(choice)
  choice.is_a?(Array) ? choice.first : choice
end