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 <%…%>
-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 suppliedcontext
object<%= @helper() %>
Escape and print the return value of acontext
helper
For more advanced features, including how to handle whitespace, be sure and check the README
Discussion
Sign in or Join to comment or subscribe