The project is in a healthy, maintained state
HTML Attributes utilities for use with ViewComponents
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

HTML Attributes Utilities

This is a small library intended to make it easier to deal with HTML attributes in View Components. It is based on https://github.com/x-govuk/html-attributes-utils

It uses 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

class MyViewComponent < ViewComponent::Base
  include Katalyst::HtmlAttributes
  
  def initialize(**html_attributes)
    super
  end
  
  def call
    tag.div(**html_attributes)
  end

  def default_html_attributes
    {
      class: "my-class"
    }
  end
end