How to use the nunjucks.render function in nunjucks

To help you get started, we’ve selected a few nunjucks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philipwalton / blog / tasks / content.js View on Github external
// render the shell as a full page, minify it, and then split it up.
  const SHELL_SPLIT_POINT = 'SHELL_SPLIT_POINT';

  const data = {
    ENV,
    site: book.site,
    articles: book.articles,
    page: {
      path: '',
      private: true,
      content: SHELL_SPLIT_POINT,
    },
    layout: 'shell.html',
  };

  const html = nunjucks.render('shell.html', data);
  const processedHtml = processHtml(html);

  const [shellStart, shellEnd] = processedHtml.split(SHELL_SPLIT_POINT);

  await fs.outputFile(
      path.join(config.publicDir, 'shell-start.html'), shellStart);

  await fs.outputFile(
      path.join(config.publicDir, 'shell-end.html'), shellEnd);
};
github dereknex / vscode-openapi-viewer / render.js View on Github external
render(filename, text) {
        let content = "";
        let ext = path.extname(filename);
        if (ext == ".json") {
            content = JSON.parse(text);
        }else if (ext == ".yaml" || ext == ".yml") {
           content = jsyaml.safeLoad(text);
            // content = JSON.stringify(yaml);
        } else {
            return "";
        }
        let swaggerUIPath = this.context.extensionPath + "/swagger-ui";
        let destFile = this.context.extensionPath + "/swagger-ui/index.htm";
        try {
            nunjucks.configure(swaggerUIPath);
            let res = nunjucks.render("index.njk", {swaggerUIPath: swaggerUIPath, content: content});
            fs.writeFileSync(destFile, res);

            // Turn windows file paths into a URI path:
            destFile = destFile.replace(/\\/g, "/");
            if (destFile[0] !== "/") {
                destFile = "/" + destFile;
            }

            return vscode.Uri.parse('file://' + destFile);
        } catch (error) {
            console.error(error);
        }
        return "";
       
    }
}
github lore / lore / packages / lore-generate / src / fileWriters / TemplateFileWriter.js View on Github external
write: function(source, target, options) {
    // console.log(source);
    // console.log(options);

    var dirname = path.dirname(source);
    var basename = path.basename(source);

    nunjucks.configure(dirname);

    var data = nunjucks.render(basename, _.merge({}, options, {
      _: _
    }));

    return writeFile(target, data, options);
  }
github blogist / blogist / config / crawl.js View on Github external
res.on('end',function(){

			var url= "{{homepage}}/gist/" + gist.id + "/" + postfix; // link to the item
			var gistjson = _(JSON.parse(data)).extend(JSON.parse(settings.toString()));
			var html = nunjucks.render("src/templates/crawl.html", {data:gistjson});
			saveSnapshot(url, html);
			if(idx+1 === arr.length){
				console.log("DONE");
			}else{
				console.log("crawl",idx);
				crawlPage(idx+1, arr);							
			}

		});
	}).on('error', function(e) {
github philipwalton / responsive-components / tasks / templates.js View on Github external
gulp.task('templates', async () => {
  try {
    const html = nunjucks.render('index.html', {
      NODE_ENV: process.env.NODE_ENV,
    });
    await fs.outputFile(
        path.join(config.publicDir, 'index.html'), processHtml(html));
  } catch (err) {
    console.error(err);
  }
});
github supermedium / superframe / site / generate.js View on Github external
glob.sync('components/*/examples/*/*.html').forEach(function (htmlPath) {
  var html = fs.readFileSync(htmlPath, 'utf-8');
  var githubCorner = nunjucks.render('github-corner-scene.html', {
    github: GITHUB + htmlPath.replace(/index.html$/, '')
  });
  html = html.replace(/<\/a-scene>((.|[\r\n])*)/, '');
  html = html.replace(/  <\/body>/, '\n' + githubCorner + '  ');
  fs.writeFileSync(htmlPath, html);
});
github whxaxes / mus / benchmark / renderNested.js View on Github external
.add('Nunjucks#renderNested', function() {
    nunjucks.render('test6.tpl', obj);
  })
  .add('Swig#renderNested', function() {
github maxlapides / dovetailer / lib / nunjucks.js View on Github external
return new Promise((resolve, reject) => {
      nunjucks.render(tplPath, context, (err, res) => {
        if (err) reject(err)
        else resolve(res)
      })
    })
  }
github senshu / Sozi / Gruntfile.js View on Github external
grunt.registerMultiTask("nunjucks_render", function () {
        for (let file of this.files) {
            grunt.file.write(file.dest, nunjucks.render(file.src[0], this.data.context));
            grunt.log.writeln("File " + file.dest + " created.");
        }
    });
github corygibbons / component-image / src / lib / renderTemplate.js View on Github external
module.exports = async function(component, stylesheet, renderer) {
  const template = nunjucks.render(tplOpts.view, {
    component: await renderComponent(component, renderer),
    styles: await parseStyleSheet(stylesheet),
  });

  return template;
};