Read more

Breaking changes for boolean attributes in HAML 6

Emanuel De
May 16, 2023Software engineer at makandra GmbH

Haml 6 has some breaking changes Show snapshot regarding boolean attributes Show snapshot .

Only the following attributes and aria/data attributes are considered boolean attributes: allowfullscreen, async, autobuffer, autofocus, autoplay, checked, controls, default, defer, disabled, download, formnovalidate, hidden, inert, ismap, itemscope, loop, multiple, muted, novalidate, open, pubdate, readonly, required, reversed, scoped,
seamless, selected, sortable, truespeed, typemustmatch

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show snapshot

This requires you to change custom attributes in case you want them to be an attribute without a value e.g. a(up-test) has to be changed to a(up-test='') in HAML 6.


Haml (no breaking changes) Version 5 Version 6
%button(disabled) <button disabled=""></button> <button disabled=""></button>
%button(disabled=true) <button disabled=""></button> <button disabled=""></button>
%button(disabled=false) <button></button> <button></button>
%button(disabled='true') <button disabled="true"></button> <button disabled="true"></button>
%button(disabled='false') <button disabled="false"></button> <button disabled="false"></button>
%button(disabled='') <button disabled=""></button> <button disabled=""></button>
Haml (no breaking changes) Version 5 Version 6
%button(data-test) <button data-test=""></button> <button data-test=""></button>
%button(data-test=true) <button data-test=""></button> <button data-test=""></button>
%button(data-test=false) <button></button> <button></button>
%button(data-test='true') <button data-test="true"></button> <button data-test="true"></button>
%button(data-test='false') <button data-test="false"></button> <button data-test="false"></button>
%button(data-test='') <button data-test=""></button> <button data-test=""></button>
Haml (with breaking changes) Version 5 Version 6
%button(up-test) <button up-test=""></button> <button up-test="true"></button>
%button(up-test=true) <button up-test=""></button> <button up-test="true"></button>
%button(up-test=false) <button></button> <button up-test="false"></button>
%button(up-test='true') <button up-test="true"></button> <button up-test="true"></button>
%button(up-test='') <button up-test=""></button> <button up-test=""></button>

Monkey Patch

In case you want to reconfigure the attributes that a recognized as boolean attributes you can use this monkey patch in an initializer:

Haml::AttributeBuilder.class_eval do
  remove_const(:BOOLEAN_ATTRIBUTES).tap do |boolean_attributes|
    const_set(:BOOLEAN_ATTRIBUTES, [*boolean_attributes, /^up-/].freeze)
Emanuel De
May 16, 2023Software engineer at makandra GmbH
Posted by Emanuel De to makandra dev (2023-05-16 16:14)