Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-attributes-utils

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-attributes-utils

  • 1.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

HTML Attributes Utilities

Tests Maintainability Test Coverage GitHub Supported ruby versions Supported rails versions

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 and 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

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"] }

FAQs

Package last updated on 25 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc