3
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
|
# File 'app/helpers/easy_admin/fields_helper.rb', line 3
def render_field(field, action:, value: nil, record: nil, form: nil)
case field[:type]
when :custom_component
if field[:component_class] && record
component_options = field[:component_options] || {}
component_options[:user] = record if component_options[:user].nil?
component = field[:component_class].new(**component_options)
return component.call.html_safe
elsif field[:component_instance] && field[:component_instance].respond_to?(:call)
return field[:component_instance].call.html_safe
end
return ""
when :custom_content
if field[:block]
context = OpenStruct.new(form: form, record: record, helpers: self)
result = field[:block].call(context)
if result.respond_to?(:call) && result.respond_to?(:view_template)
render(result)
elsif result.is_a?(String)
result.html_safe
elsif result.respond_to?(:to_s)
result.to_s.html_safe
else
""
end
else
""
end
else
field_type = field[:type] || field[:field_type] || :text
component = EasyAdmin::Field.render(
field_type,
action: action,
field: field,
value: value,
record: record,
form: form
)
result = component.call
result.html_safe
end
end
|