neorails-form_fu 0.7 → 0.41

Sign up to get free protection for your applications and to get access to all the features.
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.7'
4
- s.date = '2008-11-18'
3
+ s.version = '0.41'
4
+ s.date = '2008-07-07'
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"
@@ -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"), super(field, purge_custom_tags(options)), &block)
18
+ format_with_label(field, options.merge(:field_type => "text_area", :preserve => true), super(field, purge_custom_tags(options)), &block)
19
19
  end
20
20
 
21
21
  # wrap the date_select helper
@@ -74,17 +74,18 @@ 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
- 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
77
+ # see if we have an error on the field
78
+ errors_on = object.send(:errors).send(:on, field)
79
+ has_error = true unless errors_on.blank?
83
80
 
84
81
  # set field options
85
82
  options[:field] ||= {}
86
83
  options[:field].merge!(:has_error => has_error, :field_type => options[:field_type])
87
84
 
85
+ if options[:preserve]
86
+ tag_output = @template.preserve(tag_output)
87
+ end
88
+
88
89
  # find label name
89
90
  label_name = options[:label] || field.to_s.humanize
90
91
  options[:separator] ||= default_separator
@@ -94,14 +95,13 @@ module FormFu
94
95
  output_html = @template.field_tag(options[:field], [
95
96
  @template.label(@object_name, field, label_name),
96
97
  tag_output,
97
- block_given? ? @template.universal_capture(&block) : nil,
98
- @template.validation_tag(@object, field)
98
+ @template.validation_tag(@object, field),
99
+ block_given? ? @template.capture(&block) : nil
99
100
  ].compact.join("\n"))
100
101
 
101
102
  if block_given?
102
103
  # concat to page if block was given
103
- @template.universal_concat(output_html)
104
- return nil
104
+ return @template.concat(output_html, block.binding)
105
105
  else
106
106
  # otherwise return html directly
107
107
  return output_html
@@ -1,31 +1,14 @@
1
1
  module FormFu
2
2
  module Helpers
3
3
  # Create a form_for block using FormFuBuilder
4
- def formfu_for(*args, &block)
5
- raise ArgumentError, "Missing block" unless block_given?
6
-
4
+ def formfu_for(record_or_name_or_array, *args, &proc)
7
5
  options = args.extract_options!
8
6
  args << options.merge(:builder => FormFu::FormBuilder)
9
- form_for(*args, &block)
10
-
7
+ form_for(record_or_name_or_array, *args, &proc)
11
8
  end
12
9
 
13
10
  # also work with the more semantic name (build_form_for)
14
11
  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
-
29
12
 
30
13
  # Create a fields_for block using FormFuBuilder
31
14
  def formfu_fields_for(object_or_object_name, *args, &block)
@@ -51,10 +34,10 @@ module FormFu
51
34
  # wrap content with a fieldset tag with a legend
52
35
  def fieldset_tag(legend_name, options = {}, &block)
53
36
  if block_given?
54
- universal_concat(content_tag(:fieldset, options) do
37
+ concat(content_tag(:fieldset, options) do
55
38
  (legend_name ? content_tag(:legend, legend_name) : "")+
56
- universal_capture(&block)
57
- end)
39
+ capture(&block)
40
+ end, block.binding)
58
41
  else
59
42
  return content_tag(:fieldset, options) do
60
43
  content_tag :legend, legend_name
@@ -81,10 +64,10 @@ module FormFu
81
64
  end
82
65
 
83
66
  if block_given?
84
- universal_concat(content_tag(:div, options) do
67
+ concat(content_tag(:div, options) do
85
68
  (label.blank? ? "" : content_tag(:label, label.strip)) +
86
- universal_capture(&block)
87
- end)
69
+ capture(&block)
70
+ end, block.binding)
88
71
  else
89
72
  content_tag(:div, options) do
90
73
  (label.blank? ? "" : content_tag(:label, label.strip))+content.to_s
@@ -103,21 +86,5 @@ module FormFu
103
86
  end
104
87
  end
105
88
 
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
-
122
89
  end
123
90
  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.7"
4
+ version: "0.41"
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-11-18 00:00:00 -08:00
12
+ date: 2008-07-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency