neorails-form_fu 0.5 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/form_fu.gemspec +2 -2
- data/lib/form_fu/form_builder.rb +10 -11
- data/lib/form_fu/helpers.rb +38 -8
- metadata +2 -2
data/form_fu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'form_fu'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2008-
|
3
|
+
s.version = '0.7'
|
4
|
+
s.date = '2008-11-18'
|
5
5
|
|
6
6
|
s.summary = "Build Nice DRY Rails Forms"
|
7
7
|
s.description = "FormFu is a Rails plugin that enables you to easily build nice, tableless forms"
|
data/lib/form_fu/form_builder.rb
CHANGED
@@ -15,7 +15,7 @@ module FormFu
|
|
15
15
|
|
16
16
|
alias :text_area_input :text_area
|
17
17
|
def text_area(field, options = {}, &block)
|
18
|
-
format_with_label(field, options.merge(:field_type => "text_area"
|
18
|
+
format_with_label(field, options.merge(:field_type => "text_area"), super(field, purge_custom_tags(options)), &block)
|
19
19
|
end
|
20
20
|
|
21
21
|
# wrap the date_select helper
|
@@ -74,18 +74,17 @@ module FormFu
|
|
74
74
|
|
75
75
|
# format a helper by generating the haml to wrap it in a field_tag and include a label
|
76
76
|
def format_with_label(field, options, tag_output, &block)
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
if object and object.errors
|
78
|
+
# see if we have an error on the field
|
79
|
+
has_error = object.errors.on(field).present?
|
80
|
+
else
|
81
|
+
has_error = false
|
82
|
+
end
|
80
83
|
|
81
84
|
# set field options
|
82
85
|
options[:field] ||= {}
|
83
86
|
options[:field].merge!(:has_error => has_error, :field_type => options[:field_type])
|
84
87
|
|
85
|
-
if options[:preserve]
|
86
|
-
tag_output = @template.preserve(tag_output)
|
87
|
-
end
|
88
|
-
|
89
88
|
# find label name
|
90
89
|
label_name = options[:label] || field.to_s.humanize
|
91
90
|
options[:separator] ||= default_separator
|
@@ -95,13 +94,13 @@ module FormFu
|
|
95
94
|
output_html = @template.field_tag(options[:field], [
|
96
95
|
@template.label(@object_name, field, label_name),
|
97
96
|
tag_output,
|
98
|
-
@template.
|
99
|
-
|
97
|
+
block_given? ? @template.universal_capture(&block) : nil,
|
98
|
+
@template.validation_tag(@object, field)
|
100
99
|
].compact.join("\n"))
|
101
100
|
|
102
101
|
if block_given?
|
103
102
|
# concat to page if block was given
|
104
|
-
@template.
|
103
|
+
@template.universal_concat(output_html)
|
105
104
|
return nil
|
106
105
|
else
|
107
106
|
# otherwise return html directly
|
data/lib/form_fu/helpers.rb
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
module FormFu
|
2
2
|
module Helpers
|
3
3
|
# Create a form_for block using FormFuBuilder
|
4
|
-
def formfu_for(
|
4
|
+
def formfu_for(*args, &block)
|
5
5
|
raise ArgumentError, "Missing block" unless block_given?
|
6
6
|
|
7
7
|
options = args.extract_options!
|
8
8
|
args << options.merge(:builder => FormFu::FormBuilder)
|
9
|
-
form_for(
|
9
|
+
form_for(*args, &block)
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# also work with the more semantic name (build_form_for)
|
14
14
|
alias :build_form_for :formfu_for
|
15
|
+
|
16
|
+
|
17
|
+
# Create a form_for block using FormFuBuilder
|
18
|
+
def remote_formfu_for(*args, &block)
|
19
|
+
raise ArgumentError, "Missing block" unless block_given?
|
20
|
+
|
21
|
+
options = args.extract_options!
|
22
|
+
args << options.merge(:builder => FormFu::FormBuilder)
|
23
|
+
remote_form_for(*args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# also work with the more semantic name (build_form_for)
|
27
|
+
alias :build_remote_form_for :remote_formfu_for
|
28
|
+
|
15
29
|
|
16
30
|
# Create a fields_for block using FormFuBuilder
|
17
31
|
def formfu_fields_for(object_or_object_name, *args, &block)
|
@@ -37,10 +51,10 @@ module FormFu
|
|
37
51
|
# wrap content with a fieldset tag with a legend
|
38
52
|
def fieldset_tag(legend_name, options = {}, &block)
|
39
53
|
if block_given?
|
40
|
-
|
54
|
+
universal_concat(content_tag(:fieldset, options) do
|
41
55
|
(legend_name ? content_tag(:legend, legend_name) : "")+
|
42
|
-
|
43
|
-
end
|
56
|
+
universal_capture(&block)
|
57
|
+
end)
|
44
58
|
else
|
45
59
|
return content_tag(:fieldset, options) do
|
46
60
|
content_tag :legend, legend_name
|
@@ -67,10 +81,10 @@ module FormFu
|
|
67
81
|
end
|
68
82
|
|
69
83
|
if block_given?
|
70
|
-
|
84
|
+
universal_concat(content_tag(:div, options) do
|
71
85
|
(label.blank? ? "" : content_tag(:label, label.strip)) +
|
72
|
-
|
73
|
-
end
|
86
|
+
universal_capture(&block)
|
87
|
+
end)
|
74
88
|
else
|
75
89
|
content_tag(:div, options) do
|
76
90
|
(label.blank? ? "" : content_tag(:label, label.strip))+content.to_s
|
@@ -89,5 +103,21 @@ module FormFu
|
|
89
103
|
end
|
90
104
|
end
|
91
105
|
|
106
|
+
def universal_capture(&block)
|
107
|
+
if respond_to?(:is_haml?) and is_haml?
|
108
|
+
capture_haml(&block)
|
109
|
+
else
|
110
|
+
capture(&block)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def universal_concat(html)
|
115
|
+
if haml?
|
116
|
+
haml_concat(html)
|
117
|
+
else
|
118
|
+
concat(html)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
92
122
|
end
|
93
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neorails-form_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.7"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Crocker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|