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

Inherits:
Object
  • Object
show all
Includes:
Tag
Defined in:
merb-helpers/lib/merb-helpers/form/builder.rb

Direct Known Subclasses

Form

Instance Method Summary (collapse)

Methods included from Tag

#close_tag, #open_tag, #self_closing_tag, #tag

Constructor Details

- (Base) initialize(obj, name, origin)



10
11
12
13
# File 'merb-helpers/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

Instance Method Details

- (Object) bound_check_box(method, attrs = {})



45
46
47
48
49
# File 'merb-helpers/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

- (Object) bound_radio_button(method, attrs = {})



62
63
64
65
66
# File 'merb-helpers/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

- (Object) bound_radio_group(method, arr)



73
74
75
76
77
78
79
80
# File 'merb-helpers/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

- (Object) bound_select(method, attrs = {})



91
92
93
94
95
# File 'merb-helpers/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

- (Object) bound_text_area(method, attrs = {})



103
104
105
106
107
# File 'merb-helpers/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

- (Object) button(contents, attrs)



114
115
116
117
# File 'merb-helpers/lib/merb-helpers/form/builder.rb', line 114

def button(contents, attrs)
  update_unbound_controls(attrs, "button")
  tag(:button, contents, attrs)
end

- (Object) fieldset(attrs, &blk)



21
22
23
24
25
# File 'merb-helpers/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

- (Object) form(attrs = {}, &blk)



15
16
17
18
19
# File 'merb-helpers/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

- (Object) submit(value, attrs)



119
120
121
122
123
124
125
# File 'merb-helpers/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

- (Object) unbound_check_box(attrs)



51
52
53
54
55
56
57
58
59
60
# File 'merb-helpers/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

- (Object) unbound_radio_button(attrs)



68
69
70
71
# File 'merb-helpers/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

- (Object) unbound_radio_group(arr, attrs = {})



82
83
84
85
86
87
88
89
# File 'merb-helpers/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

- (Object) unbound_select(attrs = {})



97
98
99
100
101
# File 'merb-helpers/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

- (Object) unbound_text_area(contents, attrs)



109
110
111
112
# File 'merb-helpers/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