dustjs-linkedin
Advanced tools
Comparing version 2.2.4 to 2.3.0
@@ -1,367 +0,417 @@ | ||
var dustCompiler = (function(dust) { | ||
/*jshint latedef:false */ | ||
(function(root, factory) { | ||
if (typeof exports === 'object') { | ||
// in Node, require this file if we want to use the compiler as a standalone module | ||
module.exports = factory(require('./parser').parse, require('./dust')); | ||
} else { | ||
// in the browser, store the factory output if we want to use the compiler directly | ||
factory(root.dust.parse, root.dust); | ||
} | ||
}(this, function(parse, dust) { | ||
var compiler = {}, | ||
isArray = dust.isArray; | ||
dust.compile = function(source, name) { | ||
try { | ||
var ast = filterAST(dust.parse(source)); | ||
return compile(ast, name); | ||
} | ||
catch (err) | ||
{ | ||
if (!err.line || !err.column) { | ||
throw err; | ||
compiler.compile = function(source, name) { | ||
// if compile is called from compileFn via renderSource, name parameter can be ignored, | ||
// as the templates will be rendered immediately and need not be stored in cache, but if | ||
// compile is called directly, the template will be cached with its name, so name is mandatory. | ||
// Only renderSource passes null as name | ||
if (!name && name !== null) { | ||
dust.log(new Error("Template name parameter cannot be undefined when calling dust.compile"), 'ERROR'); | ||
} | ||
throw new SyntaxError(err.message + " At line : " + err.line + ", column : " + err.column); | ||
try { | ||
var ast = filterAST(parse(source)); | ||
return compile(ast, name); | ||
} | ||
catch (err) | ||
{ | ||
if (!err.line || !err.column) { | ||
throw err; | ||
} | ||
throw new SyntaxError(err.message + ' At line : ' + err.line + ', column : ' + err.column); | ||
} | ||
}; | ||
function filterAST(ast) { | ||
var context = {}; | ||
return compiler.filterNode(context, ast); | ||
} | ||
}; | ||
function filterAST(ast) { | ||
var context = {}; | ||
return dust.filterNode(context, ast); | ||
}; | ||
compiler.filterNode = function(context, node) { | ||
return compiler.optimizers[node[0]](context, node); | ||
}; | ||
dust.filterNode = function(context, node) { | ||
return dust.optimizers[node[0]](context, node); | ||
}; | ||
compiler.optimizers = { | ||
body: compactBuffers, | ||
buffer: noop, | ||
special: convertSpecial, | ||
format: nullify, // TODO: convert format | ||
reference: visit, | ||
'#': visit, | ||
'?': visit, | ||
'^': visit, | ||
'<': visit, | ||
'+': visit, | ||
'@': visit, | ||
'%': visit, | ||
partial: visit, | ||
context: visit, | ||
params: visit, | ||
bodies: visit, | ||
param: visit, | ||
filters: noop, | ||
key: noop, | ||
path: noop, | ||
literal: noop, | ||
raw: noop, | ||
comment: nullify, | ||
line: nullify, | ||
col: nullify | ||
}; | ||
dust.optimizers = { | ||
body: compactBuffers, | ||
buffer: noop, | ||
special: convertSpecial, | ||
format: nullify, // TODO: convert format | ||
reference: visit, | ||
"#": visit, | ||
"?": visit, | ||
"^": visit, | ||
"<": visit, | ||
"+": visit, | ||
"@": visit, | ||
"%": visit, | ||
partial: visit, | ||
context: visit, | ||
params: visit, | ||
bodies: visit, | ||
param: visit, | ||
filters: noop, | ||
key: noop, | ||
path: noop, | ||
literal: noop, | ||
comment: nullify, | ||
line: nullify, | ||
col: nullify | ||
}; | ||
compiler.pragmas = { | ||
esc: function(compiler, context, bodies, params) { | ||
var old = compiler.auto, | ||
out; | ||
if (!context) { | ||
context = 'h'; | ||
} | ||
compiler.auto = (context === 's') ? '' : context; | ||
out = compileParts(compiler, bodies.block); | ||
compiler.auto = old; | ||
return out; | ||
} | ||
}; | ||
dust.pragmas = { | ||
esc: function(compiler, context, bodies, params) { | ||
var old = compiler.auto, | ||
out; | ||
if (!context) { | ||
context = 'h'; | ||
function visit(context, node) { | ||
var out = [node[0]], | ||
i, len, res; | ||
for (i=1, len=node.length; i<len; i++) { | ||
res = compiler.filterNode(context, node[i]); | ||
if (res) { | ||
out.push(res); | ||
} | ||
} | ||
compiler.auto = (context === 's') ? '' : context; | ||
out = compileParts(compiler, bodies.block); | ||
compiler.auto = old; | ||
return out; | ||
} | ||
}; | ||
function visit(context, node) { | ||
var out = [node[0]], | ||
i, len, res; | ||
for (i=1, len=node.length; i<len; i++) { | ||
res = dust.filterNode(context, node[i]); | ||
if (res) { | ||
out.push(res); | ||
} | ||
} | ||
return out; | ||
}; | ||
// Compacts consecutive buffer nodes into a single node | ||
function compactBuffers(context, node) { | ||
var out = [node[0]], | ||
memo, i, len, res; | ||
for (i=1, len=node.length; i<len; i++) { | ||
res = dust.filterNode(context, node[i]); | ||
if (res) { | ||
if (res[0] === 'buffer') { | ||
if (memo) { | ||
memo[1] += res[1]; | ||
// Compacts consecutive buffer nodes into a single node | ||
function compactBuffers(context, node) { | ||
var out = [node[0]], | ||
memo, i, len, res; | ||
for (i=1, len=node.length; i<len; i++) { | ||
res = compiler.filterNode(context, node[i]); | ||
if (res) { | ||
if (res[0] === 'buffer') { | ||
if (memo) { | ||
memo[1] += res[1]; | ||
} else { | ||
memo = res; | ||
out.push(res); | ||
} | ||
} else { | ||
memo = res; | ||
memo = null; | ||
out.push(res); | ||
} | ||
} else { | ||
memo = null; | ||
out.push(res); | ||
} | ||
} | ||
return out; | ||
} | ||
return out; | ||
}; | ||
var specialChars = { | ||
"s": " ", | ||
"n": "\n", | ||
"r": "\r", | ||
"lb": "{", | ||
"rb": "}" | ||
}; | ||
var specialChars = { | ||
's': ' ', | ||
'n': '\n', | ||
'r': '\r', | ||
'lb': '{', | ||
'rb': '}' | ||
}; | ||
function convertSpecial(context, node) { | ||
return ['buffer', specialChars[node[1]]] | ||
}; | ||
function convertSpecial(context, node) { | ||
return ['buffer', specialChars[node[1]]]; | ||
} | ||
function noop(context, node) { | ||
return node | ||
}; | ||
function noop(context, node) { | ||
return node; | ||
} | ||
function nullify(){}; | ||
function nullify(){} | ||
function compile(ast, name) { | ||
var context = { | ||
name: name, | ||
bodies: [], | ||
blocks: {}, | ||
index: 0, | ||
auto: "h" | ||
function compile(ast, name) { | ||
var context = { | ||
name: name, | ||
bodies: [], | ||
blocks: {}, | ||
index: 0, | ||
auto: 'h' | ||
}; | ||
return '(function(){dust.register(' + | ||
(name ? '"' + name + '"' : 'null') + ',' + | ||
compiler.compileNode(context, ast) + | ||
');' + | ||
compileBlocks(context) + | ||
compileBodies(context) + | ||
'return body_0;' + | ||
'})();'; | ||
} | ||
return "(function(){dust.register(" | ||
+ (name ? "\"" + name + "\"" : "null") + "," | ||
+ dust.compileNode(context, ast) | ||
+ ");" | ||
+ compileBlocks(context) | ||
+ compileBodies(context) | ||
+ "return body_0;" | ||
+ "})();"; | ||
}; | ||
function compileBlocks(context) { | ||
var out = [], | ||
blocks = context.blocks, | ||
name; | ||
function compileBlocks(context) { | ||
var out = [], | ||
blocks = context.blocks, | ||
name; | ||
for (name in blocks) { | ||
out.push("'" + name + "':" + blocks[name]); | ||
for (name in blocks) { | ||
out.push('"' + name + '":' + blocks[name]); | ||
} | ||
if (out.length) { | ||
context.blocks = 'ctx=ctx.shiftBlocks(blocks);'; | ||
return 'var blocks={' + out.join(',') + '};'; | ||
} | ||
return context.blocks = ''; | ||
} | ||
if (out.length) { | ||
context.blocks = "ctx=ctx.shiftBlocks(blocks);"; | ||
return "var blocks={" + out.join(',') + "};"; | ||
} | ||
return context.blocks = ""; | ||
}; | ||
function compileBodies(context) { | ||
var out = [], | ||
bodies = context.bodies, | ||
blx = context.blocks, | ||
i, len; | ||
function compileBodies(context) { | ||
var out = [], | ||
bodies = context.bodies, | ||
blx = context.blocks, | ||
i, len; | ||
for (i=0, len=bodies.length; i<len; i++) { | ||
out[i] = "function body_" + i + "(chk,ctx){" | ||
+ blx + "return chk" + bodies[i] + ";}"; | ||
for (i=0, len=bodies.length; i<len; i++) { | ||
out[i] = 'function body_' + i + '(chk,ctx){' + | ||
blx + 'return chk' + bodies[i] + ';}'; | ||
} | ||
return out.join(''); | ||
} | ||
return out.join(''); | ||
}; | ||
function compileParts(context, body) { | ||
var parts = '', | ||
i, len; | ||
for (i=1, len=body.length; i<len; i++) { | ||
parts += dust.compileNode(context, body[i]); | ||
function compileParts(context, body) { | ||
var parts = '', | ||
i, len; | ||
for (i=1, len=body.length; i<len; i++) { | ||
parts += compiler.compileNode(context, body[i]); | ||
} | ||
return parts; | ||
} | ||
return parts; | ||
}; | ||
dust.compileNode = function(context, node) { | ||
return dust.nodes[node[0]](context, node); | ||
}; | ||
compiler.compileNode = function(context, node) { | ||
return compiler.nodes[node[0]](context, node); | ||
}; | ||
dust.nodes = { | ||
body: function(context, node) { | ||
var id = context.index++, | ||
name = "body_" + id; | ||
context.bodies[id] = compileParts(context, node); | ||
return name; | ||
}, | ||
compiler.nodes = { | ||
body: function(context, node) { | ||
var id = context.index++, | ||
name = 'body_' + id; | ||
context.bodies[id] = compileParts(context, node); | ||
return name; | ||
}, | ||
buffer: function(context, node) { | ||
return ".write(" + escape(node[1]) + ")"; | ||
}, | ||
buffer: function(context, node) { | ||
return '.write(' + escape(node[1]) + ')'; | ||
}, | ||
format: function(context, node) { | ||
return ".write(" + escape(node[1] + node[2]) + ")"; | ||
}, | ||
format: function(context, node) { | ||
return '.write(' + escape(node[1] + node[2]) + ')'; | ||
}, | ||
reference: function(context, node) { | ||
return ".reference(" + dust.compileNode(context, node[1]) | ||
+ ",ctx," + dust.compileNode(context, node[2]) + ")"; | ||
}, | ||
reference: function(context, node) { | ||
return '.reference(' + compiler.compileNode(context, node[1]) + | ||
',ctx,' + compiler.compileNode(context, node[2]) + ')'; | ||
}, | ||
"#": function(context, node) { | ||
return compileSection(context, node, "section"); | ||
}, | ||
'#': function(context, node) { | ||
return compileSection(context, node, 'section'); | ||
}, | ||
"?": function(context, node) { | ||
return compileSection(context, node, "exists"); | ||
}, | ||
'?': function(context, node) { | ||
return compileSection(context, node, 'exists'); | ||
}, | ||
"^": function(context, node) { | ||
return compileSection(context, node, "notexists"); | ||
}, | ||
'^': function(context, node) { | ||
return compileSection(context, node, 'notexists'); | ||
}, | ||
"<": function(context, node) { | ||
var bodies = node[4]; | ||
for (var i=1, len=bodies.length; i<len; i++) { | ||
var param = bodies[i], | ||
type = param[1][1]; | ||
if (type === "block") { | ||
context.blocks[node[1].text] = dust.compileNode(context, param[2]); | ||
return ''; | ||
'<': function(context, node) { | ||
var bodies = node[4]; | ||
for (var i=1, len=bodies.length; i<len; i++) { | ||
var param = bodies[i], | ||
type = param[1][1]; | ||
if (type === 'block') { | ||
context.blocks[node[1].text] = compiler.compileNode(context, param[2]); | ||
return ''; | ||
} | ||
} | ||
} | ||
return ''; | ||
}, | ||
return ''; | ||
}, | ||
"+": function(context, node) { | ||
if(typeof(node[1].text) === "undefined" && typeof(node[4]) === "undefined"){ | ||
return ".block(ctx.getBlock(" | ||
+ dust.compileNode(context, node[1]) | ||
+ ",chk, ctx)," + dust.compileNode(context, node[2]) + ", {}," | ||
+ dust.compileNode(context, node[3]) | ||
+ ")"; | ||
}else { | ||
return ".block(ctx.getBlock(" | ||
+ escape(node[1].text) | ||
+ ")," + dust.compileNode(context, node[2]) + "," | ||
+ dust.compileNode(context, node[4]) + "," | ||
+ dust.compileNode(context, node[3]) | ||
+ ")"; | ||
} | ||
}, | ||
'+': function(context, node) { | ||
if (typeof(node[1].text) === 'undefined' && typeof(node[4]) === 'undefined'){ | ||
return '.block(ctx.getBlock(' + | ||
compiler.compileNode(context, node[1]) + | ||
',chk, ctx),' + compiler.compileNode(context, node[2]) + ', {},' + | ||
compiler.compileNode(context, node[3]) + | ||
')'; | ||
} else { | ||
return '.block(ctx.getBlock(' + | ||
escape(node[1].text) + | ||
'),' + compiler.compileNode(context, node[2]) + ',' + | ||
compiler.compileNode(context, node[4]) + ',' + | ||
compiler.compileNode(context, node[3]) + | ||
')'; | ||
} | ||
}, | ||
"@": function(context, node) { | ||
return ".helper(" | ||
+ escape(node[1].text) | ||
+ "," + dust.compileNode(context, node[2]) + "," | ||
+ dust.compileNode(context, node[4]) + "," | ||
+ dust.compileNode(context, node[3]) | ||
+ ")"; | ||
}, | ||
'@': function(context, node) { | ||
return '.helper(' + | ||
escape(node[1].text) + | ||
',' + compiler.compileNode(context, node[2]) + ',' + | ||
compiler.compileNode(context, node[4]) + ',' + | ||
compiler.compileNode(context, node[3]) + | ||
')'; | ||
}, | ||
"%": function(context, node) { | ||
// TODO: Move these hacks into pragma precompiler | ||
var name = node[1][1]; | ||
if (!dust.pragmas[name]) return ''; | ||
'%': function(context, node) { | ||
// TODO: Move these hacks into pragma precompiler | ||
var name = node[1][1], | ||
rawBodies, | ||
bodies, | ||
rawParams, | ||
params, | ||
ctx, b, p, i, len; | ||
if (!compiler.pragmas[name]) { | ||
return ''; | ||
} | ||
var rawBodies = node[4]; | ||
var bodies = {}; | ||
for (var i=1, len=rawBodies.length; i<len; i++) { | ||
var b = rawBodies[i]; | ||
bodies[b[1][1]] = b[2]; | ||
} | ||
rawBodies = node[4]; | ||
bodies = {}; | ||
for (i=1, len=rawBodies.length; i<len; i++) { | ||
b = rawBodies[i]; | ||
bodies[b[1][1]] = b[2]; | ||
} | ||
var rawParams = node[3]; | ||
var params = {}; | ||
for (var i=1, len=rawParams.length; i<len; i++) { | ||
var p = rawParams[i]; | ||
params[p[1][1]] = p[2][1]; | ||
} | ||
rawParams = node[3]; | ||
params = {}; | ||
for (i=1, len=rawParams.length; i<len; i++) { | ||
p = rawParams[i]; | ||
params[p[1][1]] = p[2][1]; | ||
} | ||
var ctx = node[2][1] ? node[2][1].text : null; | ||
ctx = node[2][1] ? node[2][1].text : null; | ||
return dust.pragmas[name](context, ctx, bodies, params); | ||
}, | ||
return compiler.pragmas[name](context, ctx, bodies, params); | ||
}, | ||
partial: function(context, node) { | ||
return ".partial(" | ||
+ dust.compileNode(context, node[1]) | ||
+ "," + dust.compileNode(context, node[2]) | ||
+ "," + dust.compileNode(context, node[3]) + ")"; | ||
}, | ||
partial: function(context, node) { | ||
return '.partial(' + | ||
compiler.compileNode(context, node[1]) + | ||
',' + compiler.compileNode(context, node[2]) + | ||
',' + compiler.compileNode(context, node[3]) + ')'; | ||
}, | ||
context: function(context, node) { | ||
if (node[1]) { | ||
return "ctx.rebase(" + dust.compileNode(context, node[1]) + ")"; | ||
} | ||
return "ctx"; | ||
}, | ||
context: function(context, node) { | ||
if (node[1]) { | ||
return 'ctx.rebase(' + compiler.compileNode(context, node[1]) + ')'; | ||
} | ||
return 'ctx'; | ||
}, | ||
params: function(context, node) { | ||
var out = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
out.push(dust.compileNode(context, node[i])); | ||
} | ||
if (out.length) { | ||
return "{" + out.join(',') + "}"; | ||
} | ||
return "null"; | ||
}, | ||
params: function(context, node) { | ||
var out = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
out.push(compiler.compileNode(context, node[i])); | ||
} | ||
if (out.length) { | ||
return '{' + out.join(',') + '}'; | ||
} | ||
return 'null'; | ||
}, | ||
bodies: function(context, node) { | ||
var out = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
out.push(dust.compileNode(context, node[i])); | ||
} | ||
return "{" + out.join(',') + "}"; | ||
}, | ||
bodies: function(context, node) { | ||
var out = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
out.push(compiler.compileNode(context, node[i])); | ||
} | ||
return '{' + out.join(',') + '}'; | ||
}, | ||
param: function(context, node) { | ||
return dust.compileNode(context, node[1]) + ":" + dust.compileNode(context, node[2]); | ||
}, | ||
param: function(context, node) { | ||
return compiler.compileNode(context, node[1]) + ':' + compiler.compileNode(context, node[2]); | ||
}, | ||
filters: function(context, node) { | ||
var list = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
var filter = node[i]; | ||
list.push("\"" + filter + "\""); | ||
} | ||
return "\"" + context.auto + "\"" | ||
+ (list.length ? ",[" + list.join(',') + "]" : ''); | ||
}, | ||
filters: function(context, node) { | ||
var list = []; | ||
for (var i=1, len=node.length; i<len; i++) { | ||
var filter = node[i]; | ||
list.push('"' + filter + '"'); | ||
} | ||
return '"' + context.auto + '"' + | ||
(list.length ? ',[' + list.join(',') + ']' : ''); | ||
}, | ||
key: function(context, node) { | ||
return "ctx._get(false, [\"" + node[1] + "\"])"; | ||
}, | ||
key: function(context, node) { | ||
return 'ctx._get(false, ["' + node[1] + '"])'; | ||
}, | ||
path: function(context, node) { | ||
var current = node[1], | ||
keys = node[2], | ||
list = []; | ||
path: function(context, node) { | ||
var current = node[1], | ||
keys = node[2], | ||
list = []; | ||
for (var i=0,len=keys.length; i<len; i++) { | ||
if (dust.isArray(keys[i])) | ||
list.push(dust.compileNode(context, keys[i])); | ||
else | ||
list.push("\"" + keys[i] + "\""); | ||
for (var i=0,len=keys.length; i<len; i++) { | ||
if (isArray(keys[i])) { | ||
list.push(compiler.compileNode(context, keys[i])); | ||
} else { | ||
list.push('"' + keys[i] + '"'); | ||
} | ||
} | ||
return 'ctx._get(' + current + ',[' + list.join(',') + '])'; | ||
}, | ||
literal: function(context, node) { | ||
return escape(node[1]); | ||
}, | ||
raw: function(context, node) { | ||
return ".write(" + escape(node[1]) + ")"; | ||
} | ||
return "ctx._get(" + current + ",[" + list.join(',') + "])"; | ||
}, | ||
}; | ||
literal: function(context, node) { | ||
return escape(node[1]); | ||
function compileSection(context, node, cmd) { | ||
return '.' + cmd + '(' + | ||
compiler.compileNode(context, node[1]) + | ||
',' + compiler.compileNode(context, node[2]) + ',' + | ||
compiler.compileNode(context, node[4]) + ',' + | ||
compiler.compileNode(context, node[3]) + | ||
')'; | ||
} | ||
}; | ||
function compileSection(context, node, cmd) { | ||
return "." + cmd + "(" | ||
+ dust.compileNode(context, node[1]) | ||
+ "," + dust.compileNode(context, node[2]) + "," | ||
+ dust.compileNode(context, node[4]) + "," | ||
+ dust.compileNode(context, node[3]) | ||
+ ")"; | ||
}; | ||
var BS = /\\/g, | ||
DQ = /"/g, | ||
LF = /\f/g, | ||
NL = /\n/g, | ||
CR = /\r/g, | ||
TB = /\t/g; | ||
function escapeToJsSafeString(str) { | ||
return str.replace(BS, '\\\\') | ||
.replace(DQ, '\\"') | ||
.replace(LF, '\\f') | ||
.replace(NL, '\\n') | ||
.replace(CR, '\\r') | ||
.replace(TB, '\\t'); | ||
} | ||
var escape = (typeof JSON === "undefined") | ||
? function(str) { return "\"" + dust.escapeJs(str) + "\"" } | ||
: JSON.stringify; | ||
var escape = (typeof JSON === 'undefined') ? | ||
function(str) { return '"' + escapeToJsSafeString(str) + '"';} : | ||
JSON.stringify; | ||
return dust; | ||
// expose compiler methods | ||
dust.compile = compiler.compile; | ||
dust.filterNode = compiler.filterNode; | ||
dust.optimizers = compiler.optimizers; | ||
dust.pragmas = compiler.pragmas; | ||
dust.compileNode = compiler.compileNode; | ||
dust.nodes = compiler.nodes; | ||
return compiler; | ||
}); | ||
})); | ||
if (typeof exports !== 'undefined') { | ||
module.exports = dustCompiler; | ||
} else { | ||
dustCompiler(getGlobal()); | ||
} |
@@ -1,16 +0,5 @@ | ||
/*global console */ | ||
var dust = {}; | ||
function getGlobal(){ | ||
return (function(){ | ||
return this.dust; | ||
}).call(null); | ||
} | ||
(function(dust) { | ||
if(!dust) { | ||
return; | ||
} | ||
var NONE = 'NONE', | ||
/*jshint evil:true*/ | ||
(function(root) { | ||
var dust = {}, | ||
NONE = 'NONE', | ||
ERROR = 'ERROR', | ||
@@ -21,3 +10,5 @@ WARN = 'WARN', | ||
loggingLevels = [DEBUG, INFO, WARN, ERROR, NONE], | ||
logger = function() {}; | ||
EMPTY_FUNC = function() {}, | ||
logger = EMPTY_FUNC, | ||
loggerContext = this; | ||
@@ -27,7 +18,6 @@ dust.debugLevel = NONE; | ||
// Try to find the console logger in window scope (browsers) or top level scope (node.js) | ||
if (typeof window !== 'undefined' && window && window.console && window.console.log) { | ||
logger = window.console.log; | ||
} else if (typeof console !== 'undefined' && console && console.log) { | ||
logger = console.log; | ||
// Try to find the console logger in global scope | ||
if (root && root.console && root.console.log) { | ||
logger = root.console.log; | ||
loggerContext = root.console; | ||
} | ||
@@ -43,5 +33,4 @@ | ||
dust.log = function(message, type) { | ||
// dust.isDebug is deprecated, so this conditional will default the debugLevel to INFO if it's set to maintain backcompat. | ||
if (dust.isDebug && dust.debugLevel === NONE) { | ||
logger.call(console || window.console, '[!!!DEPRECATION WARNING!!!]: dust.isDebug is deprecated. Set dust.debugLevel instead to the level of logging you want ["debug","info","warn","error","none"]'); | ||
if(dust.isDebug && dust.debugLevel === NONE) { | ||
logger.call(loggerContext, '[!!!DEPRECATION WARNING!!!]: dust.isDebug is deprecated. Set dust.debugLevel instead to the level of logging you want ["debug","info","warn","error","none"]'); | ||
dust.debugLevel = INFO; | ||
@@ -56,3 +45,3 @@ } | ||
dust.logQueue.push({message: message, type: type}); | ||
logger.call(console || window.console, "[DUST " + type + "]: " + message); | ||
logger.call(loggerContext, '[DUST ' + type + ']: ' + message); | ||
} | ||
@@ -77,3 +66,3 @@ | ||
dust.onError = function(error, chunk) { | ||
logger.call(console || window.console, '[!!!DEPRECATION WARNING!!!]: dust.onError will no longer return a chunk object.'); | ||
logger.call(loggerContext, '[!!!DEPRECATION WARNING!!!]: dust.onError will no longer return a chunk object.'); | ||
dust.log(error.message || error, ERROR); | ||
@@ -120,3 +109,4 @@ if(!dust.silenceErrors) { | ||
dust.renderSource = function(source, context, callback) { | ||
return dust.compileFn(source)(context, callback); | ||
//passing null, so that 'compile' knows that template has to be compiled but not to be stored in cache | ||
return dust.compileFn(source, null)(context, callback); | ||
}; | ||
@@ -175,9 +165,5 @@ | ||
dust.nextTick = (function() { | ||
if (typeof process !== 'undefined') { | ||
return process.nextTick; | ||
} else { | ||
return function(callback) { | ||
setTimeout(callback,0); | ||
}; | ||
} | ||
return function(callback) { | ||
setTimeout(callback,0); | ||
}; | ||
} )(); | ||
@@ -407,3 +393,3 @@ | ||
return this.templateName; | ||
} | ||
}; | ||
@@ -433,3 +419,3 @@ function Stack(head, tail, idx, len) { | ||
dust.log(new Error('Chunk error [' + chunk.error + '] thrown. Ceasing to render this template.'), ERROR); | ||
this.flush = function() {}; | ||
this.flush = EMPTY_FUNC; | ||
return; | ||
@@ -458,3 +444,3 @@ } else { | ||
dust.log(new Error('Chunk error [' + chunk.error + '] thrown. Ceasing to render this template.'), ERROR); | ||
this.flush = function() {}; | ||
this.flush = EMPTY_FUNC; | ||
return; | ||
@@ -850,9 +836,10 @@ } else { | ||
})(dust); | ||
if (typeof exports !== 'undefined') { | ||
if (typeof process !== 'undefined') { | ||
require('./server')(dust); | ||
if (typeof exports === 'object') { | ||
module.exports = dust; | ||
} else { | ||
root.dust = dust; | ||
} | ||
module.exports = dust; | ||
} | ||
})(this); | ||
@@ -0,19 +1,17 @@ | ||
/*global process*/ | ||
var path = require('path'), | ||
vm = require('vm'), | ||
dust = require('./dust'), | ||
parser = require('./parser'), | ||
vm = require('vm'); | ||
compiler = require('./compiler'); | ||
module.exports = function(dust) { | ||
var compiler = require('./compiler')(dust); | ||
compiler.parse = parser.parse; | ||
dust.compile = compiler.compile; | ||
var context = vm.createContext({dust: dust}); | ||
dust.loadSource = function(source, path) { | ||
return vm.runInContext(source, context, path); | ||
}; | ||
// use Node equivalents for some Dust methods | ||
var context = vm.createContext({dust: dust}); | ||
dust.loadSource = function(source, path) { | ||
return vm.runInContext(source, context, path); | ||
}; | ||
dust.nextTick = process.nextTick; | ||
dust.nextTick = process.nextTick; | ||
// expose optimizers in commonjs env too | ||
dust.optimizers = compiler.optimizers; | ||
} | ||
module.exports = dust; |
{ | ||
"name": "dustjs-linkedin", | ||
"version": "2.2.4", | ||
"author": "Aleksander Williams", | ||
"title": "Dust - Asynchronous Templating", | ||
"version": "2.3.0", | ||
"author": { | ||
"name": "Aleksander Williams", | ||
"url": "http://akdubya.github.com/dustjs" | ||
}, | ||
"homepage": "http://linkedin.github.io/dustjs/", | ||
"description": "Asynchronous templates for the browser and node.js ( LinkedIn fork )", | ||
@@ -13,3 +18,3 @@ "contributors": [ | ||
"name": "Veena Basavaraj", | ||
"email":"vbasavaraj@linkedin.com" | ||
"email": "vbasavaraj@linkedin.com" | ||
}, | ||
@@ -30,7 +35,8 @@ { | ||
"scripts": { | ||
"test" : "node test/jasmine-test/server/specRunner.js", | ||
"start": "node src/build.js" | ||
"test": "grunt test" | ||
}, | ||
"bin": { "dustc": "./bin/dustc" }, | ||
"main": "./lib/dust", | ||
"bin": { | ||
"dustc": "./bin/dustc" | ||
}, | ||
"main": "lib/server.js", | ||
"repository": { | ||
@@ -40,13 +46,27 @@ "type": "git", | ||
}, | ||
"keywords": ["templates", "views"], | ||
"keywords": [ | ||
"templates", | ||
"views" | ||
], | ||
"devDependencies": { | ||
"jasmine-node" : "1.9.x", | ||
"cover" : "0.2.x", | ||
"uglify-js" : "1.3.3", | ||
"pegjs" : "0.7.0" | ||
"pegjs": "0.7.0", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-connect": "~0.5.0", | ||
"grunt-template-jasmine-istanbul": "~0.2.5", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-copy": "~0.4.1", | ||
"grunt-gh-pages": "~0.9.0", | ||
"grunt-contrib-compress": "~0.5.3", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-uglify": "~0.2.7", | ||
"grunt-contrib-jshint": "~0.7.2", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt-shell": "~0.6.1", | ||
"grunt-contrib-jasmine": "~0.5.2", | ||
"grunt-bump": "0.0.11" | ||
}, | ||
"license": "MIT", | ||
"engine": { | ||
"node": ">=0.5" | ||
"node": ">=0.8" | ||
} | ||
} |
Dust [![Build Status](https://secure.travis-ci.org/linkedin/dustjs.png)](http://travis-ci.org/linkedin/dustjs) | ||
==== | ||
This is the LinkedIn fork of Dust. | ||
## Getting Started | ||
A quick tutorial for how to use Dust <https://github.com/linkedin/dustjs/wiki/Dust-Tutorial> | ||
This is the LinkedIn fork of Dust. | ||
More info <http://linkedin.github.io/dustjs/> and <http://linkedin.github.io/dustjs/#installation> | ||
## More | ||
Read more here: <http://linkedin.github.com/dustjs/>. | ||
@@ -12,1 +17,53 @@ | ||
For LinkedIn secure-filters : <https://github.com/linkedin/dustjs-filters-secure>. | ||
## Building Dust locally | ||
### Grab a copy of the repo | ||
``` | ||
cd some_project_directory | ||
git clone https://github.com/linkedin/dustjs.git dustjs | ||
cd dustjs | ||
``` | ||
### (Optional) Install Grunt-cli | ||
* Grunt-cli lets you run Grunt from within a subfolder see http://gruntjs.com/getting-started | ||
``` | ||
npm install -g grunt-cli | ||
``` | ||
### fetch all the node dependencies | ||
``` | ||
npm install | ||
``` | ||
### Run jshint and tests | ||
``` | ||
grunt test | ||
``` | ||
## Contributing to Dust | ||
### setup a branch for what you are working on | ||
``` | ||
git checkout -b myBranchName | ||
``` | ||
### Run jshint and tests | ||
``` | ||
grunt test | ||
``` | ||
### ... alternatively, run the watcher which hints and tests as you code | ||
``` | ||
grunt watch | ||
``` | ||
### Add unit tests | ||
Unit tests can be found in the `test/jasmine-tests/spec` directory | ||
### Add an issue and send a pull request | ||
Pull requests are easier to track if you also include an issue | ||
sending a pull request from a branch makes it easier for you to resolve conflicts in master | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2
69
1
3
327887
15
16
8571