I have situation where I generate stylesheets based on information in the database. This means I have a views/users/show.css.erb which contains code like:
a {
color: <%= @user.favorite_color %>;
}
Fair enough, works perfectly with a respond_to { |f| f.css } in my controller. However now I would like to use some of SASS’s sassy functions like lighten, darken etc. in my CSS, so I would like to have SASS parse my view. However I cannot figure out how to register SASS as a template handler in my views without too much ugly hacks. I just don’t get how it works. Has anyone ever tried this?
I have tried including SASS’s Functions module but to no avail.
I was planning of doing the same for dynamic user themes some time ago. Back then, I found a mailing list answer to a similar question to yours, by Nathan Weizenbaum (author of SASS) which got me back on the straight and narrow:
The link is not working anymore, but the SASS FAQ has only one section called Can I use a variable from my controller in my Sass file? which answer the dynamic question:
So in general, SASS is not designed for dynamic css generation on each request. Rather it is intended to be used as a pre compilation solution to generate static css files.