Skip to content

Commit

Permalink
Fix a bug when nesting attributes more than two levels with hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Sep 7, 2024
1 parent 7267eed commit 6251bda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def __nested_attributes__(attributes, base_name, buffer = +"")
when Integer, Float
buffer << " " << base_name << name << '="' << v.to_s << '"'
when Hash
__nested_attributes__(v, "#{base_name}-#{name}-", buffer)
__nested_attributes__(v, "#{base_name}#{name}-", buffer)
when Array
buffer << " " << base_name << name << '="' << __nested_tokens__(v) << '"'
when Set
Expand Down
20 changes: 20 additions & 0 deletions quickdraw/sgml/attributes.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,24 @@

expect(example.call) == %(<#{tag} data-controller="foo" data-turbo-action="delete">content</#{tag}>)
end

test "<#{tag}> with nil attributes" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, class: nil, style: nil, data: { controller: nil }) { "content" }
end
end

expect(example.call) == %(<#{tag}>content</#{tag}>)
end

test "<#{tag}> with deeply nested attributes" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, data: { controller: "foo", foo: { comments_outlet: "#comments" } }) { "content" }
end
end

expect(example.call) == %(<#{tag} data-controller="foo" data-foo-comments-outlet="#comments">content</#{tag}>)
end
end

0 comments on commit 6251bda

Please sign in to comment.