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



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

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)
    tag.div(tag.label(radio_button + label_for(choice)), class: "radio")
  end
  safe_join(choices)
end

#label_for(choice) ⇒ Object



73
74
75
# File 'lib/sidebar_field.rb', line 73

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

#value_for(choice) ⇒ Object



77
78
79
# File 'lib/sidebar_field.rb', line 77

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