New in Haml 3.2: hyphenated data attributes

One of the best new features in Haml 3.2 for me personally is the hyphenate_data_attrs option. Here's what it does:

%a{ data: { post_id: 1 } } Link

Haml 3.1

<a data-post_id="1">Link</a>

Haml 3.2

<a data-post-id="1">Link</a>

This ugly data-post_id always bothered me, but now it got dealt with.

The 3.2 version is not released yet, so if you want to use it right now, add this to your Gemfile:

gem 'haml', '3.2.0.rc.2', branch: '3-2-stable', github: 'haml/haml'

Note that in 3.2 hyphenate_data_attrs will be true by default. You can turn it off (but really, simply update your js code that depends on your data- attributes) by putting this into an initializer:

# config/initializers/haml.rb
Haml::Template.options[:hyphenate_data_attrs] = false

You're the 2346th person to read this article.