Engines

Template + Data = Engines

📘

Since Engines interact directly with Crystal, they must be written in JavaScript and/or CoffeeScript.

Engines (or "template engines") apply data to templates.

Examples

Here is a simple example using Mustache:

var handlebars = require('handlebars');

module.exports = function(data, template) {
  var output = handlebars.compile(template)(data);
  return output;
};
# {{{name}}} v{{{version}}}

{{{description}}}

Here is a simple example using Jade:

var jade = require('jade');

module.exports = function(data, template) {
  var fn = jade.compile(template);
  var output = fn(data);
  return output;
};
h1
  | Maintainer:
  = ' ' + maintainer.name
table
  tr
    td Twitter
    td= maintainer.twitter
  tr
    td Blog
    td= maintainer.blog

Did this page help you?