From ea5b4daa6c295d3ba8208cdb70fc282dbaf24638 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Thu, 3 Oct 2024 20:55:35 -0500 Subject: [PATCH] Allow recursively nested tokens in attributes --- lib/phlex/sgml.rb | 8 ++++++++ quickdraw/sgml/attributes.test.rb | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index ec501fcd..3fb74572 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -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 diff --git a/quickdraw/sgml/attributes.test.rb b/quickdraw/sgml/attributes.test.rb index c1e3ac0d..e96040c7 100644 --- a/quickdraw/sgml/attributes.test.rb +++ b/quickdraw/sgml/attributes.test.rb @@ -258,6 +258,24 @@ ) == %(
) end +test "_, Array(String | Array)" do + expect( + phlex { div(attribute: ["hello", ["world"]]) }, + ) == %(
) +end + +test "_, Array(Array | String)" do + expect( + phlex { div(attribute: [["hello"], "world"]) }, + ) == %(
) +end + +test "_, Array(String | EmptyArray)" do + expect( + phlex { div(attribute: ["hello", []]) }, + ) == %(
) +end + test "_, Array(*invalid*)" do expect { phlex { div(attribute: [Object.new]) }