k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
981 stars 59 forks source link

Using Hamlit in the asset pipeline in Rails 6 #155

Closed stuartgibson closed 4 years ago

stuartgibson commented 4 years ago

I'm currently attempting to upgrade a Rails 4 app to Rails 6. It uses haml templates in the asset pipeline for Angular components. In Rails 4, this worked fine with Hamlit registered as an engine in the asset config with the following in an initializer:

Rails.application.assets.register_engine('.haml', Hamlit::Template)

In the Rails 6 version of Sprockets, register_engine is no longer available and I can't work out how to get haml assets to work locally as before. Any pointers appreciated.

k0kubun commented 4 years ago

https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#registering-all-versions-of-sprockets-in-processors

Could you try the following one?

Rails.application.config.assets.configure do |env|
  env.register_mime_type 'text/haml', extensions: ['.haml']
  env.register_transformer 'text/haml', 'text/html', Hamlit::Template
end