Class: Sidebar::ParamField
- Inherits:
-
Object
- Object
- Sidebar::ParamField
show all
- Includes:
- ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
- Defined in:
- lib/sidebar.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 = { }) ⇒ ParamField
Returns a new instance of ParamField.
22
23
24
|
# File 'lib/sidebar.rb', line 22
def initialize(key, default, options = { })
@key, @default, @options = key.to_s, default, options
end
|
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
17
18
19
|
# File 'lib/sidebar.rb', line 17
def default
@default
end
|
#key ⇒ Object
Returns the value of attribute key.
15
16
17
|
# File 'lib/sidebar.rb', line 15
def key
@key
end
|
#options ⇒ Object
Returns the value of attribute options.
16
17
18
|
# File 'lib/sidebar.rb', line 16
def options
@options
end
|
Class Method Details
.build(key, default, options) ⇒ Object
105
106
107
|
# File 'lib/sidebar.rb', line 105
def self.build(key, default, options)
param_field = class_for(options).new(key, default, options)
end
|
.class_for(options) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/sidebar.rb', line 109
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
47
48
49
|
# File 'lib/sidebar.rb', line 47
def canonicalize(value)
value
end
|
34
35
36
|
# File 'lib/sidebar.rb', line 34
def input_html()
text_field_tag(input_name(), .config[key], { :class => 'span4'})
end
|
43
44
45
|
# File 'lib/sidebar.rb', line 43
def input_name()
"configure[#{.id}][#{key}]"
end
|
#label ⇒ Object
26
27
28
|
# File 'lib/sidebar.rb', line 26
def label
options[:label] || key.humanize.gsub(/url/i, 'URL')
end
|
#label_html(sidebar) ⇒ Object
30
31
32
|
# File 'lib/sidebar.rb', line 30
def label_html()
content_tag('label', label)
end
|
#line_html(sidebar) ⇒ Object
38
39
40
41
|
# File 'lib/sidebar.rb', line 38
def line_html()
html = label_html()
html << content_tag(:div, input_html(), :class => 'input')
end
|