Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function renderJade(viewFiles, viewModel, callback) {
var jadeFile = viewFiles[0];
if (viewFiles.length > 1) {
console.warn('TEMPLATES: More than one possible Jade view file found, will take main or index.');
jadeFile = _.find(viewFiles, function (file) {
return Path.basename(file, Path.extname(file)) === 'main' || Path.basename(file, Path.extname(file)) === 'index';
});
}
if (jadeFile) {
// Handle exports.
viewModel.basedir = Path.join(__dirname, '../templates/jade/');
Consolidate.jade(jadeFile, viewModel, function (err, html) {
if (!err) {
callback && callback(html);
}
else {
console.error('TEMPLATES: Error generating view from Jade file ' + jadeFile, err);
callback && callback();
}
});
}
else {
console.warn('TEMPLATES: Could not find appropriate main Jade view file, please rename your main template to main.jade or index.jade.');
callback && callback();
}
}
path.exists(process.cwd()+"/template"+chemical.page+".jade", function(found){
if(found)
cons.jade(process.cwd()+"/template"+chemical.page+".jade", chemical.data || {}, self.render(chemical));
else
cons.jade(process.cwd()+"/template/404.jade", chemical.data || {}, self.render(chemical));
});
});