Skip to content

Tutorial04 Using programmatic API

Taka Okunishi edited this page Jun 24, 2015 · 16 revisions

Overview

coz provides programmatic API.

This is usefull when you do not want to install coz globally.

Install coz locally

$ npm install coz --save-dev

Base usage.

This is an example to execute rendering via programmatic API.

#!/usr/bin/env

/**
 * run_rendering.js
 * This is a bud file for "examples/04-from-programmatic-api/run_rendering.js"
 */

var coz = require('coz');

// Render .bud files.
coz.render([
    '**/.*.bud'
], function (err) {
    console.log(err ? err : 'Done!');
});


#!/usr/bin/env

/**
 * .exec-me.txt.bud
 * This is a bud file for "examples/04-exec-bud-itself"
 */

module.exports = {
    force: true,
    mode: '444',
    tmpl: 'This file is rendered from: ""',
    data: {
        from: __filename
    }
};

// If there is no parent, it means that this module is executed directory.
// e.g., `node .exec-me.txt.bud`
var main = module.parent == null;
if (!main) {
    // Render this bud file.
    // `__filename` is Node.js reserved word and contains path of this file.
    require('coz').render(__filename);
}

See also

Tutorials

Links

Clone this wiki locally