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

Support nested attribute hashes rendered as hyphenated attributes #451

Merged
merged 2 commits into from
Mar 18, 2023
Merged

Support nested attribute hashes rendered as hyphenated attributes #451

merged 2 commits into from
Mar 18, 2023

Conversation

Ikariusrb
Copy link
Contributor

@Ikariusrb Ikariusrb commented Feb 10, 2023

Closes #450

Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks! Only a minor note on the context grouping since I figured what's here was unintentional.

Would you mind adding another context with the same test case pairing but testing that a data attribute as a full named key (with hyphens, not using nested hashes) works as expected?

spec/arbre/unit/html/tag_attributes_spec.rb Outdated Show resolved Hide resolved
@javierjulio javierjulio marked this pull request as ready for review February 11, 2023 01:11
@Ikariusrb
Copy link
Contributor Author

Ikariusrb commented Feb 11, 2023

Would you mind adding another context with the same test case pairing but testing that a data attribute as a full named key (with hyphens, not using nested hashes) works as expected?

I'm not quite certain what you're asking for here. You're asking for a test showing that the (exceedingly awkward) code that I (ab)used to get Arbre to emit a hyphenated attribute before still works? If that's what you're asking for, I can add a test easily, but IMO the code I used to do that was terrible and should never be encouraged, and adding a test to codify it as part of the developer contract would be encouragement in my eyes.

If that's not what you're asking for, I'm a bit lost, and require further clarification :)

@javierjulio
Copy link
Member

javierjulio commented Feb 11, 2023

@Ikariusrb no but I think we should still address the original issue. I'm good with the support here for nested hashes, so thank you! My understanding is that with your changes, it should resolve the original issue you had right? For example, this test case passes with your changes.

      it "should render the attributes to html" do
        tag.build id: "my_id", "data-action" => "action"
        expect(tag.to_s).to eq "<tag id=\"my_id\" data-action=\"action\"></tag>\n"
      end

I was thinking for completion it would be nice to have a set of tests like this in the pattern you set up, to further demonstrate that hyphenated keys rather than nested hashes also works as expected now. What do you think?

@Ikariusrb
Copy link
Contributor Author

Ikariusrb commented Feb 11, 2023

@javierjulio
My PR doesn't change the ability to pass in hyphenated attributes directly at all. The problem is ruby itself doesn't support hyphenated symbols constructed with colon shorthand syntax, and Arbre expects to receive the attributes as keyword args, so you have to construct a hash, use .to_sym and rocket to get a hyphenated key, then double-splat it out to the keyword args to get it passed in as Arbre expects. I consider that workaround to've been mostly a hack.

Changing the call signature for the tag builders is something I'd rather not attempt to touch, as that's far more likely to break something than what I added. The approach would likely be to accept attributes as a hash. I believe ruby will gather keyword args and put them in a hash if there's a final empty positional arg in a method signature, but to make that change I'd want to review the tests with more care than I have time for to make sure all cases were covered, and even then I'd be worried someone would've done something fun and unique in the wild that would end up breaking.

@Ikariusrb
Copy link
Contributor Author

@javierjulio - any update on the ability for this to be merged?

@javierjulio
Copy link
Member

@Ikariusrb yes, I will get to this soon, thank you.

@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.12 🎉

Comparison is base (b09b813) 91.23% compared to head (faf4f99) 91.36%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #451      +/-   ##
==========================================
+ Coverage   91.23%   91.36%   +0.12%     
==========================================
  Files          17       17              
  Lines         468      475       +7     
==========================================
+ Hits          427      434       +7     
  Misses         41       41              
Impacted Files Coverage Δ
lib/arbre/html/attributes.rb 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@javierjulio
Copy link
Member

@Ikariusrb I rebased to get CI green again on the latest. I reviewed this and realize why this makes no changes to hyphenated attributes. I remember now why I asked though since I wanted to have a test case to demonstrate that it works as we didn't have a test for that. The reason why is that the arguments are forwarded and the last arg is a hash, so keyword arguments in this case should not matter. It wasn't dependent on your change. It's a related request to improve the tests.

@javierjulio javierjulio removed the request for review from deivid-rodriguez March 18, 2023 23:44
@javierjulio javierjulio self-assigned this Mar 18, 2023
Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@javierjulio javierjulio merged commit cb35476 into activeadmin:master Mar 18, 2023
@javierjulio javierjulio changed the title add support for nested attribute hashes rendered as hyphen separated flat attributes Support nested attribute hashes rendered as hyphenated attributes Mar 18, 2023
varyonic pushed a commit to varyonic/arbo that referenced this pull request Jul 27, 2023
…tiveadmin#451)

* add support for nested attribute hashes rendered as hyphen separated flat attributes

* move two more tests inside #to_s context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hyphenated tag attributes are poorly supported, making stimulus integration painful
2 participants