{"__v":1,"_id":"562d247e26a0a10d00ad6bff","category":{"__v":1,"_id":"562d247b26a0a10d00ad6be7","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"},"project":"55ba86e68f4ef01900c0ae1f","user":"55ba86a810133e2b00feb6bc","version":{"__v":10,"_id":"562d247a26a0a10d00ad6be2","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:47:02.409Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Generators generate code.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Examples\"\n}\n[/block]\nThis generator is static, meaning it does not accept any input. The output file `README.md` will always be the same as the template `template.hbs`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"outputs:\\n  - generator:\\n      filename: README.md\\n      template: template.hbs\",\n      \"language\": \"yaml\",\n      \"name\": \"config.yml\"\n    },\n    {\n      \"code\": \"# Hello, world!\\n\\nHow are you today?\",\n      \"language\": \"text\",\n      \"name\": \"template.hbs\"\n    },\n    {\n      \"code\": \"# Hello, world!\\n\\nHow are you today?\",\n      \"language\": \"markdown\",\n      \"name\": \"Output: README.md\"\n    }\n  ]\n}\n[/block]\nIn order to accept input, add a [Schema](doc:schematics) and [Engine](doc:engines) to your Generator:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"name: My Application\\ndescription: My Application is an application.\\noutputs:\\n  - generator:\\n  \\t\\tengine: handlebars.js\\n      filename: README.md\\n      schema:\\n      \\ttype: object\\n        properties:\\n          name:\\n            required: true\\n            type: string\\n          description:\\n          \\trequired: true\\n            type: string\\n          version:\\n          \\trequired: true\\n            type:\\n              - number\\n              - string\\n      template: template.hbs\",\n      \"language\": \"yaml\",\n      \"name\": \"config.yml\"\n    },\n    {\n      \"code\": \"# {{{name}}} v{{{version}}}\\n\\n{{{description}}}\",\n      \"language\": \"text\",\n      \"name\": \"template.hbs\"\n    },\n    {\n      \"code\": \"module.exports = function(data, template) {\\n  template = template.replace('{{{name}}}', data.name);\\n  template = template.replace('{{{version}}}', data.version);\\n  template = template.replace('{{{description}}}', data.description);\\n  return template;\\n};\",\n      \"language\": \"javascript\",\n      \"name\": \"handlebars.js\"\n    },\n    {\n      \"code\": \"# My Application v1.0.0\\n\\nMy Application is an application.\",\n      \"language\": \"text\",\n      \"name\": \"Output: README.md\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The `handlebars.js` file in this example is meant to be a psuedo-[Handlebars.js](http://handlebarsjs.com) engine. Check out [handlebars.template](https://hub.crystal.sh/handlebars/template) for a real working Engine for Handlebars.js.\"\n}\n[/block]","excerpt":"","slug":"generators","type":"basic","title":"Generators"}
Generators generate code. [block:api-header] { "type": "basic", "title": "Examples" } [/block] This generator is static, meaning it does not accept any input. The output file `README.md` will always be the same as the template `template.hbs`: [block:code] { "codes": [ { "code": "outputs:\n - generator:\n filename: README.md\n template: template.hbs", "language": "yaml", "name": "config.yml" }, { "code": "# Hello, world!\n\nHow are you today?", "language": "text", "name": "template.hbs" }, { "code": "# Hello, world!\n\nHow are you today?", "language": "markdown", "name": "Output: README.md" } ] } [/block] In order to accept input, add a [Schema](doc:schematics) and [Engine](doc:engines) to your Generator: [block:code] { "codes": [ { "code": "name: My Application\ndescription: My Application is an application.\noutputs:\n - generator:\n \t\tengine: handlebars.js\n filename: README.md\n schema:\n \ttype: object\n properties:\n name:\n required: true\n type: string\n description:\n \trequired: true\n type: string\n version:\n \trequired: true\n type:\n - number\n - string\n template: template.hbs", "language": "yaml", "name": "config.yml" }, { "code": "# {{{name}}} v{{{version}}}\n\n{{{description}}}", "language": "text", "name": "template.hbs" }, { "code": "module.exports = function(data, template) {\n template = template.replace('{{{name}}}', data.name);\n template = template.replace('{{{version}}}', data.version);\n template = template.replace('{{{description}}}', data.description);\n return template;\n};", "language": "javascript", "name": "handlebars.js" }, { "code": "# My Application v1.0.0\n\nMy Application is an application.", "language": "text", "name": "Output: README.md" } ] } [/block] [block:callout] { "type": "info", "body": "The `handlebars.js` file in this example is meant to be a psuedo-[Handlebars.js](http://handlebarsjs.com) engine. Check out [handlebars.template](https://hub.crystal.sh/handlebars/template) for a real working Engine for Handlebars.js." } [/block]