coz-examples
Examples for coz
Examples
01 Minimum Demo
01-minimum-demo/.who-likes-what.txt.bud
/** * .who-likes-what.txt.bud * This is a bud file for "examples/01-minimum-demo" */ // Exports as a Node.js module.moduleexports = // Template string. By default, parsed by Handlebars engine. tmpl: '{{#each members}}Hi, my name is {{@key}}. I like {{this}}.\n{{/each}}' // Overwrite when already existing. force: true // File path to write out. path: 'who-likes-what.txt' // File permission. mode: '444' // Data to render. data: members: "Mai": "apple" "Tom": "Orange" "Rita": "Banana" ;
01-minimum-demo/who-likes-what.txt
Hi, my name is Mai. I like apple.Hi, my name is Tom. I like Orange.Hi, my name is Rita. I like Banana.
02 Separated Template
02-separated-template/.what-colors.html.bud
/** * .what-colors.html.bud * This is a bud file for "examples/02-separated-template" */ // Exports as a Node.js module.moduleexports = // Template file path. Relative to this bud file. tmpl: '.what-colors.html.hbs' // Overwrite when already existing. force: true // File path to write out. path: 'what-colors.html' // File permission. mode: '444' // Data to render. data: ;
02-separated-template/.what-colors.html.hbs
Colors {{#each colors}} {{@key}}{{this}} {{/each}}
02-separated-template/.what-colors.html.json
02-separated-template/what-colors.html
Colors bananayellow applered grapepurple
04 From Programmatic Api
04-from-programmatic-api/.travel-by-what.txt.bud
/** * .travel-by-what.txt * This is a bud file for "examples/04-from-programmatic-api" */ // Exports as a Node.js module.moduleexports = tmpl: '{{#each ways}}Goes {{@key}} by {{this}}.\n{{/each}}' force: true mode: '444' data: ways: 'Tokyo': 'Train' 'France': 'Airplane' ;
04-from-programmatic-api/run_rendering.js
#!/usr/bin/env node /** * run_rendering.js * This is an executable file for "examples/04-from-programmatic-api/run_rendering.js" */ var coz = ; // Render .bud files.coz;
04-from-programmatic-api/travel-by-what.txt
Goes Tokyo by Train.Goes France by Airplane.
05 Exec Bud Itself
05-exec-bud-itself/.exec-me.txt.bud
#!/usr/bin/env node /** * .exec-me.txt.bud * This is a bud file for "examples/04-exec-bud-itself" */ moduleexports = force: true mode: '444' tmpl: 'This file is rendered from: "{{from}}"' data: from: ; // If there is no parent, it means that this module is executed directory.// e.g., `node .exec-me.txt.bud`var main = moduleparent == null;if main // Render this bud file. // `__filename` is Node.js reserved word and contains path of this file. ;
05-exec-bud-itself/exec-me.txt
This file is rendered from: ".exec-me.txt.bud"
06 Customize Coz
06-customize-coz/.render-by-custom-cli.txt.bud
/** * render-by-custom-cli.txt.bud * This is a bud file for "examples/06-customize-coz" */ // Bud for coz CLI with custom configurationmoduleexports = force: true mode: '444' tmpl: 'myCustomTmpl01' data: 'generator': __filename ;
06-customize-coz/.render-with-custom-setup.txt.bud
/** * render-with-custom-setup.txt.bud * This is a bud file for "examples/06-customize-coz" */ // Bud with custom setupmoduleexports = force: true mode: '444' // Template with using custom helper function. tmpl: 'Hey, {{emphasize msg}}' engine: 'handlebars' // Setup options for handlebars engine. setup: // Register custom handlebars helpers. helpers: { return txt + '!!!!'; } data: 'msg': 'watch out' ;if !moduleparent ;
06-customize-coz/render-by-custom-cli.txt
myCustomTmpl01
06-customize-coz/render-by-my-custom-engine-01.txt
This is good day to die.
06-customize-coz/render-by-my-custom-tmpl-01.json
06-customize-coz/render-with-custom-engine.js
#!/usr/bin/env node /** * render-with-custom-engine.js * This is an executable file for "examples/06-customize-coz" */ var Coz = Coz; // Create a custom coz context.var coz = // Define custom engines. engines: 'myCustomEngine01': // Aliases for this engine. // These names also can be used in "engine" property of bud. $aliases: 'myCustom01' /** * Compile template string and create template function. * @implements {module:coz/lib/template~Engine.prototype.compile} * @param * @param */ { // Define a template function with source. // Template function takes a single agument `data` object and returns rendered string. /** * Compiled template function * @param * @returns */ { var rendered = Stringsource; Object; return rendered; } // Pass the template function to callback. var err = null; ; } ; // Use custom coz context to render.coz;
06-customize-coz/render-with-custom-setup.txt
Hey, WATCH OUT!!!!
06-customize-coz/render-with-custom-tmpl.js
#!/usr/bin/env node /** * render-with-custom-tmpl.js * This is an executable file for "examples/06-customize-coz" */ var Coz = Coz; // Create a custom coz context.var coz = // Define custom templates. tmpls: // Custom template to generate single line json string. { return JSON; } ; coz;
06-customize-coz/use-custom-config-from-cli.config.js
/** * use-custom-config-from-cli.config.js * This is a CLI configuration file for "examples/06-customize-coz" */ // Custom configuration for CLImoduleexports = tmpls: // Custom template function. { return JSON; } ;
06-customize-coz/use-custom-config-from-cli.sh
#!/bin/bash ### # use-custom-config-from-cli.sh # This is a CLI shell file for "examples/06-customize-coz" ## HERE=$(dirname $0) cd ${HERE} # Render bud with custom configuration. coz render ".render-by-custom-cli.txt.bud" -c "use-custom-config-from-cli.config.js"