Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fs = require('fs'),
path = require('path'),
express = require('express'),
request = require('request'),
dust = require('dustjs-linkedin');
dust.config.whitespace = true;
dust.config.cache = false;
// Define a custom `onLoad` function to tell Dust how to load templates
dust.onLoad = function(tmpl, cb) {
fs.readFile(path.join('./views', path.relative('/', path.resolve('/', tmpl + '.dust'))),
{ encoding: 'utf8' }, cb);
};
var app = express();
app.get('/', function (req, res) {
dust.stream("hello", {
"async": request('http://www.dustjs.com/')
}).pipe(res);
});
app.listen(3000, function () {
console.log('Visit http://localhost:3000 to see streaming!');
});
var fs = require('fs'),
path = require('path'),
express = require('express'),
dust = require('dustjs-linkedin'),
q = require('q');
// Define a custom `onLoad` function to tell Dust how to load templates
dust.onLoad = function(tmpl, cb) {
fs.readFile(path.join('./views', path.relative('/', path.resolve('/', tmpl + '.dust'))),
{ encoding: 'utf8' }, cb);
};
var app = express();
var position;
var context = {
wait: function(chunk, context, bodies, params) {
var delayMilliseconds = parseInt(params.delay, 10) * 1000;
// Returning a Promise-- Dust will wait for the promise to resolve
var promise = q(position++).delay(delayMilliseconds);
promise.then(function(position) {
console.log('Rendering', params.name, 'which started in position', position);
});
return promise;
*/
dust.isThenable = function(elem) {
return elem &&
typeof elem === 'object' &&
typeof elem.then === 'function' && !elem.objectType;
};
/**
* Override Dust's onLoad() function so that templates are loaded from the store.
* The cache key is also determined to include the appId.
*
* @param templatePath
* @param options
* @param callback
*/
var loadTemplate = dust.onLoad = function(templatePath, options, callback)
{
//var log = options.log;
// `templateName` is the name of the template requested by dust.render / dust.stream
// or via a partial include, like {> "hello-world" /}
// `options` can be set as part of a Context. They will be explored later
// `callback` is a Node-like callback that takes (err, data)
var store = options.store;
store.existsFile(templatePath, function(exists) {
if (!exists) {
return callback({
"message": "Dust cannot find file: " + templatePath
});
}
};
function load(name) {
return xhr.basedGet('dust/' + name + '.js')
.then(template => {
// need to do that so we don't have to expose dust compile
/*jslint evil: true */
let loadTemplate = new Function('dust', template); //eslint-disable-line no-new-func
/*jslint evil: false */
loadTemplate(engine);
return template;
});
}
engine.onLoad = function () {
let templateName = arguments[0],
callback;
if (arguments.length > 2) {
/* istanbul ignore next */
callback = arguments[2];
} else {
callback = arguments[1];
}
return load(templateName).then((template) => {
if (!template) {
return callback(new Error('Template ' + templateName + ' not found'));
}
callback(null, template);
}, (error) => {
}
}
// Found, return the successful candidate
return callback(null, candidate);
});
}
// Disable Dust.js caching so we can handle it ourselves
Dust.config.cache = false;
// Enable whitespace for more readable outputs
Dust.config.whitespace = true;
// Locate the requested template
Dust.onLoad = (name, options, callback) => {
let file;
// Absolute path
if(Path.isAbsolute(name)) {
file = name;
// Try cache first
if(templateCache[file]) {
try {
return callback(null, Dust.loadSource(templateCache[file]));
} catch(err) {
return callback(err);
}
}
// Load and compile template
const Dust = function () {
this.templates = {}
// Loading core Dust helpers
require('dustjs-helpers')
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)
}
function requireTemplate(name, callback) {
var tmpl;
try {
tmpl = require(root(name))(dust);
} catch(e) {
if (callback) { callback(e); } else { throw e; }
}
if (callback) {
callback(null, tmpl);
} else {
return tmpl;
}
}
// Adding an `onLoad` function lets us load partials
module.exports = dust.onLoad = requireTemplate;
'use strict';
var chai = require('chai');
chai.Assertion.includeStack = true;
require('chai').should();
var expect = require('chai').expect;
var nodePath = require('path');
var fs = require('fs');
var dust = require('dustjs-linkedin');
dust.onLoad = function(path, callback) {
if (!fs.existsSync(path)) {
if (!path.endsWith('.dust')) {
path += '.dust';
}
}
fs.readFile(path, 'utf-8', callback);
};
require('marko-async/dust').registerHelpers(dust);
function testRender(path, data, done, options) {
options = options || {};
var inputPath = nodePath.join(__dirname, path);
after(function () {
dustjs.onLoad = undefined;
});
beforeEach(function(done) {
var dust = require('dustjs-linkedin');
dust.onLoad = function(path, callback) {
if (!fs.existsSync(path)) {
if (!path.endsWith('.dust')) {
path += '.dust';
}
}
fs.readFile(path, 'utf-8', callback);
};
require('../dust').registerHelpers(dust);
require('../').configure({
fileWriter: {
outputDir: nodePath.join(__dirname, 'build'),
urlPrefix: '/static',