Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
STATE = state.create(config, reader, dust.load = function cabbage(name, chunk, context) {
var view, notCached, views;
active += 1;
view = name;
notCached = !dust.cache[name];
views = utils.resolveViewDir(context.global, MY_SPECIAL_FRIEND);
if (notCached && views !== MY_SPECIAL_FRIEND) {
// We exploit the cache to hook into load/onLoad behavior. Dust first checks the cache before
// trying to load (using dust.cache[name]), so if we add a custom getter for a known key we can
// get dust to call our code and replace its behavior without changing its internals.
view = MY_SPECIAL_FRIEND;
Object.defineProperty(dust.cache, view, {
configurable: true,
get: function () {
var self = this;
// Remove the getter immediately (must delete as it's a
// getter. setting it to undefined will fail.)
res.__dynamicHelpers = {};
for (var key in dynamicHelpers) {
res.__dynamicHelpers[key] = dynamicHelpers[key].call(
res.app,
res.req,
res);
}
}
baseContext = baseContext.push(res.__dynamicHelpers);
}
// TODO: Figure out a good way to catch parser errors. Currently Dust's
// parser just throws them instead of passing them to the callback.
// See https://github.com/akdubya/dustjs/issues#issue/12
if (res.app.settings.env === 'development') {
dust.cache = {}; // Reflect template changes without a restart.
getView(view, function (err, content) {
if (err) { res.req.next(err); return; }
dust.renderSource(content, options, callback);
});
} else {
dust.render(view, options, callback);
}
};
STATE = state.create(config, reader, dust.load = function cabbage(name, chunk, context) {
var view, notCached, views;
active += 1;
view = name;
notCached = !dust.cache[name];
views = utils.resolveViewDir(context.global, MY_SPECIAL_FRIEND);
if (notCached && views !== MY_SPECIAL_FRIEND) {
// We exploit the cache to hook into load/onLoad behavior. Dust first checks the cache before
// trying to load (using dust.cache[name]), so if we add a custom getter for a known key we can
// get dust to call our code and replace its behavior without changing its internals.
view = MY_SPECIAL_FRIEND;
Object.defineProperty(dust.cache, view, {
configurable: true,
get: function () {
var self = this;
// Remove the getter immediately (must delete as it's a
// getter. setting it to undefined will fail.)
delete this[view];
return function (chunks, context) {
function onChunk(chunk) {
reader(name, utils.nameify(name), context, function (err, src) {
if (err) {
chunk.setError(err);
return;
afterEach(function () {
dustjs.cache = {};
});
this.load = function loadCodeTemplate(templatePath, done) {
var fs = require('fs');
if (dust.cache.hasOwnProperty(templatePath)) {
return done(getDustTemplate(templatePath));
}
fs.readFile(templatePath, function readTemplate(err, template) {
dust.register(
templatePath,
dust.loadSource(dust.compile(template.toString(), templatePath))
);
done(getDustTemplate(templatePath));
});
};
};
Dust.prototype.clearCache = function () {
dust.cache = {}
}