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.
9
10
11
12
13
|
# File 'lib/sidebar_field.rb', line 9
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.
2
3
4
|
# File 'lib/sidebar_field.rb', line 2
def key
@key
end
|
#options ⇒ Object
Returns the value of attribute options.
3
4
5
|
# File 'lib/sidebar_field.rb', line 3
def options
@options
end
|
Class Method Details
.build(key, default, options) ⇒ Object
98
99
100
|
# File 'lib/sidebar_field.rb', line 98
def self.build(key, default, options)
class_for(options).new(key, default, options)
end
|
.class_for(options) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/sidebar_field.rb', line 102
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
35
36
37
|
# File 'lib/sidebar_field.rb', line 35
def canonicalize(value)
value
end
|
#current_value(sidebar) ⇒ Object
39
40
41
|
# File 'lib/sidebar_field.rb', line 39
def current_value()
canonicalize(.config[key])
end
|
23
24
25
|
# File 'lib/sidebar_field.rb', line 23
def input_html()
text_field_tag(input_name(), current_value(), class: 'form-control')
end
|
31
32
33
|
# File 'lib/sidebar_field.rb', line 31
def input_name()
"configure[#{.id}][#{key}]"
end
|
#label ⇒ Object
15
16
17
|
# File 'lib/sidebar_field.rb', line 15
def label
options[:label] || key.humanize.gsub(/url/i, 'URL')
end
|
#label_html(_sidebar) ⇒ Object
19
20
21
|
# File 'lib/sidebar_field.rb', line 19
def label_html()
content_tag('label', label)
end
|
#line_html(sidebar) ⇒ Object
27
28
29
|
# File 'lib/sidebar_field.rb', line 27
def line_html()
content_tag(:div, label_html() + input_html(), class: 'form-group')
end
|