Parent

Included Modules

Merb::Helpers::Form::Builder::Base

Public Class Methods

new(obj, name, origin) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 10
def initialize(obj, name, origin)
  @obj, @origin = obj, origin
  @name = name || @obj.class.name.snake_case.split("/").last
end

Public Instance Methods

bound_check_box(method, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 45
def bound_check_box(method, attrs = {})
  name = control_name(method)
  update_bound_controls(method, attrs, "checkbox")
  unbound_check_box({:name => name}.merge(attrs))
end
bound_radio_button(method, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 62
def bound_radio_button(method, attrs = {})
  name = control_name(method)
  update_bound_controls(method, attrs, "radio")
  unbound_radio_button({:name => name, :value => control_value(method)}.merge(attrs))
end
bound_radio_group(method, arr) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 73
def bound_radio_group(method, arr)
  val = control_value(method)
  arr.map do |attrs|
    attrs = {:value => attrs} unless attrs.is_a?(Hash)
    attrs[:checked] = true if (val == attrs[:value])
    radio_group_item(method, attrs)
  end.join
end
bound_select(method, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 91
def bound_select(method, attrs = {})
  name = control_name(method)
  update_bound_controls(method, attrs, "select")
  unbound_select({:name => name}.merge(attrs))
end
bound_text_area(method, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 103
def bound_text_area(method, attrs = {})
  name = "#{@name}[#{method}]"
  update_bound_controls(method, attrs, "text_area")
  unbound_text_area(control_value(method), {:name => name}.merge(attrs))
end
button(contents, attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 114
def button(contents, attrs)
  update_unbound_controls(attrs, "button")
  tag(:button, contents, attrs)
end
fieldset(attrs, &blk) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 21
def fieldset(attrs, &blk)
  legend = (l_attr = attrs.delete(:legend)) ? tag(:legend, l_attr) : ""
  tag(:fieldset, legend + @origin.capture(&blk), attrs)
  # @origin.concat(contents, blk.binding)
end
form(attrs = {}, &blk) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 15
def form(attrs = {}, &blk)
  captured = @origin.capture(&blk)
  fake_method_tag = process_form_attrs(attrs)
  tag(:form, fake_method_tag + captured, attrs)
end
submit(value, attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 119
def submit(value, attrs)
  attrs[:type]  ||= "submit"
  attrs[:name]  ||= "form_submit"
  attrs[:value] ||= value
  update_unbound_controls(attrs, "submit")
  self_closing_tag(:input, attrs)
end
unbound_check_box(attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 51
def unbound_check_box(attrs)
  update_unbound_controls(attrs, "checkbox")
  if attrs.delete(:boolean)
    on, off = attrs.delete(:on), attrs.delete(:off)
    unbound_hidden_field(:name => attrs[:name], :value => off) <<
      self_closing_tag(:input, {:type => "checkbox", :value => on}.merge(attrs))
  else
    self_closing_tag(:input, {:type => "checkbox"}.merge(attrs))
  end
end
unbound_radio_button(attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 68
def unbound_radio_button(attrs)
  update_unbound_controls(attrs, "radio")
  self_closing_tag(:input, {:type => "radio"}.merge(attrs))
end
unbound_radio_group(arr, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 82
def unbound_radio_group(arr, attrs = {})
  arr.map do |ind_attrs|
    ind_attrs = {:value => ind_attrs} unless ind_attrs.is_a?(Hash)
    joined = attrs.merge(ind_attrs)
    joined.merge!(:label => joined[:label] || joined[:value])
    unbound_radio_button(joined)
  end.join
end
unbound_select(attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 97
def unbound_select(attrs = {})
  update_unbound_controls(attrs, "select")
  attrs[:name] << "[]" if attrs[:multiple] && !(attrs[:name] =~ /\[\]$/)
  tag(:select, options_for(attrs), attrs)
end
unbound_text_area(contents, attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 109
def unbound_text_area(contents, attrs)
  update_unbound_controls(attrs, "text_area")
  tag(:textarea, contents, attrs)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.