Class: Sidebar::ParamField

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
Defined in:
lib/sidebar.rb

Direct Known Subclasses

CheckBoxField, RadioField, SelectField, TextAreaField

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

#defaultObject

Returns the value of attribute default.



17
18
19
# File 'lib/sidebar.rb', line 17

def default
  @default
end

#keyObject

Returns the value of attribute key.



15
16
17
# File 'lib/sidebar.rb', line 15

def key
  @key
end

#optionsObject

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

#input_html(sidebar) ⇒ Object



34
35
36
# File 'lib/sidebar.rb', line 34

def input_html(sidebar)
  text_field_tag(input_name(sidebar), sidebar.config[key], { :class => 'span4'})
end

#input_name(sidebar) ⇒ Object



43
44
45
# File 'lib/sidebar.rb', line 43

def input_name(sidebar)
  "configure[#{sidebar.id}][#{key}]"
end

#labelObject



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(sidebar)
  ('label', label)
end

#line_html(sidebar) ⇒ Object



38
39
40
41
# File 'lib/sidebar.rb', line 38

def line_html(sidebar)
  html = label_html(sidebar)
  html << (:div,  input_html(sidebar), :class => 'input')
end