Rails - embedded scss file in Javascript

I am on Rails 3.2 with an asset pipeline.

I would like to embed some minified css in a javascript string (to dynamically include it from the JS library I'm writing). My css is written using scss and my js using coffeescript.

Do you know how to do this?

+4
source share
1 answer

I would go with @meagar to have CSS and a JavaScript file.

However, if you really want to get it through javascript, you can add an async get call (e.g. $ .get) and treat the response as your new line. Ugly, hum?

Another option is to generate CSS output and put it manually in your javascript or, even better, load it into your coffeescript file as follows:

for filename in list do (filename) -> fs.readFile filename, (err, contents) -> compile filename, contents.toString() 

(e.g. coffescript.org )

0
source

All Articles