activeadmin / arbre

An Object Oriented DOM Tree in Ruby
MIT License
764 stars 74 forks source link

Include empty attributes in HTML output #543

Closed javierjulio closed 11 months ago

javierjulio commented 12 months ago

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.

codecov[bot] commented 12 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/activeadmin/arbre/pull/543?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=activeadmin) | Coverage Δ | | |---|---|---| | [lib/arbre/html/attributes.rb](https://app.codecov.io/gh/activeadmin/arbre/pull/543?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=activeadmin#diff-bGliL2FyYnJlL2h0bWwvYXR0cmlidXRlcy5yYg==) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.