Lightweight template engine.
templator
is a lightweight template engine featuring the following functionality:
-
Replaces
{{property_name_1.property_name_2.etc}}
with the value of the corresponding propertydata.property_name_1.property_name_2.etc
of adata
object passed as a parameter to the module's imported function. -
Replaces
{{> ./relative_path/file_name.ext}}
with recursively rendered content of the target file. -
Recursively renders all files in the
srcFolder
, except files with names starting with the_
symbol, and places the rendered files in thedestFolder
.
$ npm install templator --save-dev
const templator = require('templator');
const data = getDataObjectSomehow();
templator(srcFolder, destFolder, data)
.then(() => {
console.log('Success!');
})
.catch(err => {
console.error(err);
});
srcFolder {String}
- Absolute or relative (to process.cwd()
) path to the folder containing the templates.
destFolder {String}
- Absolute or relative (to process.cwd()
) path to the folder the rendered files to be saved in.
data {Object}
- A data object to be used to replace {{property1.property2}}
placeholders.
Returns {Promise<Void>}
.