Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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);
};
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 "";
}
}
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);
}
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) {
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);
}
});
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);
});
.add('Nunjucks#renderNested', function() {
nunjucks.render('test6.tpl', obj);
})
.add('Swig#renderNested', function() {
return new Promise((resolve, reject) => {
nunjucks.render(tplPath, context, (err, res) => {
if (err) reject(err)
else resolve(res)
})
})
}
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.");
}
});
module.exports = async function(component, stylesheet, renderer) {
const template = nunjucks.render(tplOpts.view, {
component: await renderComponent(component, renderer),
styles: await parseStyleSheet(stylesheet),
});
return template;
};