user94154
user94154

Reputation: 16574

Using the Eco template engine with Rails

Eco is an embedded Coffeescript templating language. It resembles ERB. Is there a way I can use this as a server-side templating language in a Rails app?

The ultimate goal is to use some partials written in Eco on both the client and the server.

Upvotes: 4

Views: 7264

Answers (5)

phaedryx
phaedryx

Reputation: 2054

Put gem 'eco' in your Gemfile and name your files with .jst.eco and it should work just fine in Rails 3.1

Upvotes: 3

MetaSkills
MetaSkills

Reputation: 1854

I just noticed that Rails 3.1 will support this. Basically Sam Stephenson just published ruby-eco and hooked up sprockets to use it. So this means using .eco in your view templates will now just work.

Link to the commit

Upvotes: 10

Trevor Burnham
Trevor Burnham

Reputation: 77416

[Update: As Ben points out below, sstephenson—the creator of Eco and a member of the core Rails team—has created something called ruby-eco that lets the two play nice together. My original answer, below, predates that project.]

It's not possible to do it directly, because Eco runs on Node.js, and you can't run Node.js directly within Rails (see this related question).

You could proxy certain routes from your Rails app to a Node.js app running on a different port, but there wouldn't be any easy way of passing information between the two applications, so this would likely be pointless.

For the time being, Eco vs. Rails is an either-or decision. But if you're not willing to make the leap from Rails to Node, you can still do JavaScript templating on the server side using Johnson, which lets you run JS from Ruby. (To my knowledge, no one has written a CoffeeScript-Johnson integration yet—you could write one yourself pretty easily, though, using the coffee -pe command to convert CoffeeScript to JavaScript.)

Upvotes: 2

Nate Kidwell
Nate Kidwell

Reputation: 21

I have a project using eco inside rails as a secure templating system like Liquid. I call it Ice and is over at http://github.com/ludicast/ice.

Initially I used some generic javascript templating engine but the steam gathering around eco made it an easy choice.

Upvotes: 1

Related Questions