當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。