Template manager. A simple wrapper of lodash template for using vio internally.
- Source:
Methods
(static) generate(targetPath, args)
- Source:
Process the template file and save the result to virtual IO. If the target file has existed, throw fatal error and exit.
Example
const template = require('rekit-core').template;
const tpl = 'hello ${user}!';
template.generate('path/to/result.txt', { template: tpl, context: { user: 'Nate' } });
// Result => create a file 'path/to/result.txt' which contains text: 'hello Nate!'
// NOTE the result is only in vio, you need to call vio.flush() to write to disk.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
targetPath |
string | The path to save the result. |
||||||||||||
args |
Object | The path to save the result. Properties
|
(static) readTemplate(file)
- Source:
Read a template content, if the file isn't absolute path, find it in rekit-core/templates folder. Otherwise read the file content. If the file doesn't exist, throw fatal error and exit.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | The path to the template file. |