Class: SidebarField
- Inherits:
-
Object
show all
- Includes:
- ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
- Defined in:
- lib/sidebar_field.rb
Defined Under Namespace
Classes: CheckBoxField, RadioField, SelectField, TextAreaField
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(key, default, options = {}) ⇒ SidebarField
Returns a new instance of SidebarField.
10
11
12
13
14
|
# File 'lib/sidebar_field.rb', line 10
def initialize(key, default, options = {})
@key = key.to_s
@default = default
@options = options
end
|
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
4
5
6
|
# File 'lib/sidebar_field.rb', line 4
def default
@default
end
|
#key ⇒ Object
Returns the value of attribute key.
4
5
6
|
# File 'lib/sidebar_field.rb', line 4
def key
@key
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/sidebar_field.rb', line 4
def options
@options
end
|
Class Method Details
.build(key, default, options) ⇒ Object
100
101
102
|
# File 'lib/sidebar_field.rb', line 100
def self.build(key, default, options)
class_for(options).new(key, default, options)
end
|
.class_for(options) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# 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
|
Instance Method Details
#canonicalize(value) ⇒ Object
36
37
38
|
# File 'lib/sidebar_field.rb', line 36
def canonicalize(value)
value
end
|
#current_value(sidebar) ⇒ Object
40
41
42
|
# File 'lib/sidebar_field.rb', line 40
def current_value()
canonicalize(.config[key])
end
|
24
25
26
|
# File 'lib/sidebar_field.rb', line 24
def input_html()
text_field_tag(input_name(), current_value(), class: "form-control")
end
|
32
33
34
|
# File 'lib/sidebar_field.rb', line 32
def input_name()
"configure[#{.id}][#{key}]"
end
|
#label ⇒ Object
16
17
18
|
# File 'lib/sidebar_field.rb', line 16
def label
options[:label] || key.humanize.gsub(/url/i, "URL")
end
|
#label_html(_sidebar) ⇒ Object
20
21
22
|
# File 'lib/sidebar_field.rb', line 20
def label_html()
tag.label(label)
end
|
#line_html(sidebar) ⇒ Object
28
29
30
|
# File 'lib/sidebar_field.rb', line 28
def line_html()
tag.div(label_html() + input_html(), class: "form-group")
end
|