class SidebarField
Attributes
default[RW]
key[RW]
options[RW]
Public Class Methods
build(key, default, options)
click to toggle source
# File lib/sidebar_field.rb, line 100 def self.build(key, default, options) class_for(options).new(key, default, options) end
class_for(options)
click to toggle source
# File lib/sidebar_field.rb, line 104 def self.class_for(options) case options[:input_type] when :text_area TextAreaField when :textarea TextAreaField when :radio RadioField when :checkbox CheckBoxField when :select SelectField else if options[:choices] SelectField else self end end end
new(key, default, options = {})
click to toggle source
# File lib/sidebar_field.rb, line 10 def initialize(key, default, options = {}) @key = key.to_s @default = default @options = options end
Public Instance Methods
canonicalize(value)
click to toggle source
# File lib/sidebar_field.rb, line 36 def canonicalize(value) value end
current_value(sidebar)
click to toggle source
# File lib/sidebar_field.rb, line 40 def current_value(sidebar) canonicalize(sidebar.config[key]) end
input_html(sidebar)
click to toggle source
# File lib/sidebar_field.rb, line 24 def input_html(sidebar) text_field_tag(input_name(sidebar), current_value(sidebar), class: "form-control") end
input_name(sidebar)
click to toggle source
# File lib/sidebar_field.rb, line 32 def input_name(sidebar) "configure[#{sidebar.id}][#{key}]" end
label()
click to toggle source
# File lib/sidebar_field.rb, line 16 def label options[:label] || key.humanize.gsub(/url/i, "URL") end
label_html(_sidebar)
click to toggle source
# File lib/sidebar_field.rb, line 20 def label_html(_sidebar) tag.label(label) end
line_html(sidebar)
click to toggle source
# File lib/sidebar_field.rb, line 28 def line_html(sidebar) tag.div(label_html(sidebar) + input_html(sidebar), class: "form-group") end