app/components/lookbook/base_component.rb in lookbook-1.0.3 vs app/components/lookbook/base_component.rb in lookbook-1.0.4

- old
+ new

@@ -29,14 +29,22 @@ def alpine_component nil end + def alpine_encode(data) + if data.is_a? String + "\'#{json_escape data}\'" + else + json_escape data.to_json.tr("\"", "\'") + end + end + def prepare_alpine_data(x_data = nil) alpine_component_name = x_data || @html_attrs&.dig(:"x-data") || alpine_component if alpine_component_name.present? - args = Array.wrap(alpine_data) - args.any? ? "#{alpine_component_name}(#{safe_join(args)})" : alpine_component_name + args = Array.wrap(alpine_data).compact + args.any? ? "#{alpine_component_name}(#{args.join(",")})" : alpine_component_name end end end end