neorails-form_fu 0.3 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -1
- data/form_fu.gemspec +1 -1
- data/lib/form_fu/form_builder.rb +13 -4
- metadata +1 -1
data/README
CHANGED
data/form_fu.gemspec
CHANGED
data/lib/form_fu/form_builder.rb
CHANGED
@@ -3,15 +3,17 @@ module FormFu
|
|
3
3
|
# A form builder that produces tableless, lined-up forms.
|
4
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
5
|
# automatically wrap all the standard formbuilder helpers
|
6
|
-
(field_helpers - %w(label hidden_field
|
6
|
+
(field_helpers - %w(label hidden_field text_area select apply_form_for_options!)).each do |selector|
|
7
7
|
src = <<-END_SRC
|
8
|
+
alias :#{selector}_input :#{selector}
|
8
9
|
def #{selector}(field, options = {}, &block)
|
9
10
|
format_with_label(field, options.merge(:field_type => "#{selector}"), super(field, purge_custom_tags(options)), &block)
|
10
11
|
end
|
11
12
|
END_SRC
|
12
13
|
class_eval src, __FILE__, __LINE__
|
13
14
|
end
|
14
|
-
|
15
|
+
|
16
|
+
alias :text_area_input :text_area
|
15
17
|
def text_area(field, options = {}, &block)
|
16
18
|
format_with_label(field, options.merge(:field_type => "text_area", :preserve => true), super(field, purge_custom_tags(options)), &block)
|
17
19
|
end
|
@@ -36,7 +38,7 @@ module FormFu
|
|
36
38
|
# build radio choices html
|
37
39
|
choices_html = ""
|
38
40
|
choices.each do |key, value|
|
39
|
-
radio_html =
|
41
|
+
radio_html = radio_button_input(field, value)+key
|
40
42
|
|
41
43
|
# wrap radio html in a label (for easier selection)
|
42
44
|
choices_html << @template.content_tag(:label, radio_html, :class => "radio-option")
|
@@ -47,6 +49,7 @@ module FormFu
|
|
47
49
|
end
|
48
50
|
|
49
51
|
# wrap the select helper
|
52
|
+
alias :select_input :select
|
50
53
|
def select(field, choices, options={}, &block)
|
51
54
|
html_options = options.delete(:html) || {}
|
52
55
|
format_with_label(field, options.merge(:field_type => "select"), super(field, choices, options, html_options), &block)
|
@@ -83,8 +86,14 @@ module FormFu
|
|
83
86
|
tag_output = @template.preserve(tag_output)
|
84
87
|
end
|
85
88
|
|
89
|
+
# find label name
|
90
|
+
label_name = options[:label] || field.to_s.humanize
|
91
|
+
options[:separator] ||= default_separator
|
92
|
+
label_name = "#{label_name}#{options.delete(:separator)}"
|
93
|
+
|
94
|
+
# build output html
|
86
95
|
output_html = @template.field_tag(options[:field], [
|
87
|
-
@template.label(@object_name, field,
|
96
|
+
@template.label(@object_name, field, label_name),
|
88
97
|
tag_output,
|
89
98
|
@template.validation_tag(@object, field),
|
90
99
|
block_given? ? @template.capture(&block) : nil
|