This is a plugin meant for Jekyll.
This filter is described at the Shopify Liquid wiki, but somehow didn't make it into the general repository.
Just plop this guy in your _plugins directory and use it like this:
var title = {{ page.title | json }};
Easy!
Shouldn't this work the same without requiring Rails?