Skip to content

Commit d92d5c3

Browse files
author
Prayrit Jain
committed
Release v2.5.0
1 parent af1d01d commit d92d5c3

File tree

8 files changed

+93
-35
lines changed

8 files changed

+93
-35
lines changed

archive/dust-2.5.0.tar.gz

44.7 KB
Binary file not shown.

archive/dust-2.5.0.zip

46 KB
Binary file not shown.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dustjs-linkedin",
3-
"version": "2.4.2",
3+
"version": "2.5.0",
44
"main": "dist/dust-full.min.js",
55
"devDependencies": {
66
"pegjs": "0.8.0"

dist/dust-core.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Dust - Asynchronous Templating - v2.4.2
1+
/*! Dust - Asynchronous Templating - v2.5.0
22
* http://linkedin.github.io/dustjs/
33
* Copyright (c) 2014 Aleksander Williams; Released under the MIT License */
44
(function(root) {
@@ -16,6 +16,25 @@
1616

1717
dust.debugLevel = NONE;
1818

19+
dust.config = {
20+
whitespace: false,
21+
};
22+
23+
// Directive aliases to minify code
24+
dust._aliases = {
25+
"write": "w",
26+
"end": "e",
27+
"map": "m",
28+
"render": "r",
29+
"reference": "f",
30+
"section": "s",
31+
"exists": "x",
32+
"notexists": "nx",
33+
"block": "b",
34+
"partial": "p",
35+
"helper": "h"
36+
};
37+
1938
// Try to find the console in global scope
2039
if (root && root.console && root.console.log) {
2140
loggerContext = root.console;
@@ -297,7 +316,7 @@
297316
Context.prototype._get = function(cur, down) {
298317
var ctx = this.stack,
299318
i = 1,
300-
value, first, len, ctxThis;
319+
value, first, len, ctxThis, fn;
301320
first = down[0];
302321
len = down.length;
303322

@@ -342,14 +361,16 @@
342361

343362
// Return the ctx or a function wrapping the application of the context.
344363
if (typeof ctx === 'function') {
345-
return function() {
364+
fn = function() {
346365
try {
347366
return ctx.apply(ctxThis, arguments);
348367
} catch (err) {
349368
dust.log(err, ERROR);
350369
throw err;
351370
}
352371
};
372+
fn.__dustBody = !!ctx.__dustBody;
373+
return fn;
353374
} else {
354375
if (ctx === undefined) {
355376
dust.log('Cannot find the value for reference [{' + down.join('.') + '}] in template [' + this.getTemplateName() + ']');
@@ -499,7 +520,6 @@
499520
this.events = {};
500521
}
501522
if (!this.events[type]) {
502-
dust.log('Event type [' + type + '] does not exist. Using just the specified callback.', WARN);
503523
if(callback) {
504524
this.events[type] = callback;
505525
} else {
@@ -612,7 +632,7 @@
612632

613633
Chunk.prototype.section = function(elem, context, bodies, params) {
614634
// anonymous functions
615-
if (typeof elem === 'function') {
635+
if (typeof elem === 'function' && !elem.__dustBody) {
616636
try {
617637
elem = elem.apply(context.current(), [this, context, bodies, params]);
618638
} catch(e) {
@@ -797,6 +817,13 @@
797817
return this;
798818
};
799819

820+
// Chunk aliases
821+
for(var f in Chunk.prototype) {
822+
if(dust._aliases[f]) {
823+
Chunk.prototype[dust._aliases[f]] = Chunk.prototype[f];
824+
}
825+
}
826+
800827
function Tap(head, tail) {
801828
this.head = head;
802829
this.tail = tail;
@@ -816,7 +843,7 @@
816843
return value;
817844
};
818845

819-
var HCHARS = new RegExp(/[&<>\"\']/),
846+
var HCHARS = /[&<>"']/,
820847
AMP = /&/g,
821848
LT = /</g,
822849
GT = />/g,

dist/dust-core.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dust-full.js

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Dust - Asynchronous Templating - v2.4.2
1+
/*! Dust - Asynchronous Templating - v2.5.0
22
* http://linkedin.github.io/dustjs/
33
* Copyright (c) 2014 Aleksander Williams; Released under the MIT License */
44
(function(root) {
@@ -16,6 +16,25 @@
1616

1717
dust.debugLevel = NONE;
1818

19+
dust.config = {
20+
whitespace: false,
21+
};
22+
23+
// Directive aliases to minify code
24+
dust._aliases = {
25+
"write": "w",
26+
"end": "e",
27+
"map": "m",
28+
"render": "r",
29+
"reference": "f",
30+
"section": "s",
31+
"exists": "x",
32+
"notexists": "nx",
33+
"block": "b",
34+
"partial": "p",
35+
"helper": "h"
36+
};
37+
1938
// Try to find the console in global scope
2039
if (root && root.console && root.console.log) {
2140
loggerContext = root.console;
@@ -297,7 +316,7 @@
297316
Context.prototype._get = function(cur, down) {
298317
var ctx = this.stack,
299318
i = 1,
300-
value, first, len, ctxThis;
319+
value, first, len, ctxThis, fn;
301320
first = down[0];
302321
len = down.length;
303322

@@ -342,14 +361,16 @@
342361

343362
// Return the ctx or a function wrapping the application of the context.
344363
if (typeof ctx === 'function') {
345-
return function() {
364+
fn = function() {
346365
try {
347366
return ctx.apply(ctxThis, arguments);
348367
} catch (err) {
349368
dust.log(err, ERROR);
350369
throw err;
351370
}
352371
};
372+
fn.__dustBody = !!ctx.__dustBody;
373+
return fn;
353374
} else {
354375
if (ctx === undefined) {
355376
dust.log('Cannot find the value for reference [{' + down.join('.') + '}] in template [' + this.getTemplateName() + ']');
@@ -499,7 +520,6 @@
499520
this.events = {};
500521
}
501522
if (!this.events[type]) {
502-
dust.log('Event type [' + type + '] does not exist. Using just the specified callback.', WARN);
503523
if(callback) {
504524
this.events[type] = callback;
505525
} else {
@@ -612,7 +632,7 @@
612632

613633
Chunk.prototype.section = function(elem, context, bodies, params) {
614634
// anonymous functions
615-
if (typeof elem === 'function') {
635+
if (typeof elem === 'function' && !elem.__dustBody) {
616636
try {
617637
elem = elem.apply(context.current(), [this, context, bodies, params]);
618638
} catch(e) {
@@ -797,6 +817,13 @@
797817
return this;
798818
};
799819

820+
// Chunk aliases
821+
for(var f in Chunk.prototype) {
822+
if(dust._aliases[f]) {
823+
Chunk.prototype[dust._aliases[f]] = Chunk.prototype[f];
824+
}
825+
}
826+
800827
function Tap(head, tail) {
801828
this.head = head;
802829
this.tail = tail;
@@ -816,7 +843,7 @@
816843
return value;
817844
};
818845

819-
var HCHARS = new RegExp(/[&<>\"\']/),
846+
var HCHARS = /[&<>"']/,
820847
AMP = /&/g,
821848
LT = /</g,
822849
GT = />/g,
@@ -3546,7 +3573,7 @@
35463573
var compiler = {},
35473574
isArray = dust.isArray;
35483575

3549-
3576+
35503577
compiler.compile = function(source, name) {
35513578
// the name parameter is optional.
35523579
// this can happen for templates that are rendered immediately (renderSource which calls compileFn) or
@@ -3556,7 +3583,7 @@
35563583
if (!name && name !== null) {
35573584
throw new Error('Template name parameter cannot be undefined when calling dust.compile');
35583585
}
3559-
3586+
35603587
try {
35613588
var ast = filterAST(parse(source));
35623589
return compile(ast, name);
@@ -3583,7 +3610,7 @@
35833610
body: compactBuffers,
35843611
buffer: noop,
35853612
special: convertSpecial,
3586-
format: nullify, // TODO: convert format
3613+
format: format,
35873614
reference: visit,
35883615
'#': visit,
35893616
'?': visit,
@@ -3640,9 +3667,10 @@
36403667
for (i=1, len=node.length; i<len; i++) {
36413668
res = compiler.filterNode(context, node[i]);
36423669
if (res) {
3643-
if (res[0] === 'buffer') {
3670+
if (res[0] === 'buffer' || res[0] === 'format') {
36443671
if (memo) {
3645-
memo[1] += res[1];
3672+
memo[0] = (res[0] === 'buffer') ? 'buffer' : memo[0];
3673+
memo[1] += res.slice(1, -2).join('');
36463674
} else {
36473675
memo = res;
36483676
out.push(res);
@@ -3665,7 +3693,7 @@
36653693
};
36663694

36673695
function convertSpecial(context, node) {
3668-
return ['buffer', specialChars[node[1]]];
3696+
return ['buffer', specialChars[node[1]], node[2], node[3]];
36693697
}
36703698

36713699
function noop(context, node) {
@@ -3674,6 +3702,10 @@
36743702

36753703
function nullify(){}
36763704

3705+
function format(context, node) {
3706+
return dust.config.whitespace ? node : null;
3707+
}
3708+
36773709
function compile(ast, name) {
36783710
var context = {
36793711
name: name,
@@ -3716,7 +3748,7 @@
37163748

37173749
for (i=0, len=bodies.length; i<len; i++) {
37183750
out[i] = 'function body_' + i + '(chk,ctx){' +
3719-
blx + 'return chk' + bodies[i] + ';}';
3751+
blx + 'return chk' + bodies[i] + ';}body_' + i + '.__dustBody=!0;';
37203752
}
37213753
return out.join('');
37223754
}
@@ -3743,15 +3775,15 @@
37433775
},
37443776

37453777
buffer: function(context, node) {
3746-
return '.write(' + escape(node[1]) + ')';
3778+
return '.w(' + escape(node[1]) + ')';
37473779
},
37483780

37493781
format: function(context, node) {
3750-
return '.write(' + escape(node[1] + node[2]) + ')';
3782+
return '.w(' + escape(node[1] + node[2]) + ')';
37513783
},
37523784

37533785
reference: function(context, node) {
3754-
return '.reference(' + compiler.compileNode(context, node[1]) +
3786+
return '.f(' + compiler.compileNode(context, node[1]) +
37553787
',ctx,' + compiler.compileNode(context, node[2]) + ')';
37563788
},
37573789

@@ -3798,7 +3830,7 @@
37983830
},
37993831

38003832
'@': function(context, node) {
3801-
return '.helper(' +
3833+
return '.h(' +
38023834
escape(node[1].text) +
38033835
',' + compiler.compileNode(context, node[2]) + ',' +
38043836
compiler.compileNode(context, node[4]) + ',' +
@@ -3838,7 +3870,7 @@
38383870
},
38393871

38403872
partial: function(context, node) {
3841-
return '.partial(' +
3873+
return '.p(' +
38423874
compiler.compileNode(context, node[1]) +
38433875
',' + compiler.compileNode(context, node[2]) +
38443876
',' + compiler.compileNode(context, node[3]) + ')';
@@ -3907,12 +3939,12 @@
39073939
return escape(node[1]);
39083940
},
39093941
raw: function(context, node) {
3910-
return ".write(" + escape(node[1]) + ")";
3942+
return ".w(" + escape(node[1]) + ")";
39113943
}
39123944
};
39133945

39143946
function compileSection(context, node, cmd) {
3915-
return '.' + cmd + '(' +
3947+
return '.' + (dust._aliases[cmd] || cmd) + '(' +
39163948
compiler.compileNode(context, node[1]) +
39173949
',' + compiler.compileNode(context, node[2]) + ',' +
39183950
compiler.compileNode(context, node[4]) + ',' +
@@ -3946,8 +3978,7 @@
39463978
dust.pragmas = compiler.pragmas;
39473979
dust.compileNode = compiler.compileNode;
39483980
dust.nodes = compiler.nodes;
3949-
3981+
39503982
return compiler;
39513983

39523984
}));
3953-

dist/dust-full.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dustjs-linkedin",
33
"title": "Dust - Asynchronous Templating",
4-
"version": "2.4.2",
4+
"version": "2.5.0",
55
"author": {
66
"name": "Aleksander Williams",
77
"url": "http://akdubya.github.com/dustjs"

0 commit comments

Comments
 (0)