Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should return json when calling `render()`", function(done) {
var name = "test"
var schema = TestHelper.getPageSchema()
schema.template = "test.dust"
// load a template
var template = "{#names}{title} {name}{~n}{/names}"
var compiled = dust.compile(template, "test", true)
dust.loadSource(compiled)
var req = { url: "/test" }
var p = page(name, schema)
var v = view(req.url, p, true)
var data = {
title: "Sir",
names: [{ name: "Moe" }, { name: "Larry" }, { name: "Curly" }]
}
v.setData(data)
v.render(function(err, result) {
result.should.eql(data)
done()
})
}, function(err, text) {
if (err) {
return callback(err);
}
// compile and store into dust.cache
try {
//console.log("WRITE TO TEMPLATE CACHE: " + templatePath);
template = dust.loadSource(dust.compile(text));
TEMPLATE_CACHE[templateCacheKey] = template;
} catch (e) {
delete TEMPLATE_CACHE[templateCacheKey];
return callback(e);
}
// proceed
executeTemplate(template, templatePath, context, callback);
});
};
locateFile(file, options.viewFolders, (err, file) => {
if(err) return callback(err);
// Try cache first
if(templateCache[file]) {
try {
return callback(null, Dust.loadSource(templateCache[file]));
} catch(err) {
return callback(err);
}
}
// Load and compile template
compileTemplate(file, callback);
});
}
bundle.formatDust = function (pattern, model, renderCb) {
if (!this.cache[pattern]) {
this.cache[pattern] = dust.loadSource(dust.compile(this.get(pattern)));
}
dust.render(this.cache[pattern], model, renderCb);
};
return bundle;
this.log( 'Views folder is not found. Skip loading views', 'warning' );
}
if ( stats && stats.isDirectory() ) fs.readdirSync( full_view_path ).forEach( function( file ) {
this.load_views( path.join( view_path, file ) );
}, this );
else if ( stats && stats.isFile() && this._views_mtime[ view_path ] != stats.mtime.getTime() ) {
this.log( 'Load view `%s`'.format( view_path ), 'trace' );
var template = fs.readFileSync( full_view_path, 'utf8' );
var compiled = dust.compile( template, view_path );
this._views_mtime[ view_path ] = stats.mtime.getTime();
dust.loadSource( compiled );
}
if ( !view_path ) {
this.views_loaded = true;
if ( stats ) this.log( 'Views are loaded', 'info' );
this.emit( 'views_are_loaded' );
}
};
dust.helpers.t = function localizationDustHelper(chunk, context, bodies) {
var renderer = chunk.root['decent-renderer'];
var scope = renderer.scope;
var t = scope.require('localization') || function(s) {return s;};
var body = dust.helpers.tap(bodies.block, chunk, context);
var localizedBody = t(body);
var reTokenized = localizedBody.replace(/\[([^\]]+)]/g, '{$1}');
dust.loadSource(dust.compile(reTokenized, reTokenized));
return chunk.map(function renderLocalizedString(chunk) {
dust.render(reTokenized, context, function(err, rendered) {
chunk.end(rendered);
});
});
};
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);
}
});
}
function(file) {
if (file.isDirectory() || file.getAbsolutePath() === scaffoldDir.getAbsolutePath()) {
return;
}
if (file.getName() === '.DS_Store') {
return;
}
var inputTemplate = file.readAsString();
var templateName = file.getName();
var compiled = dust.compile(inputTemplate, templateName, false);
dust.loadSource(compiled);
var outputPath = file.getAbsolutePath().slice(scaffoldDir.getAbsolutePath().length + 1);
if (outputPath.endsWith('.dust')) {
outputPath = outputPath.slice(0, 0-'.dust'.length);
}
var skip = false;
var outputFile = new File(
path.join(
outputDir,
outputPath.replace(/_([a-zA-Z0-9]+)_/g, function(match, varName) {
var replacement = viewModel[varName];
if (replacement === false) {
skip = true;
return '';
DarkTip.setting = function(key, data) {
var tplNames = [];
if (typeof data === 'undefined') {
return settingsContext.get(key);
}
tplNames = key.match(/^module\.template\.([^\.].*)$/);
if (tplNames && tplNames.length)
{
data = dust.loadSource(dust.compile(data, tplNames[1]));
}
settingsContext.set(key, data);
return this;
};
fs.readFile(templatePath, function readTemplate(err, template) {
dust.register(
templatePath,
dust.loadSource(dust.compile(template.toString(), templatePath))
);
done(getDustTemplate(templatePath));
});
};