@@ -9,37 +9,31 @@ def initialize(*args)
9
9
end
10
10
11
11
def inputs ( *args , &block )
12
- # Store that we are creating inputs without a block
13
- @inputs_with_block = block_given? ? true : false
14
- content = with_new_form_buffer { super }
15
- form_buffers . last << content . html_safe
12
+ @inputs_with_block = block_given?
13
+ form_buffers . last << with_new_form_buffer { super }
16
14
end
17
15
18
- # The input method returns a properly formatted string for
19
- # its contents, so we want to skip the internal buffering
20
- # while building up its contents
16
+ # If this `input` call is inside a `inputs` block, add the content
17
+ # to the form buffer. Else, return it directly.
21
18
def input ( method , *args )
22
- content = with_new_form_buffer { super }
23
- return content . html_safe unless @inputs_with_block
24
- form_buffers . last << content . html_safe
19
+ content = with_new_form_buffer { super }
20
+ @inputs_with_block ? form_buffers . last << content : content
25
21
end
26
22
27
- def cancel_link ( url = nil , html_options = { } , li_attributes = { } )
28
- li_attributes [ :class ] ||= "cancel"
29
- url ||= { :action => "index" }
30
- form_buffers . last << template . content_tag ( :li , ( template . link_to I18n . t ( 'active_admin.cancel' ) , url , html_options ) , li_attributes )
23
+ def cancel_link ( url = { :action => "index" } , html_options = { } , li_attrs = { } )
24
+ li_attrs [ :class ] ||= "cancel"
25
+ li_content = template . link_to I18n . t ( 'active_admin.cancel' ) , url , html_options
26
+ form_buffers . last << template . content_tag ( :li , li_content , li_attrs )
31
27
end
32
28
33
29
def actions ( *args , &block )
34
- content = with_new_form_buffer do
35
- block_given? ? super : super { commit_action_with_cancel_link }
30
+ form_buffers . last << with_new_form_buffer do
31
+ block_given? ? super : super { commit_action_with_cancel_link }
36
32
end
37
- form_buffers . last << content . html_safe
38
33
end
39
34
40
35
def action ( *args )
41
- content = with_new_form_buffer { super }
42
- form_buffers . last << content . html_safe
36
+ form_buffers . last << with_new_form_buffer { super }
43
37
end
44
38
45
39
def commit_action_with_cancel_link
@@ -76,16 +70,16 @@ def has_many(association, options = {}, &block)
76
70
form_buffers . last << template . content_tag ( :h3 , object . class . reflect_on_association ( association ) . klass . model_name . human ( :count => 1.1 ) )
77
71
inputs options , &form_block
78
72
79
- js = js_for_has_many ( association , form_block , template )
80
- form_buffers . last << js . html_safe
73
+ form_buffers . last << js_for_has_many ( association , form_block , template )
81
74
end
82
75
end
83
- form_buffers . last << content . html_safe
76
+ form_buffers . last << content
84
77
end
85
78
79
+ # BTW: the fact that this *could* return nil might currently be causing problems
86
80
def semantic_errors ( *args )
87
- content = with_new_form_buffer { super }
88
- form_buffers . last << content . html_safe unless content . nil?
81
+ content = with_new_form_buffer { super }
82
+ form_buffers . last << content if content
89
83
end
90
84
91
85
# These methods are deprecated and removed from Formtastic, however are
@@ -164,7 +158,7 @@ def input_class_by_trying(as)
164
158
165
159
def with_new_form_buffer
166
160
form_buffers << "" . html_safe
167
- return_value = yield
161
+ return_value = yield . html_safe
168
162
form_buffers . pop
169
163
return_value
170
164
end
@@ -187,9 +181,7 @@ def js_for_has_many(association, form_block, template)
187
181
text = I18n . t 'active_admin.has_many_new' , :model => association_human_name
188
182
onclick = "$(this).before('#{ js } '.replace(/#{ placeholder } /g, new Date().getTime())); return false;"
189
183
190
- template . link_to text , "#" ,
191
- :onclick => onclick ,
192
- :class => "button"
184
+ template . link_to ( text , "#" , :onclick => onclick , :class => "button" ) . html_safe
193
185
end
194
186
195
187
end
0 commit comments