Class: Sidebar::ParamField::RadioField

Inherits:
Sidebar::ParamField show all
Defined in:
lib/sidebar.rb

Instance Attribute Summary

Attributes inherited from Sidebar::ParamField

#default, #key, #options

Instance Method Summary collapse

Methods inherited from Sidebar::ParamField

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

Constructor Details

This class inherits a constructor from Sidebar::ParamField

Instance Method Details

#input_html(sidebar) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/sidebar.rb', line 67

def input_html(sidebar)
  options[:choices].collect do |choice|
    value = value_for(choice)
    radio_button_tag(input_name(sidebar), value,
                     value == sidebar.config[key], options) +
      ('label', label_for(choice))
  end.join("<br />")
end

#label_for(choice) ⇒ Object



76
77
78
# File 'lib/sidebar.rb', line 76

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

#value_for(choice) ⇒ Object



80
81
82
# File 'lib/sidebar.rb', line 80

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