Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Fs.readFile(file, 'utf8', (err, data) => {
if(err) return callback(err);
try {
// Compile it
let compiled = Dust.compile(data);
// Cache it
if(useCache) {
templateCache[file] = compiled;
}
callback(null, Dust.loadSource(compiled));
} catch(err) {
// Show a friendlier error for rendering issues
let relativePath = Path.relative(__basedir, file);
return callback(
new Error('Template Error: ' + err.message + ' in ' + relativePath)
);
}
});
}
reader(name, utils.nameify(name), context, function (err, src) {
if (err) {
chunk.setError(err);
return;
}
// It's not a string, so we need to load and compile
// before we can evaluate
if (typeof src !== 'function') {
src = dust.loadSource(dust.compile(src, name));
}
if (!config.cache) {
delete self[name];
}
src(chunk, context).end();
active -= 1;
});
}
fs.readFile(filePath, 'utf8', function (rErr, code) {
if (rErr) {
triggerError(rErr.message);
return false;
}
var jst;
try {
jst = dust.compile(code, path.basename(filePath, '.dust'));
} catch (e) {
triggerError(e.message);
return false;
}
//write jst code into output
fs.writeFile(output, jst, 'utf8', function (wErr) {
if (wErr) {
triggerError(wErr.message);
} else {
emitter.emit('done');
emitter.emit('always');
}
});
});
};
this.wrapper = function(before, after) {
before = before || '';
after = after || '';
wrappperTplIndex = dust.loadSource(dust.compile((before + '{>"{module.setting.template.index}" /}' + after), 'wrapper-index'));
wrappperTplLoading = dust.loadSource(dust.compile((before + '{>"{module.setting.template.loading}" /}' + after), 'wrapper-loading'));
return self;
};
this.getWrappedIndexTplName = function() {
.then(([content]) => dust.compile(content, 'index'))
.then(dust.loadSource)
partials.forEach(function(v, i) {
var contents = grunt.file.read(v);
var name = path.basename(v, path.extname(v));
if(me.options.templateEngine === 'handlebars') {
Handlebars.registerPartial(name, contents);
} else if(me.options.templateEngine === 'dust') {
var templateName = name;
var source = dust.compile(contents, templateName);
dust.loadSource(source);
}
});
}
'template': function(key, value, localeCode, dictionary, dictionaryName, writer) {
if (Array.isArray(value)) {
value = value.join('');
}
var dust = require('dustjs-linkedin'),
templateName = dictionaryName + '_' + localeCode + '.' + key;
require('dustjs-helpers');
try {
writer.write(dust.compile(value, templateName));
} catch(e) {
logger.error('Error compiling template "' + templateName + '". Template: ' + JSON.stringify(value), e);
}
logger.info('Compiled Dust template "' + templateName + '".');
dictionary[key] = {
type: 'dust',
templateName: templateName
};
}
};
dust.onLoad = (templateName, opts, callback) => {
var name
if (opts && opts.host && templateName.indexOf(opts.host) === -1 && this.templates[opts.host + templateName]) {
name = opts.host + templateName
} else {
name = templateName
}
if (!this.templates[name]) {
return callback({message: 'Template not found: ' + name}, null)
}
var compiled = dust.compile(this.templates[name])
var tmpl = dust.loadSource(compiled)
return callback(null, tmpl)
}
}
fs.readFile(templatePath, function (err, file) {
if (err) {
logger.error('Failed to read notification template %s - sending to dead letter.', templatePath);
q.notificationQueue.deadLetter(n);
return;
}
q.notificationTemplates[tname] = dust.compile(file.toString(), tname);
dust.loadSource(q.notificationTemplates[tname], tname);
fn();
});
}