-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Support nested attribute hashes rendered as hyphenated attributes #451
Conversation
There was a problem hiding this 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?
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 :) |
@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? |
@javierjulio 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. |
@javierjulio - any update on the ability for this to be merged? |
@Ikariusrb yes, I will get to this soon, thank you. |
Codecov ReportPatch coverage:
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
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. |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…tiveadmin#451) * add support for nested attribute hashes rendered as hyphen separated flat attributes * move two more tests inside #to_s context
Closes #450