How to use the Environment function from nunjucks
Find comprehensive JavaScript nunjucks.Environment code examples handpicked from public code repositorys.
0 1 2 3 4 5 6 7 8 9 10
const nunjucks = require('nunjucks') const fs = require('fs') let filenames = ['body-ch', 'body-en'] filenames.forEach(filename => { let env = new nunjucks.Environment(); let precompiledBody = nunjucks.precompile(filename + '.njk', { env: env }) fs.writeFile((filename + ".js"), precompiledBody, () => {
2
13
0
7 8 9 10 11 12 13 14 15 16 17
const nunjucks = require('nunjucks'); const postcssPresetEnv = require('postcss-preset-env'); const highlight = require('highlight.js'); const prettier = require('prettier'); const nunjucksEnvironment = new nunjucks.Environment( new nunjucks.FileSystemLoader(path.resolve(__dirname, 'src', 'docs')), { throwOnUndefined : true, },
3
3
1
+ 4 other calls in file
GitHub: nihruk/design-system
12 13 14 15 16 17 18 19 20 21 22
.filter(x => x) .join('/') } function createEnvironment() { const environment = new nunjucks.Environment( new nunjucks.FileSystemLoader( path.resolve(__dirname, '..'), { throwOnUndefined: true,
3
3
2
+ 3 other calls in file
GitHub: tcurdt/xstatic
54 55 56 57 58 59 60 61 62 63
cb(`Failed to load layout $(path}`) }) } } const env = new Nunjucks.Environment(loader, options.compile) const template = Nunjucks.compile(doc.body.data.toString(), env, doc.file.path) return Promise.resolve(template) } }
2
2
0
GitHub: dimaslanjaka/page
373 374 375 376 377 378 379 380 381 382
* Env Nunjucks * @param {import('express').Express} app * @returns */ function envNunjucks(app) { const env = new nunjucks.Environment([new nunjucks.FileSystemLoader(__dirname)]); if (typeof app === 'object') { try { nunjucks.configure(__dirname, { autoescape: true,
0
2
0
24 25 26 27 28 29 30 31 32 33
return null; }, async load(id) { const env = typeof envFn === "function" ? await envFn(new Environment()) : envFn; if (id.endsWith(".nunjucks.precompiled.js")) { // Generate the precompiled template module based on the ID const templatePath = id.slice(0, -".nunjucks.precompiled.js".length);
0
1
0
3 4 5 6 7 8 9 10 11 12
var autoescape = opts.autoescape === undefined ? true : opts.autoescape, noCache = opts.noCache || false, watch = opts.watch || false, throwOnUndefined = opts.throwOnUndefined || false, env = new nunjucks.Environment( new nunjucks.FileSystemLoader(path || 'views', { noCache: noCache, watch: watch, }), {
0
0
2
+ 3 other calls in file
160 161 162 163 164 165 166 167 168 169
} delete require.cache[require.resolve(path.normalize(`${baseDataLocal}/global.PROD.js`))]; const dataGlobal = await GetData(`global.${ENV}`, baseDataLocal, baseDataRemote, baseDataRemoteCache); const nunjucksEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(dir.src)); nunjucksEnv.addExtension('ComponentExtension', new ComponentExtension(nunjucks, nunjucksEnv)); const gulpData = async (file) => { if (typeof file.data !== 'undefined') return file.data;
0
0
1
GitHub: mik-sea/web-gereja
14 15 16 17 18 19 20 21 22 23
return; } const context = Object.assign({}, data, file.data); const filePath = file.path; const env = options.env || new nunjucks.Environment(new nunjucks.FileSystemLoader(file.base), options); if (options.filters && !options.env) { for (const key of Object.keys(options.filters)) { env.addFilter(key, options.filters[key]);
0
0
0
GitHub: c-calvin/tanghexinbl
4 5 6 7 8 9 10 11 12 13 14
const nunjucks = require('nunjucks'); const { inherits } = require('util'); const Promise = require('bluebird'); function Tag() { this.env = new nunjucks.Environment(null, { autoescape: false }); }
0
0
0
+ 2 other calls in file
13 14 15 16 17 18 19 20 21 22
} setLibrary(env) { this.njkEnv = env || new NunjucksLib.Environment( new NunjucksLib.FileSystemLoader([ super.getIncludesDir(), TemplatePath.getWorkingDir() ])
0
0
0
+ 2 other calls in file
GitHub: kejcao/home
56 57 58 59 60 61 62 63 64 65 66
}).code} </script>`); }; } let env = new nunjucks.Environment(new nunjucks.FileSystemLoader()); env.addExtension('StyleExtension', new StyleExtension()); env.addExtension('ScriptExtension', new ScriptExtension()); env.addFilter('raw', str => { return env.renderString(str, this.ctx);
0
0
0
+ 2 other calls in file
178 179 180 181 182 183 184 185 186 187 188
return e; }; class Tag { constructor() { this.env = new Environment(null, { autoescape: false }); }
0
0
0
nunjucks.configure is the most popular function in nunjucks (144 examples)