Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install barista/coffeescript on Rails 2.3

I am trying to get barista up and running in a Rails 2.3 application (that may not be moved to a new version of rails for the time beeing..). I switched the app to bundle so I added the following gems to my Gemspec:

gem "barista"
gem "json"

Then executed bundle install which run through. Now as far as I understand to "compile" the coffeescript there is a rake task that comes with barista. But it doesn't seem to be installed properly so I can use it with rake. I.e. when I execute rake -T there is no barista:brew

I saw a pending pull request on git hub suggesting to add require 'barista/tasks' but that only resulted in rake not finding it. So what am I doing wrong or more general how do I get up and running with barista on Rails 2.3.x?

like image 447
Mark Avatar asked Dec 17 '25 20:12

Mark


2 Answers

It has been some time ago since I used Barista and I have it not in use in any project, so I cannot verify it.

But I remember that one advantage of Barista is, that it waits serving a request until a modified CoffeeScript file is recompiled. This ensures that the browser doesn't request an outdated file.

So there is no need to compile the CoffeeScript files with a Rake task.

CoffeeScript itself comes also with a watch function, that compiles CoffeeScripts when a change is detected:

coffee -w /path/to/scripts

The reason why I stopped using Barista is simply that I discovered Guard. So I wrote guard-coffeescript to compile my CoffeeScripts in the same moment I save the file.

Guard-coffeescript has some advantages over Barista and CoffeeScript:

  • Fast and low CPU consumption because it relies on file system modification events.
  • Can be configured in many ways, e.g. multiple source folders and output folders.
  • Immediate feedback when an error occurs, even with system notifications like Growl.
like image 83
Netzpirat Avatar answered Dec 19 '25 11:12

Netzpirat


Note that Rails 2 support for Barista is, according to Barista's README, "untested" (it was originally built for Rails 3 only), so there may be compatibility issues. Also note that you need either therubyracer gem, or the node binary on your system's PATH (or any of the other JS runtimes supported by ExecJS).

Try this:

  1. Add a file named foo.coffee to the folder app/coffeescripts with the contents

    alert 'Hello, Barista!'

  2. Now add <%= javascript_include_tag "foo" %> to an ERB file and load that page.

You should get the alert, just as you would if the compiled foo.js were in public/javascripts.

like image 28
Trevor Burnham Avatar answered Dec 19 '25 09:12

Trevor Burnham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!