本文整理汇总了TypeScript中nunjucks.render函数的典型用法代码示例。如果您正苦于以下问题:TypeScript render函数的具体用法?TypeScript render怎么用?TypeScript render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
handler: function (request, reply) {
// read template and compile using context object
nunjucks.render('index.html', getName(request), function (err, html) {
// reply with HTML response
reply(html);
});
}
示例2: main
/**
* Iterate over each API directory, and use the `compodoc` tool to generate
* reference API documentation in the `docs` folder. This folder is ignored
* in git, so a publish must be done with `npm run publish-docs`.
*
* To use this, run `npm run generate-docs`.
*/
async function main() {
const children = await readdir(apiPath);
const dirs = children.filter(x => {
return (
!x.endsWith('.ts') &&
!x.includes('dfareporting') &&
!x.includes('compute')
);
});
const contents = nunjucks.render(templatePath, {apis: dirs});
await writeFile(indexPath, contents);
const q = new Q({concurrency: 50});
console.log(`Generating docs for ${dirs.length} APIs...`);
let i = 0;
const promises = dirs.map(dir => {
return q
.add(() =>
execa('npx', ['compodoc', `src/apis/${dir}`, '-d', `./docs/${dir}`])
)
.then(() => {
i++;
console.log(`[${i}/${dirs.length}] ${dir}`);
});
});
await Promise.all(promises);
}
示例3: render
function render (claim: Claim, type: string): string {
const dashboardName = ClaimStatusFlow.dashboardFor(claim)
try {
const template = nunjucks.render(path.join(__dirname, './views', 'status', type, dashboardName + '.njk').toString(), { claim: claim })
return app.settings.nunjucksEnv.filters['safe'](template)
} catch (err) {
return ''
}
}
示例4: callback
return through.obj(function(file:gutil.File, encoding: string, callback: (err?: Error, data?: gutil.File) => void): void {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream() ||Â !(file.contents instanceof Buffer)) {
return this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
var data = JSON.parse(file.contents.toString());
let result: string;
try {
result = nunjucks.render(template, data);
} catch(err) {
return callback(new gutil.PluginError(PLUGIN_NAME, err, {fileName: template}));
}
var basename = path.basename(file.path),
stylename = basename.substr(0, basename.length-path.extname(basename).length);
var resultFile = file.clone({contents: false});
resultFile.path = gutil.replaceExtension(file.path, ".html");
resultFile.contents = new Buffer(result);
callback(null, resultFile);
});
示例5: generateFile
const renderTemplates = (context) => {
generateFile("docker-compose.yml", context);
generateFile("Dockerfile", context);
console.log(nunjucks.render(templatePathFor("README.md"), context));
};
示例6:
const generateFile = (fileName, context) => {
let fileContent = nunjucks.render(templatePathFor(fileName), context);
fs.writeFile(fileName, fileContent);
};