class Sidebar::ParamField

Attributes

default[RW]
key[RW]
options[RW]

Public Class Methods

build(key, default, options) click to toggle source
# 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) click to toggle source
# 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
new(key, default, options = { }) click to toggle source
# File lib/sidebar.rb, line 22
def initialize(key, default, options = { })
  @key, @default, @options = key.to_s, default, options
end

Public Instance Methods

canonicalize(value) click to toggle source
# File lib/sidebar.rb, line 47
def canonicalize(value)
  value
end
input_html(sidebar) click to toggle source
# 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) click to toggle source
# File lib/sidebar.rb, line 43
def input_name(sidebar)
  "configure[#{sidebar.id}][#{key}]"
end
label() click to toggle source
# File lib/sidebar.rb, line 26
def label
  options[:label] || key.humanize.gsub(/url/i, 'URL')
end
label_html(sidebar) click to toggle source
# File lib/sidebar.rb, line 30
def label_html(sidebar)
  content_tag('label', label)
end
line_html(sidebar) click to toggle source
# File lib/sidebar.rb, line 38
def line_html(sidebar)
  html = label_html(sidebar)
  html << content_tag(:div,  input_html(sidebar), :class => 'input')
end