diff --git a/lib/phlex/html.rb b/lib/phlex/html.rb index afe24b88..bb6e00b5 100644 --- a/lib/phlex/html.rb +++ b/lib/phlex/html.rb @@ -354,7 +354,14 @@ def capture(&block) when Symbol buffer << " " << name << '="' << ERB::Util.html_escape(v.name) << '"' when Hash - _build_attributes(v.transform_keys { "#{k}-#{_1.name.tr('_', '-')}" }, buffer: buffer) + _build_attributes( + v.transform_keys { |subkey| + case subkey + when Symbol then"#{k}-#{subkey.name.tr('_', '-')}" + else "#{k}-#{subkey}" + end + }, buffer: buffer + ) else buffer << " " << name << '="' << ERB::Util.html_escape(v.to_s) << '"' end diff --git a/test/phlex/view/attributes.rb b/test/phlex/view/attributes.rb index 37951569..e9cb04af 100644 --- a/test/phlex/view/attributes.rb +++ b/test/phlex/view/attributes.rb @@ -15,6 +15,18 @@ def template end end + with "string keyed hash attributes" do + view do + def template + div data: { "name_first_name" => "Joel" } + end + end + + it "flattens the attributes without dasherizing them" do + expect(output).to be == %(
) + end + end + if RUBY_ENGINE == "ruby" with "unique tag attributes" do view do