Skip to content

feat(element): Add add_attribute for valueless attributes - #144

Open
gjtorikian wants to merge 2 commits into
mainfrom
add-attribute-without-value
Open

feat(element): Add add_attribute for valueless attributes#144
gjtorikian wants to merge 2 commits into
mainfrom
add-attribute-without-value

Conversation

@gjtorikian

Copy link
Copy Markdown
Owner

Summary

  • Adds Selma::HTML::Element#add_attribute(name) for setting valueless attributes (e.g. data-foo) without having to pass "" via []=
  • lol_html still requires a value under the hood, so the attribute is written as name=""
  • If the attribute already exists, the existing value is preserved (no-op rather than overwrite)
  • Documents the new method in the README element API list
  • Closes Support for writing attributes without a value, e.g. element#tag_name["data-foo"] = true #38

Test plan

  • bundle exec rake test passes
  • New test confirms <p> gains data-this-is-special=""
  • New test confirms existing attribute value is preserved

Adds `Selma::HTML::Element#add_attribute(name)` for the common case of
annotating an element with a valueless attribute (e.g. `data-foo`)
without having to pass an empty string via `[]=`. lol_html still
requires a value, so the attribute is written as `name=""`. If the
attribute already exists, the existing value is preserved.

Closes #38
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.

Support for writing attributes without a value, e.g. element#tag_name["data-foo"] = true

1 participant