4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/jintastic.rb', line 4
def in_place_editor_for(path_spec_or_object, attributes, html_text = nil)
instance = path_spec_or_object.kind_of?(Array) ? path_spec_or_object.last : path_spec_or_object
if attributes.class==Symbol
attribute = attributes
input_attributes = Array(attribute)
elsif attributes.values.first==:form
attribute = attributes.keys.first
elsif attributes.values.first.class==String
attribute = attributes.keys.first
form_partial = attributes[attribute]
else
attribute = attributes.keys.first
input_attributes = attributes[attribute]
end
container_tag = instance.respond_to?(:column_for_attribute) ?
instance.column_for_attribute(attribute).type == :text ? :pre : :span : :span
form_tag_options = {}
content_tag_options = {:class=>'in_place_attribute'}
form_partial ||= "#{instance.class.to_s.downcase.pluralize}/form" unless input_attributes
html_text ||= instance[attribute]
if instance.valid?
form_tag_options.merge!({:html=>{:style=>"display: none"}})
else
content_tag_options.merge!({:style=>"display: none"})
end
render :partial => 'jintastic/in_place_editor',
:locals => {:container_tag=>container_tag,
:input_attributes=>input_attributes,
:path_spec_or_object=>path_spec_or_object,
:html_text=>html_text,
:content_tag_options=>content_tag_options,
:form_tag_options=>form_tag_options,
:form_partial=>form_partial}
end
|