Skip to content

Commit

Permalink
Allow recursively nested tokens in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Oct 4, 2024
1 parent 7f166d7 commit ea5b4da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ def __nested_tokens__(tokens)
else
buffer << token.to_s
end
when Array
if token.length > 0
if i > 0
buffer << " " << __nested_tokens__(token)
else
buffer << __nested_tokens__(token)
end
end
when nil
# Do nothing
else
Expand Down
18 changes: 18 additions & 0 deletions quickdraw/sgml/attributes.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@
) == %(<div attribute="Hello"></div>)
end

test "_, Array(String | Array)" do
expect(
phlex { div(attribute: ["hello", ["world"]]) },
) == %(<div attribute="hello world"></div>)
end

test "_, Array(Array | String)" do
expect(
phlex { div(attribute: [["hello"], "world"]) },
) == %(<div attribute="hello world"></div>)
end

test "_, Array(String | EmptyArray)" do
expect(
phlex { div(attribute: ["hello", []]) },
) == %(<div attribute="hello"></div>)
end

test "_, Array(*invalid*)" do
expect {
phlex { div(attribute: [Object.new]) }
Expand Down

0 comments on commit ea5b4da

Please sign in to comment.