Using the Eco Template Engine with Rails

Eco is the built-in Coffeescript template language. It resembles an ERB. Is there a way I can use this as a server-side template language in a Rails application?

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

+4
source share
5 answers

I just noticed that Rails 3.1 will support this. Basically, Sam Stevenson just posted ruby-eco and hooked up asterisks to use it. Thus, this means using .eco in your view, only templates will now work.

Link to commit

+10
source

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

+3
source

[ Update . As Ben points out below, sstephenson - the creator of Eco and a member of the Rails group - created something called ruby-eco , which allows the two to play well together. My initial answer below precedes this project.]

It is not possible to do this directly because Eco runs on Node.js and you cannot run Node.js directly in Rails (see this related question ).

You can proxy specific routes from your Rails application to a Node.js application running on a different port, but there would be no easy way to transfer information between the two applications, so this would probably be pointless.

Currently Eco vs. Rails is either a solution or a solution. But if you don't want to jump from Rails to Node, you can still use server-side JavaScript templating using Johnson , which allows you to run JS from Ruby. (As far as I know, no one has written CoffeeScript-Johnson integration yet - you could write it quite easily, though, using the coffee -pe to convert CoffeeScript to JavaScript.)

+2
source

I have a project using eco inside the rails as a safe template system like Liquid. I call it Ice and ends at http://github.com/ludicast/ice .

I originally used some common JavaScript template engine, but collecting steam around eco made it an easy choice.

+1
source

Source: https://habr.com/ru/post/1341388/


All Articles