Alex Rivera | Logout

Adding HAML to the Rails asset pipeline

Asked 2011-10-14T15:59:39.023
13

I would like to serve client side templates that have been pre-processed through HAML. I have tried using the haml_assets gem and adding the following code to an initializer:

Rails.application.assets.register_engine ".haml", Tilt::HamlTemplate

Both of these methods serve the raw HAML and not compiled HAML when I access the asset. How can I add HAML to the pipeline?

Edit
Report

1 Answer

5

This works for me:

# app/assets/javascripts/test.html.haml

%p hello

# config/initializers/haml_template.rb

Rails.application.assets.register_mime_type 'text/html', '.html'
Rails.application.assets.register_engine '.haml', Tilt::HamlTemplate

This works for http://127.0.0.1:3000/assets/test.html.haml

Rails.application.assets is a Sprockets::Environment.

See here for API reference:

answered 2012-03-14T05:19:13.670

Your Answer