Skip to content

Commit 686866c

Browse files
author
Seth Kinast
committed
Release v2.7.2
1 parent e4a06d6 commit 686866c

8 files changed

+128
-64
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Change Log
22

3+
### v2.7.2 (2015/06/08 20:41 +00:00)
4+
- [#673](https://github.com/linkedin/dustjs/pull/673) Pass the current context to filters (@sethkinast)
5+
- [#676](https://github.com/linkedin/dustjs/pull/676) If a Promise is resolved with an array, iterate over it instead of rendering the whole array at once. Closes #674 (@sethkinast)
6+
- [#647](https://github.com/linkedin/dustjs/pull/647) Allow helpers to return primitives Previously returning a primitive would crash rendering with no way to recover. You can still return a Chunk and do more complex work if you need to. Helpers act like references or sections depending on if they have a body. When they have no body, they act like a reference and look in `params.filters` for filters to use. When they have a body, they act like a section. You can return thenables and streams normally. {@return value="<Hello>" filters="|s" /} {@return value="<Hello>"}{.} World{/return} Closes #645 (@sethkinast)
7+
- [#664](https://github.com/linkedin/dustjs/pull/664) Be slightly pickier about what Dust thinks a Stream is. Closes #663 (@sethkinast)
8+
- [#661](https://github.com/linkedin/dustjs/pull/661) Add saucelabs integration (@sethkinast)
9+
- [#658](https://github.com/linkedin/dustjs/pull/658) Refactor testing frameworks Closes #649 Closes #602 Closes #642 (@sethkinast)
10+
- [#660](https://github.com/linkedin/dustjs/pull/660) Grammar: s/char/character/ to avoid using a reserved name Closes #659 (@sethkinast)
11+
312
### v2.7.1 (2015/04/30 20:32 +00:00)
413
- [#655](https://github.com/linkedin/dustjs/pull/655) Update CommonJS example to make use of new onLoad behavior (@sethkinast)
514
- [#653](https://github.com/linkedin/dustjs/pull/653) Fix array iteration when context is undefined (@sethkinast)

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dustjs-linkedin",
3-
"version": "2.7.1",
3+
"version": "2.7.2",
44
"homepage": "https://github.com/linkedin/dustjs",
55
"authors": [
66
"Veena Basavaraj <vybs@users.noreply.github.com>",

dist/dust-core.js

+53-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/*! dustjs-linkedin - v2.7.1
1+
/*! dustjs-linkedin - v2.7.2
22
* http://dustjs.com/
33
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
44
(function (root, factory) {
5-
/*global define*/
65
if (typeof define === 'function' && define.amd && define.amd.dust === true) {
76
define('dust.core', [], factory);
87
} else if (typeof exports === 'object') {
@@ -12,7 +11,7 @@
1211
}
1312
}(this, function() {
1413
var dust = {
15-
"version": "2.7.1"
14+
"version": "2.7.2"
1615
},
1716
NONE = 'NONE', ERROR = 'ERROR', WARN = 'WARN', INFO = 'INFO', DEBUG = 'DEBUG',
1817
EMPTY_FUNC = function() {};
@@ -266,29 +265,32 @@
266265
*/
267266
dust.isStreamable = function(elem) {
268267
return elem &&
269-
typeof elem.on === 'function';
268+
typeof elem.on === 'function' &&
269+
typeof elem.pipe === 'function';
270270
};
271271

272272
// apply the filter chain and return the output string
273-
dust.filter = function(string, auto, filters) {
274-
var i, len, name;
273+
dust.filter = function(string, auto, filters, context) {
274+
var i, len, name, filter;
275275
if (filters) {
276276
for (i = 0, len = filters.length; i < len; i++) {
277277
name = filters[i];
278+
if (!name.length) {
279+
continue;
280+
}
281+
filter = dust.filters[name];
278282
if (name === 's') {
279283
auto = null;
280-
}
281-
else if (typeof dust.filters[name] === 'function') {
282-
string = dust.filters[name](string);
283-
}
284-
else {
284+
} else if (typeof filter === 'function') {
285+
string = filter(string, context);
286+
} else {
285287
dust.log('Invalid filter `' + name + '`', WARN);
286288
}
287289
}
288290
}
289291
// by default always apply the h filter, unless asked to unescape with |s
290292
if (auto) {
291-
string = dust.filters[auto](string);
293+
string = dust.filters[auto](string, context);
292294
}
293295
return string;
294296
};
@@ -757,7 +759,7 @@
757759
} else if (dust.isStreamable(elem)) {
758760
return this.stream(elem, context, null, auto, filters);
759761
} else if (!dust.isEmpty(elem)) {
760-
return this.write(dust.filter(elem, auto, filters));
762+
return this.write(dust.filter(elem, auto, filters, context));
761763
} else {
762764
return this;
763765
}
@@ -783,6 +785,12 @@
783785
}
784786
}
785787

788+
if (dust.isEmptyObject(bodies)) {
789+
// No bodies to render, and we've already invoked any function that was available in
790+
// hopes of returning a Chunk.
791+
return chunk;
792+
}
793+
786794
if (!dust.isEmptyObject(params)) {
787795
context = context.push(params);
788796
}
@@ -902,17 +910,33 @@
902910
}
903911
};
904912

905-
Chunk.prototype.helper = function(name, context, bodies, params) {
913+
Chunk.prototype.helper = function(name, context, bodies, params, auto) {
906914
var chunk = this,
915+
filters = params.filters,
907916
ret;
917+
918+
// Pre-2.7.1 compat: if auto is undefined, it's an old template. Automatically escape
919+
if (auto === undefined) {
920+
auto = 'h';
921+
}
922+
908923
// handle invalid helpers, similar to invalid filters
909924
if(dust.helpers[name]) {
910925
try {
911926
ret = dust.helpers[name](chunk, context, bodies, params);
912-
if (dust.isThenable(ret)) {
913-
return this.await(ret, context, bodies);
927+
if (ret instanceof Chunk) {
928+
return ret;
929+
}
930+
if(typeof filters === 'string') {
931+
filters = filters.split('|');
932+
}
933+
if (!dust.isEmptyObject(bodies)) {
934+
return chunk.section(ret, context, bodies, params);
914935
}
915-
return ret;
936+
// Helpers act slightly differently from functions in context in that they will act as
937+
// a reference if they are self-closing (due to grammar limitations)
938+
// In the Chunk.await function we check to make sure bodies is null before acting as a reference
939+
return chunk.reference(ret, context, auto, filters);
916940
} catch(err) {
917941
dust.log('Error in helper `' + name + '`: ' + err.message, ERROR);
918942
return chunk.setError(err);
@@ -928,23 +952,26 @@
928952
* @param thenable {Thenable} the target thenable to await
929953
* @param context {Context} context to use to render the deferred chunk
930954
* @param bodies {Object} must contain a "body", may contain an "error"
955+
* @param auto {String} automatically apply this filter if the Thenable is a reference
956+
* @param filters {Array} apply these filters if the Thenable is a reference
931957
* @return {Chunk}
932958
*/
933959
Chunk.prototype.await = function(thenable, context, bodies, auto, filters) {
934-
var body = bodies && bodies.block,
935-
errorBody = bodies && bodies.error;
936960
return this.map(function(chunk) {
937961
thenable.then(function(data) {
938-
if(body) {
939-
chunk.render(body, context.push(data)).end();
962+
if (bodies) {
963+
chunk = chunk.section(data, context, bodies);
940964
} else {
941-
chunk.reference(data, context, auto, filters).end();
965+
// Actually a reference. Self-closing sections don't render
966+
chunk = chunk.reference(data, context, auto, filters);
942967
}
968+
chunk.end();
943969
}, function(err) {
970+
var errorBody = bodies && bodies.error;
944971
if(errorBody) {
945972
chunk.render(errorBody, context.push(err)).end();
946973
} else {
947-
dust.log('Unhandled promise rejection in `' + context.getTemplateName() + '`');
974+
dust.log('Unhandled promise rejection in `' + context.getTemplateName() + '`', INFO);
948975
chunk.end();
949976
}
950977
});
@@ -976,8 +1003,8 @@
9761003
chunk = chunk.map(function(chunk) {
9771004
chunk.render(body, context.push(thunk)).end();
9781005
});
979-
} else {
980-
// Don't fork, just write into the master async chunk
1006+
} else if(!bodies) {
1007+
// When actually a reference, don't fork, just write into the master async chunk
9811008
chunk = chunk.reference(thunk, context, auto, filters);
9821009
}
9831010
})
@@ -988,7 +1015,7 @@
9881015
if(errorBody) {
9891016
chunk.render(errorBody, context.push(err));
9901017
} else {
991-
dust.log('Unhandled stream error in `' + context.getTemplateName() + '`');
1018+
dust.log('Unhandled stream error in `' + context.getTemplateName() + '`', INFO);
9921019
}
9931020
if(!ended) {
9941021
ended = true;

0 commit comments

Comments
 (0)