JoHksi JoHksi - 1 year ago 110
CoffeeScript Question

how does preprocessor engine runs when asset files are compiled in rails?

Let's say I have a file called

I'm confused how this file is interpreted when rails application is compiled. My understanding is like following:
1) Coffeescript preprocessor engine interprets from coffeescript to ruby(erb).
2) ERB preprocessor engine converts ruby to javscript.

Am I understanding this correctly?

Answer Source

For example,

The extension of the file will be composed of two parts: the format (foobar.js) followed by the handler (

A handler is a preprocessor for the template, or a templating language. There are a number of handlers built in, and many more can be added by using extra gems.

The order of conversion is from right to left.

In your case, the CoffeeScript engine try to convert CoffeeScript into JavaScript (Error may occur because of existing ERB may cause CoffeeScript has invalid syntax) and then the ERB handlers will replace all the Ruby code to what the output value should be.

I always put .erb at last for these kind of situation. For example, main.css.scss.erb or app.js.es6.erb.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download