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
|
# File 'app/helpers/trestle/format_helper.rb', line 22
def autoformat_value(value, options={})
case value
when Array
content_tag(:ol, safe_join(value.map { |v|
content_tag(:li, v.is_a?(Array) ? v : autoformat_value(v, options)) },
"\n"))
when Time, DateTime
timestamp(value)
when Date
datestamp(value)
when TrueClass, FalseClass
status_tag(icon("fa fa-check"), :success) if value
when NilClass
blank = options.key?(:blank) ? options[:blank] : I18n.t("admin.format.blank")
if blank.respond_to?(:call)
instance_exec(&blank)
else
content_tag(:span, blank, class: "blank")
end
when String
if value.html_safe? || options[:truncate] == false
value
else
truncate(value, options[:truncate] || {})
end
when ->(value) { value.respond_to?(:id) }
display(value)
else
value
end
end
|