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

Include empty attributes in HTML output #543

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

javierjulio
Copy link
Member

This is mostly a full revert of commit 1526789 which was a bad change. Empty attributes are valid HTML (e.g. boolean attributes) and should be supported in Arbre. The bad commit was for just addressing the class attribute but that applied to any attribute in HTML when it shouldn't have, even for just class. Note that if an attribute value is nil then it is removed. This follows same output logic to the Rails tag.attributes helper method.

With this change, the generated HTML string is improved:

tag = Arbre::HTML::Tag.new
tag.build disabled: nil, required: "", class: "blue"
tag.to_s
=> "<tag required=\"\" class=\"blue\"></tag>\n"

Prior to this change, the output for that would have been:

=> "<tag class=\"blue\"></tag>\n"

This will be in a major (v2) release due to being a breaking change.

@javierjulio javierjulio self-assigned this Oct 8, 2023
@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (70ed0b9) 91.66% compared to head (04cee57) 91.57%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #543      +/-   ##
==========================================
- Coverage   91.66%   91.57%   -0.09%     
==========================================
  Files          17       17              
  Lines         480      475       -5     
==========================================
- Hits          440      435       -5     
  Misses         40       40              
Files Coverage Δ
lib/arbre/html/attributes.rb 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This is mostly a full revert of commit 1526789 which was a bad change. Empty attributes are valid HTML and should be supported in Arbre (e.g. boolean attributes). The bad commit was for just addressing the class attribute but that applied to any attribute in HTML when it shouldn't have, even for class. Note that if an attribute value is nil then it is removed. This follows similar output logic to Rails `tag.attributes` helper.
@javierjulio javierjulio force-pushed the include-empty-attributes-in-html branch from bdf5e9b to 04cee57 Compare October 24, 2023 21:15
@javierjulio javierjulio merged commit 8164455 into master Oct 24, 2023
22 checks passed
@javierjulio javierjulio deleted the include-empty-attributes-in-html branch October 24, 2023 21:31
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.

1 participant