Precompilation of thin patterns using the rail resource pipeline

It would be very convenient if I could precompile subtle templates using the rails resource pipeline. I was hoping to insert my templates in app / assets / html and serve them that way.

Here is what I have 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 does not compile them, and the output file still has the extension .slim.

Is there any way to make this work?

+7
source share
4 answers

The answer from @ kurt-mueller is correct, but it needs to be updated for Rails 4 with 3+ stars. Changes have occurred in Sprockets, which means that the assets property is missing during initialization. Instead, you can:

 # 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 
+1
source

I wish I was late for 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 the paste to the following line:

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

I did something similar with great success with HAML (which I use to write templates for Rails / AngJS applications).

+1
source

You can try adding a new path, like this, to production.rb :

 config.assets.precompile += ["*.js", "*.css", "*.slim"] #whatever you need 
0
source

you need to add static files to the precompilation array:

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

-one
source

All Articles