Skip to content

Commit

Permalink
Release v2.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Jun 8, 2015
1 parent e4a06d6 commit 686866c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 64 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Change Log

### v2.7.2 (2015/06/08 20:41 +00:00)
- [#673](https://github.com/linkedin/dustjs/pull/673) Pass the current context to filters (@sethkinast)
- [#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)
- [#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)
- [#664](https://github.com/linkedin/dustjs/pull/664) Be slightly pickier about what Dust thinks a Stream is. Closes #663 (@sethkinast)
- [#661](https://github.com/linkedin/dustjs/pull/661) Add saucelabs integration (@sethkinast)
- [#658](https://github.com/linkedin/dustjs/pull/658) Refactor testing frameworks Closes #649 Closes #602 Closes #642 (@sethkinast)
- [#660](https://github.com/linkedin/dustjs/pull/660) Grammar: s/char/character/ to avoid using a reserved name Closes #659 (@sethkinast)

### v2.7.1 (2015/04/30 20:32 +00:00)
- [#655](https://github.com/linkedin/dustjs/pull/655) Update CommonJS example to make use of new onLoad behavior (@sethkinast)
- [#653](https://github.com/linkedin/dustjs/pull/653) Fix array iteration when context is undefined (@sethkinast)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dustjs-linkedin",
"version": "2.7.1",
"version": "2.7.2",
"homepage": "https://github.com/linkedin/dustjs",
"authors": [
"Veena Basavaraj <vybs@users.noreply.github.com>",
Expand Down
79 changes: 53 additions & 26 deletions dist/dust-core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*! dustjs-linkedin - v2.7.1
/*! dustjs-linkedin - v2.7.2
* http://dustjs.com/
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
(function (root, factory) {
/*global define*/
if (typeof define === 'function' && define.amd && define.amd.dust === true) {
define('dust.core', [], factory);
} else if (typeof exports === 'object') {
Expand All @@ -12,7 +11,7 @@
}
}(this, function() {
var dust = {
"version": "2.7.1"
"version": "2.7.2"
},
NONE = 'NONE', ERROR = 'ERROR', WARN = 'WARN', INFO = 'INFO', DEBUG = 'DEBUG',
EMPTY_FUNC = function() {};
Expand Down Expand Up @@ -266,29 +265,32 @@
*/
dust.isStreamable = function(elem) {
return elem &&
typeof elem.on === 'function';
typeof elem.on === 'function' &&
typeof elem.pipe === 'function';
};

// apply the filter chain and return the output string
dust.filter = function(string, auto, filters) {
var i, len, name;
dust.filter = function(string, auto, filters, context) {
var i, len, name, filter;
if (filters) {
for (i = 0, len = filters.length; i < len; i++) {
name = filters[i];
if (!name.length) {
continue;
}
filter = dust.filters[name];
if (name === 's') {
auto = null;
}
else if (typeof dust.filters[name] === 'function') {
string = dust.filters[name](string);
}
else {
} else if (typeof filter === 'function') {
string = filter(string, context);
} else {
dust.log('Invalid filter `' + name + '`', WARN);
}
}
}
// by default always apply the h filter, unless asked to unescape with |s
if (auto) {
string = dust.filters[auto](string);
string = dust.filters[auto](string, context);
}
return string;
};
Expand Down Expand Up @@ -757,7 +759,7 @@
} else if (dust.isStreamable(elem)) {
return this.stream(elem, context, null, auto, filters);
} else if (!dust.isEmpty(elem)) {
return this.write(dust.filter(elem, auto, filters));
return this.write(dust.filter(elem, auto, filters, context));
} else {
return this;
}
Expand All @@ -783,6 +785,12 @@
}
}

if (dust.isEmptyObject(bodies)) {
// No bodies to render, and we've already invoked any function that was available in
// hopes of returning a Chunk.
return chunk;
}

if (!dust.isEmptyObject(params)) {
context = context.push(params);
}
Expand Down Expand Up @@ -902,17 +910,33 @@
}
};

Chunk.prototype.helper = function(name, context, bodies, params) {
Chunk.prototype.helper = function(name, context, bodies, params, auto) {
var chunk = this,
filters = params.filters,
ret;

// Pre-2.7.1 compat: if auto is undefined, it's an old template. Automatically escape
if (auto === undefined) {
auto = 'h';
}

// handle invalid helpers, similar to invalid filters
if(dust.helpers[name]) {
try {
ret = dust.helpers[name](chunk, context, bodies, params);
if (dust.isThenable(ret)) {
return this.await(ret, context, bodies);
if (ret instanceof Chunk) {
return ret;
}
if(typeof filters === 'string') {
filters = filters.split('|');
}
if (!dust.isEmptyObject(bodies)) {
return chunk.section(ret, context, bodies, params);
}
return ret;
// Helpers act slightly differently from functions in context in that they will act as
// a reference if they are self-closing (due to grammar limitations)
// In the Chunk.await function we check to make sure bodies is null before acting as a reference
return chunk.reference(ret, context, auto, filters);
} catch(err) {
dust.log('Error in helper `' + name + '`: ' + err.message, ERROR);
return chunk.setError(err);
Expand All @@ -928,23 +952,26 @@
* @param thenable {Thenable} the target thenable to await
* @param context {Context} context to use to render the deferred chunk
* @param bodies {Object} must contain a "body", may contain an "error"
* @param auto {String} automatically apply this filter if the Thenable is a reference
* @param filters {Array} apply these filters if the Thenable is a reference
* @return {Chunk}
*/
Chunk.prototype.await = function(thenable, context, bodies, auto, filters) {
var body = bodies && bodies.block,
errorBody = bodies && bodies.error;
return this.map(function(chunk) {
thenable.then(function(data) {
if(body) {
chunk.render(body, context.push(data)).end();
if (bodies) {
chunk = chunk.section(data, context, bodies);
} else {
chunk.reference(data, context, auto, filters).end();
// Actually a reference. Self-closing sections don't render
chunk = chunk.reference(data, context, auto, filters);
}
chunk.end();
}, function(err) {
var errorBody = bodies && bodies.error;
if(errorBody) {
chunk.render(errorBody, context.push(err)).end();
} else {
dust.log('Unhandled promise rejection in `' + context.getTemplateName() + '`');
dust.log('Unhandled promise rejection in `' + context.getTemplateName() + '`', INFO);
chunk.end();
}
});
Expand Down Expand Up @@ -976,8 +1003,8 @@
chunk = chunk.map(function(chunk) {
chunk.render(body, context.push(thunk)).end();
});
} else {
// Don't fork, just write into the master async chunk
} else if(!bodies) {
// When actually a reference, don't fork, just write into the master async chunk
chunk = chunk.reference(thunk, context, auto, filters);
}
})
Expand All @@ -988,7 +1015,7 @@
if(errorBody) {
chunk.render(errorBody, context.push(err));
} else {
dust.log('Unhandled stream error in `' + context.getTemplateName() + '`');
dust.log('Unhandled stream error in `' + context.getTemplateName() + '`', INFO);
}
if(!ended) {
ended = true;
Expand Down
Loading

0 comments on commit 686866c

Please sign in to comment.