eco: Embedded CoffeeScript templates for Node.js

Node developers have a growing number of templating options these days. EJS, Jade, and Mustache.js are popular options.

Sam Stephenson has released 1.0.0 of Eco, or Embedded CoffeeScript, his take on EJS. If you’re unfamiliar with CoffeeScript, be sure and check out Episode 0.2.9.

You can install eco via npm

npm install eco

… and the usual require:

eco = require "eco"

Eco templates look much like EJS templates, except the escaped code is CoffeeScript instead of JavaScript:

<% if @projects.length: %>
  <% for project in @projects: %>
    <a href="<%= project.url %>"><%= project.name %></a>
    <p><%= project.description %></p>
  <% end %>
<% else: %>
  No projects
<% end %>

Like most &lt;%...%&gt;-based templating languages, Eco’s code blocks come in a few flavors:

  • <% expression %> Evaluate without printing
  • <%= expression %> Evaluate, escape, and print
  • <%- expression %> Evaluate and print without escaping
  • <%= @property %> Escape and print the value of a supplied context object
  • <%= @helper() %> Escape and print the return value of a context helper

For more advanced features, including how to handle whitespace, be sure and check the README

[Source on GitHub]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

 
0:00 / 0:00