本文整理匯總了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);
};