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?
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
1 What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.
4.1 Precompiling Assets. Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk. Compiled assets are written to the location specified in config.
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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With