Sha256: 834cb46e1eda48b4e2a09a7314db1b644e994f0f11eeb71b2a3a74206b347d23
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
# HTML Attributes Utilities [](https://github.com/DFE-Digital/html-attributes-utils/actions/workflows/tests.yml) [](https://codeclimate.com/github/DFE-Digital/html-attributes-utils/maintainability) [](https://codeclimate.com/github/DFE-Digital/html-attributes-utils/test_coverage)    This is a small library intended to make it easier to deal with HTML attributes. It was written to reduce overlap in the [govuk-components](https://github.com/DFE-Digital/govuk-components) and [govuk-formbuilder](https://github.com/DFE-Digital/govuk-formbuilder) libraries. It provides refinements for `Hash` that allow: * deep merging while protecting default values from being overwritten * tidying hashes by removing key/value pairs that have empty or nil values ## Example use ```ruby require "html_attributes_utils" def MyPresenter using HTMLAttributesUtils def initialize(custom_attributes = {}) @custom_attributes = custom_attributes end def attributes default_attributes .deep_merge_html_attributes(@custom_attributes) .deep_tidy_html_attributes end private def default_attributes { lang: "en-GB", class: "govuk-juggling-widget" } end end MyPresenter.new(lang: "fr", class: "stripes", some_other_attr: "").attributes => { lang: "fr", class: ["govuk-juggling-widget", "stripes"] } ```
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
katalyst-govuk-formbuilder-1.9.2 | vendor/bundle/ruby/3.3.0/gems/html-attributes-utils-1.0.2/README.md |
html-attributes-utils-1.0.2 | README.md |
html-attributes-utils-1.0.1 | README.md |