Transformers

Transforms output before rendering.

📘

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

Transformers take the output from Generators and transforms it.

Some use cases include:

  • converting from one format to another (i.e CoffeeScript to JavaScript, JSON to XML, etc.)
  • beautifying output

Examples

Here is a simple example of a Transformer that transforms CoffeeScript to JavaScript:

var coffeescript = require('coffee-script');

module.exports = function(cs) {
  var js = coffeescript.compile(cs, { bare: true });
  return js;
};

Did this page help you?