3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/helpers/solder/application_helper.rb', line 3
def solder_onto(name, touch: [], attribute_safelist: ["class"], &block)
soldered_html = capture(&block).to_s.strip
fragment = Nokogiri::HTML.fragment(soldered_html)
first_fragment_child = fragment.first_element_child
ui_state = Rails.cache.read "solder/#{solder_key(name)}"
ui_state&.select { attribute_safelist.include?(_1) }&.each do |attribute_name, value|
first_fragment_child[attribute_name] = sanitize(value, tags: [])
end
first_fragment_child["data-controller"] = "#{first_fragment_child["data-controller"]} solder".strip
first_fragment_child["data-solder-key-value"] = solder_key(name)
first_fragment_child["data-solder-touch"] ||= Array(touch).map(&:to_sgid).map(&:to_s).join(":")
first_fragment_child.to_html.html_safe
end
|