Posts Tagged ‘asset pipeline’

Running jQuery code from Ruby using ExecJS-Async

9.4.11 by eric

pipes

Last week I wrote a post about using the Asset Pipeline outside of Rails because we needed to test answers for Code School’s upcoming Zombies 2 course. But we also need a way to test javascript (that uses jQuery) that manipulates a DOM, and all from inside of Ruby.

ExecJS to the rescue

ExecJS is a ruby gem that lets you run JavaScript code from Ruby. It does this by using the best javascript runtime available to evaluate Javascript and returning the result in Ruby! For example:

ExecJS.eval "'red yellow blue'.split(' ')"
# => ["red", "yellow", "blue"]

Rad! Or you can use it to compile a block of javascript and then call it later, like this:

context = ExecJS.compile "var run = function(foo) { return foo + foo }"
context.call 'run', 'bar'
# => 'barbar'

Read the rest of this entry »

Using the Asset Pipeline outside of Rails – Serving CoffeeScript and SASS

8.28.11 by eric

In our upcoming Rails for Zombies 2 Code School course, we have a couple of challenges that make use of Rails 3.1 new Asset Pipeline. The Asset Pipeline is the thing in Rails that serves up your javascript, images, and stylesheets. But it can also compile CoffeeScript into Javascript, or SASS into CSS.

And so we wanted to teach people a little bit of CoffeeScript/SASS in Rails for Zombies 2. But that means we have to have a way to test CoffeeScript/SASS. We accomplished this by extracting the bits in Rails 3.1 that implement the pipeline and used them to serve and compile CoffeeScript into Javascript and SASS into CSS.

Read the rest of this entry »