How to use the --bare option in Rails 3.1 for CoffeeScript?

Does anyone know how I can use this option in Rails 3.1? Now CoffeScript puts a function with .call(this) in every file, but I want to remove it.

EDIT: " Unable to find the variable" error with Rails 3.1 and Coffeescript "and the" template for CoffeeScript modules "that I want. I will change my global vars to use the @global area.

+12
ruby-on-rails coffeescript
May 23 '11 at 15:26
source share
2 answers

I would recommend not to do this. See My answer in the Template for CoffeeScript Modules for some reason. ("Making CoffeeScript code incompatible with ready-made Rails 3.1" is another reason.) It's better to just use

 window.a = b 

or even

 @a = b 

instead of a = b when you are trying to export something to a global scope.

In previous versions of Rails 3.1, bare compilation was enabled. This was classified as a bug and fixed in RC1.

So, although I strongly recommend you not to do this , here's how to enable bare assembly: Add

 Tilt::CoffeeScriptTemplate.default_bare = true 

to your environment.rb .

+20
May 23 '11 at 16:08
source share

I recommend taking advantage of CoffeeScript closure and keeping track of the distribution of the CommonJS module. But sometimes, sometimes, it's quite normal to use the --bare option. In my case, when providing the Jasmine spec helper, so that I can keep things at the top level, and also use the included Sprockets directive in the Jasmine specifications.

To this end, I created the sprockets-blackcoffee gem, which you can learn about here. https://github.com/metaskills/sprockets-blackcoffee

+4
Jan 12 2018-12-12T00:
source share



All Articles