Beispiel #1
0
 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);
   });
 }
/**
 * 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);
}
Beispiel #3
0
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 ''
  }
}
Beispiel #4
0
  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);
  });
Beispiel #5
0
const renderTemplates = (context) => {
  generateFile("docker-compose.yml", context);
  generateFile("Dockerfile", context);
  console.log(nunjucks.render(templatePathFor("README.md"), context));
};
Beispiel #6
0
const generateFile = (fileName, context) => {
  let fileContent =   nunjucks.render(templatePathFor(fileName), context);
  fs.writeFile(fileName, fileContent);
};