当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript nunjucks.render函数代码示例

本文整理汇总了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);
   });
 }
开发者ID:bigbassroller,项目名称:isomorphic-ts,代码行数:7,代码来源:index.ts

示例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);
}
开发者ID:google,项目名称:google-api-nodejs-client,代码行数:33,代码来源:docs.ts

示例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 ''
  }
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:9,代码来源:index.ts

示例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);
  });
开发者ID:kaa,项目名称:gulp-nunjucks-template,代码行数:24,代码来源:index.ts

示例5: generateFile

const renderTemplates = (context) => {
  generateFile("docker-compose.yml", context);
  generateFile("Dockerfile", context);
  console.log(nunjucks.render(templatePathFor("README.md"), context));
};
开发者ID:levionessa,项目名称:dockerfile-generator,代码行数:5,代码来源:app.ts

示例6:

const generateFile = (fileName, context) => {
  let fileContent =   nunjucks.render(templatePathFor(fileName), context);
  fs.writeFile(fileName, fileContent);
};
开发者ID:levionessa,项目名称:dockerfile-generator,代码行数:4,代码来源:app.ts


注:本文中的nunjucks.render函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。