7

It would be super handy if I could precompile slim templates using the rails asset pipeline. I was hoping to stick my templates in app/assets/html and serve them up that way.

Here's what I've got so far:

# config/initializers/slim.rb
Rails.application.assets.register_engine('.slim', Slim::Template)

# config/application.rb
config.assets.paths << "#{Rails.root}/app/assets/html"
config.assets.register_mime_type('text/html', '.html')

Running rake assets:precompile reads the .html.slim files in app/assets/html but it doesn't compile them and the output file still has the .slim extension.

Is there a way to make this work?

Jimmy Baker
  • 3,215
  • 1
  • 24
  • 26

4 Answers4

1

Sorry I'm tardy to the party, but Dillon Buchanan answered this question here.

Go to the config/initializers directory and create a file like slim_assets.rb (or something similar) and copy-pasta the following line:

Rails.application.assets.register_engine('.slim', Slim::Template)

I've done something similar with great success with HAML (which I use to write templates for Rails/AngJS apps).

Kurt Mueller
  • 3,173
  • 2
  • 29
  • 50
1

The answer by @kurt-mueller is correct but needs to be updated for Rails 4 with Sprockets 3+. There was a change in Sprockets that means the assets property is not present during initialisation. Instead you can do:

# config/initializers/slim.rb

Rails.application.config.after_initialize do |app|
  app.config.assets.configure do |env|
    env.register_engine(".slim", Slim::Template)
  end
end
Andrew France
  • 4,758
  • 1
  • 25
  • 27
  • Updated my answer to use the [recommended method](https://github.com/rails/sprockets-rails/issues/307#issuecomment-170707886). – Andrew France Feb 10 '16 at 17:03
0

You could try to add the new path like this on production.rb:

config.assets.precompile += ["*.js", "*.css", "*.slim"]  #whatever you need
Anezio Campos
  • 1,555
  • 1
  • 10
  • 18
-1

you need add the static files into precompile array:

config.assets.precompile += %w( vendor/modernizr 404.html )