{"_id":"562d247e26a0a10d00ad6c00","project":"55ba86e68f4ef01900c0ae1f","category":{"_id":"562d247b26a0a10d00ad6be7","__v":1,"pages":["562d247e26a0a10d00ad6bfc","562d247e26a0a10d00ad6bfd","562d247e26a0a10d00ad6bfe","562d247e26a0a10d00ad6bff","562d247e26a0a10d00ad6c00","562d247e26a0a10d00ad6c01","562d247e26a0a10d00ad6c02","562d247e26a0a10d00ad6c03","562d247e26a0a10d00ad6c04"],"project":"55ba86e68f4ef01900c0ae1f","version":"562d247a26a0a10d00ad6be2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T22:45:50.984Z","from_sync":false,"order":7,"slug":"autocode-elements","title":"Hacking Autocode"},"user":"55ba86a810133e2b00feb6bc","__v":0,"version":{"_id":"562d247a26a0a10d00ad6be2","__v":10,"project":"55ba86e68f4ef01900c0ae1f","createdAt":"2015-10-25T18:50:34.678Z","releaseDate":"2015-10-25T18:50:34.678Z","categories":["562d247b26a0a10d00ad6be3","562d247b26a0a10d00ad6be4","562d247b26a0a10d00ad6be5","562d247b26a0a10d00ad6be6","562d247b26a0a10d00ad6be7","562d247b26a0a10d00ad6be8","562d247b26a0a10d00ad6be9","566f8106f11d5a0d007226fa","566fb8be1dabd80d00b1206c","566fb8c4cbb2fb0d00f7c4c0","566fb8c9e10ecb0d0004edd0","566fb8ea6995210d003aaa65","566fb8fce10ecb0d0004edd1","566fb901e10ecb0d0004edd2","566fb90e81801f0d00802d60","566fb9126995210d003aaa66"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-30T22:54:59.525Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Since Engines interact directly with Crystal, they must be written in JavaScript and/or CoffeeScript.\"\n}\n[/block]\nEngines (or \"template engines\") apply data to templates.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Examples\"\n}\n[/block]\nHere is a simple example using [Mustache](https://mustache.github.io):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var handlebars = require('handlebars');\\n\\nmodule.exports = function(data, template) {\\n  var output = handlebars.compile(template)(data);\\n  return output;\\n};\",\n      \"language\": \"javascript\",\n      \"name\": \"engine.js\"\n    },\n    {\n      \"code\": \"# {{{name}}} v{{{version}}}\\n\\n{{{description}}}\",\n      \"language\": \"handlebars\",\n      \"name\": \"template.m\"\n    }\n  ]\n}\n[/block]\nHere is a simple example using [Jade](http://jade-lang.com):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var jade = require('jade');\\n\\nmodule.exports = function(data, template) {\\n  var fn = jade.compile(template);\\n  var output = fn(data);\\n  return output;\\n};\",\n      \"language\": \"javascript\",\n      \"name\": \"engine.js\"\n    },\n    {\n      \"code\": \"h1\\n  | Maintainer:\\n  = ' ' + maintainer.name\\ntable\\n  tr\\n    td Twitter\\n    td= maintainer.twitter\\n  tr\\n    td Blog\\n    td= maintainer.blog\",\n      \"language\": \"haxe\",\n      \"name\": \"template.jade\"\n    }\n  ]\n}\n[/block]","excerpt":"Template + Data = Engines","slug":"engines","type":"basic","title":"Engines"}

Engines

Template + Data = Engines

[block:callout] { "type": "info", "body": "Since Engines interact directly with Crystal, they must be written in JavaScript and/or CoffeeScript." } [/block] Engines (or "template engines") apply data to templates. [block:api-header] { "type": "basic", "title": "Examples" } [/block] Here is a simple example using [Mustache](https://mustache.github.io): [block:code] { "codes": [ { "code": "var handlebars = require('handlebars');\n\nmodule.exports = function(data, template) {\n var output = handlebars.compile(template)(data);\n return output;\n};", "language": "javascript", "name": "engine.js" }, { "code": "# {{{name}}} v{{{version}}}\n\n{{{description}}}", "language": "handlebars", "name": "template.m" } ] } [/block] Here is a simple example using [Jade](http://jade-lang.com): [block:code] { "codes": [ { "code": "var jade = require('jade');\n\nmodule.exports = function(data, template) {\n var fn = jade.compile(template);\n var output = fn(data);\n return output;\n};", "language": "javascript", "name": "engine.js" }, { "code": "h1\n | Maintainer:\n = ' ' + maintainer.name\ntable\n tr\n td Twitter\n td= maintainer.twitter\n tr\n td Blog\n td= maintainer.blog", "language": "haxe", "name": "template.jade" } ] } [/block]