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

Allow recursively nested tokens in attributes #807

Merged
merged 1 commit into from
Oct 4, 2024
Merged
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
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