Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dynamic param value contains double-quotes make alpine x-data has… #602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/components/lookbook/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ def alpine_component
end

def alpine_encode(data)
if data.is_a? String
"'#{json_escape data}'"
else
json_escape data.to_json.tr("\"", "'")
end
data.to_json
end

def prepare_alpine_data(x_data = nil)
Expand Down
4 changes: 2 additions & 2 deletions app/components/lookbook/params/field/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def before_render
styles, html = StylesExtractor.call(render_input)
Editor::Component.add_styles(param.input, styles)

escaped_value = json_escape(param.value.to_s).gsub("\n", '\n')
data = { name: param.name, value: param.value }.to_json
wrapper_attrs = {
data: {"param-input": param.input},
"x-data": "paramsInputComponent({name: \"#{param.name}\", value: \"#{escaped_value}\"})"
"x-data": "paramsInputComponent(#{data})"
}
@rendered_input = tag.div(**wrapper_attrs) { html.html_safe }
end
Expand Down