25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/stay/helper.rb', line 25
def stay(record, field, opts = {})
raise ArgumentError, "Can't have Canceller without Submitter" if opts[:canceller] && opts[:submitter].nil?
opts[:type] ||= :text_field
html = "<span class='stay' "
html << "data-activator='#{ opts[:activator] }' " if opts[:activator]
html << "data-submitter='#{ opts[:submitter] }' " if opts[:submitter]
html << "data-canceller='#{ opts[:canceller] }' " if opts[:canceller]
html << "data-tinymce-theme='simple' " if opts[:type] == :tiny_mce
html << "data-tinymce-theme='#{ opts[:type][1] }' " if opts[:type].is_a?(Array)
html << ">"
html << "<span class='stay-object'>"
val = (record.is_a?(Array) ? record.last : record).send(field)
if val.nil?
html << "-"
else
html << sanitize(val, tags: %w(p strong em span ul li ol br)).to_html
end
html << "</span>"
html << "<span class='stay-form' style='display:none'>"
html << generate_form(record, field, opts[:type])
html << "</span>"
html << "</span>"
html.html_safe
end
|