From 39ba91857f61e1207d02aec3df26d601370a290a Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Tue, 28 Apr 2015 19:39:13 -0700 Subject: [PATCH] Release v1.7.1 --- CHANGELOG.md | 6 +++++- bower.json | 2 +- dist/dust-helpers.js | 21 ++++++++++++++------- dist/dust-helpers.min.js | 4 ++-- package.json | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a5de87..701092e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## Change Log -### v1.7.0 (2015/04/18 00:24 +00:00) +### v1.7.1 (2015/04/29 02:39 +00:00) +- [#136](https://github.com/linkedin/dustjs-helpers/pull/136) Sync linkedin/dustjs#650 (@sethkinast) +- [#135](https://github.com/linkedin/dustjs-helpers/pull/135) Evaluate truth test bodies inside a @select before resolving the select. (@sethkinast) + +### v1.7.0 (2015/04/18 00:26 +00:00) - [#133](https://github.com/linkedin/dustjs-helpers/pull/133) Don't require a key for `{@select}` (@sethkinast) - [#129](https://github.com/linkedin/dustjs-helpers/pull/129) Refactor for 1.7 (@sethkinast) - [#132](https://github.com/linkedin/dustjs-helpers/pull/132) Drop 0.8 support and bump dust core dependency (@sethkinast) diff --git a/bower.json b/bower.json index d430a7f..f77d196 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "dustjs-helpers", - "version": "1.7.0", + "version": "1.7.1", "homepage": "https://github.com/linkedin/dustjs-helpers", "authors": [ "Veena Basavaraj ", diff --git a/dist/dust-helpers.js b/dist/dust-helpers.js index e6f0847..cf2a3ff 100644 --- a/dist/dust-helpers.js +++ b/dist/dust-helpers.js @@ -1,4 +1,4 @@ -/*! dustjs-helpers - v1.7.0 +/*! dustjs-helpers - v1.7.1 * http://dustjs.com/ * Copyright (c) 2015 Aleksander Williams; Released under the MIT License */ (function(root, factory) { @@ -51,6 +51,7 @@ function addSelectState(context, opts) { } var state = { + isPending: false, isResolved: false, isDeferredComplete: false, deferreds: [] @@ -108,7 +109,7 @@ function filter(chunk, context, bodies, params, helperName, test) { var body = bodies.block, skip = bodies.else, selectState = getSelectState(context) || {}, - key, value, type; + willResolve, key, value, type; // Once one truth test in a select passes, short-circuit the rest of the tests if (selectState.isResolved) { @@ -131,14 +132,20 @@ function filter(chunk, context, bodies, params, helperName, test) { value = coerce(context.resolve(params.value), type); if (test(key, value)) { - if (selectState) { - selectState.isResolved = true; + // Once a truth test passes, put the select into "pending" state. Now we can render the body of + // the truth test (which may contain truth tests) without altering the state of the select. + if (!selectState.isPending) { + willResolve = true; + selectState.isPending = true; } - if(body) { - return chunk.render(body, context); + if (body) { + chunk = chunk.render(body, context); + } + if (willResolve) { + selectState.isResolved = true; } } else if (skip) { - return chunk.render(skip, context); + chunk = chunk.render(skip, context); } return chunk; } diff --git a/dist/dust-helpers.min.js b/dist/dust-helpers.min.js index 2c897e6..302ba44 100644 --- a/dist/dust-helpers.min.js +++ b/dist/dust-helpers.min.js @@ -1,4 +1,4 @@ -/*! dustjs-helpers - v1.7.0 +/*! dustjs-helpers - v1.7.1 * http://dustjs.com/ * Copyright (c) 2015 Aleksander Williams; Released under the MIT License */ -!function(a,b){"function"==typeof define&&define.amd&&define.amd.dust===!0?define(["dust.core"],b):"object"==typeof exports?module.exports=b(require("dustjs-linkedin")):b(a.dust)}(this,function(dust){function a(a,b,c){c=c||"INFO",a=a?"{@"+a+"}: ":"",dust.log(a+b,c)}function b(b){k[b]||(a(b,"Deprecation warning: "+b+" is deprecated and will be removed in a future version of dustjs-helpers","WARN"),a(null,"For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#"+b.replace(/\W+/g,""),"WARN"),k[b]=!0)}function c(a){return a.stack.tail&&a.stack.tail.head&&"undefined"!=typeof a.stack.tail.head.__select__}function d(a){return c(a)&&a.get("__select__")}function e(a,b){var c,d=a.stack.head,e=a.rebase();a.stack&&a.stack.tail&&(e.stack=a.stack.tail);var f={isResolved:!1,isDeferredComplete:!1,deferreds:[]};for(c in b)f[c]=b[c];return e.push({__select__:f}).push(d,a.stack.index,a.stack.of)}function f(a){var b,c;if(a.deferreds.length)for(a.isDeferredComplete=!0,b=0,c=a.deferreds.length;c>b;b++)a.deferreds[b]()}function g(a,b){return"function"==typeof b?b.toString().replace(/(^\s+|\s+$)/gm,"").replace(/\n/gm,"").replace(/,\s*/gm,", ").replace(/\)\{/gm,") {"):b}function h(a,b){return function(c,d,e,f){return i(c,d,e,f,a,b)}}function i(b,c,e,f,g,h){var i,k,l,m=e.block,n=e["else"],o=d(c)||{};if(o.isResolved)return b;if(f.hasOwnProperty("key"))i=f.key;else{if(!o.hasOwnProperty("key"))return a(g,"No key specified","WARN"),b;i=o.key}if(l=f.type||o.type,i=j(c.resolve(i),l),k=j(c.resolve(f.value),l),h(i,k)){if(o&&(o.isResolved=!0),m)return b.render(m,c)}else if(n)return b.render(n,c);return b}function j(a,b){switch(b&&(b=b.toLowerCase()),b){case"number":return+a;case"string":return String(a);case"boolean":return a="false"===a?!1:a,Boolean(a);case"date":return new Date(a)}return a}var k={},l={tap:function(a,c,d){return b("tap"),d.resolve(a)},sep:function(a,b,c){var d=c.block;return b.stack.index===b.stack.of-1?a:d?d(a,b):a},first:function(a,b,c){return 0===b.stack.index?c.block(a,b):a},last:function(a,b,c){return b.stack.index===b.stack.of-1?c.block(a,b):a},contextDump:function(b,c,d,e){var f,h,i=c.resolve(e.to),j=c.resolve(e.key);switch(j){case"full":f=c.stack;break;default:f=c.stack.head}switch(h=JSON.stringify(f,g,2),i){case"console":a("contextDump",h);break;default:h=h.replace(/a}),lte:h("lte",function(a,b){return b>=a}),gt:h("gt",function(a,b){return a>b}),gte:h("gte",function(a,b){return a>=b}),any:function(b,c,e,f){var g=d(c);return g?g.isDeferredComplete?a("any","Must not be nested inside {@any} or {@none} block","ERROR"):b=b.map(function(a){g.deferreds.push(function(){g.isResolved&&(a=a.render(e.block,c)),a.end()})}):a("any","Must be used inside a {@select} block","ERROR"),b},none:function(b,c,e,f){var g=d(c);return g?g.isDeferredComplete?a("none","Must not be nested inside {@any} or {@none} block","ERROR"):b=b.map(function(a){g.deferreds.push(function(){g.isResolved||(a=a.render(e.block,c)),a.end()})}):a("none","Must be used inside a {@select} block","ERROR"),b},size:function(a,b,c,d){var e,f,g=d.key;if(g=b.resolve(d.key),g&&g!==!0)if(dust.isArray(g))e=g.length;else if(!isNaN(parseFloat(g))&&isFinite(g))e=g;else if("object"==typeof g){e=0;for(f in g)g.hasOwnProperty(f)&&e++}else e=(g+"").length;else e=0;return a.write(e)}};for(var m in l)dust.helpers[m]=l[m];return dust}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd&&define.amd.dust===!0?define(["dust.core"],b):"object"==typeof exports?module.exports=b(require("dustjs-linkedin")):b(a.dust)}(this,function(dust){function a(a,b,c){c=c||"INFO",a=a?"{@"+a+"}: ":"",dust.log(a+b,c)}function b(b){k[b]||(a(b,"Deprecation warning: "+b+" is deprecated and will be removed in a future version of dustjs-helpers","WARN"),a(null,"For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#"+b.replace(/\W+/g,""),"WARN"),k[b]=!0)}function c(a){return a.stack.tail&&a.stack.tail.head&&"undefined"!=typeof a.stack.tail.head.__select__}function d(a){return c(a)&&a.get("__select__")}function e(a,b){var c,d=a.stack.head,e=a.rebase();a.stack&&a.stack.tail&&(e.stack=a.stack.tail);var f={isPending:!1,isResolved:!1,isDeferredComplete:!1,deferreds:[]};for(c in b)f[c]=b[c];return e.push({__select__:f}).push(d,a.stack.index,a.stack.of)}function f(a){var b,c;if(a.deferreds.length)for(a.isDeferredComplete=!0,b=0,c=a.deferreds.length;c>b;b++)a.deferreds[b]()}function g(a,b){return"function"==typeof b?b.toString().replace(/(^\s+|\s+$)/gm,"").replace(/\n/gm,"").replace(/,\s*/gm,", ").replace(/\)\{/gm,") {"):b}function h(a,b){return function(c,d,e,f){return i(c,d,e,f,a,b)}}function i(b,c,e,f,g,h){var i,k,l,m,n=e.block,o=e["else"],p=d(c)||{};if(p.isResolved)return b;if(f.hasOwnProperty("key"))k=f.key;else{if(!p.hasOwnProperty("key"))return a(g,"No key specified","WARN"),b;k=p.key}return m=f.type||p.type,k=j(c.resolve(k),m),l=j(c.resolve(f.value),m),h(k,l)?(p.isPending||(i=!0,p.isPending=!0),n&&(b=b.render(n,c)),i&&(p.isResolved=!0)):o&&(b=b.render(o,c)),b}function j(a,b){switch(b&&(b=b.toLowerCase()),b){case"number":return+a;case"string":return String(a);case"boolean":return a="false"===a?!1:a,Boolean(a);case"date":return new Date(a)}return a}var k={},l={tap:function(a,c,d){return b("tap"),d.resolve(a)},sep:function(a,b,c){var d=c.block;return b.stack.index===b.stack.of-1?a:d?d(a,b):a},first:function(a,b,c){return 0===b.stack.index?c.block(a,b):a},last:function(a,b,c){return b.stack.index===b.stack.of-1?c.block(a,b):a},contextDump:function(b,c,d,e){var f,h,i=c.resolve(e.to),j=c.resolve(e.key);switch(j){case"full":f=c.stack;break;default:f=c.stack.head}switch(h=JSON.stringify(f,g,2),i){case"console":a("contextDump",h);break;default:h=h.replace(/a}),lte:h("lte",function(a,b){return b>=a}),gt:h("gt",function(a,b){return a>b}),gte:h("gte",function(a,b){return a>=b}),any:function(b,c,e,f){var g=d(c);return g?g.isDeferredComplete?a("any","Must not be nested inside {@any} or {@none} block","ERROR"):b=b.map(function(a){g.deferreds.push(function(){g.isResolved&&(a=a.render(e.block,c)),a.end()})}):a("any","Must be used inside a {@select} block","ERROR"),b},none:function(b,c,e,f){var g=d(c);return g?g.isDeferredComplete?a("none","Must not be nested inside {@any} or {@none} block","ERROR"):b=b.map(function(a){g.deferreds.push(function(){g.isResolved||(a=a.render(e.block,c)),a.end()})}):a("none","Must be used inside a {@select} block","ERROR"),b},size:function(a,b,c,d){var e,f,g=d.key;if(g=b.resolve(d.key),g&&g!==!0)if(dust.isArray(g))e=g.length;else if(!isNaN(parseFloat(g))&&isFinite(g))e=g;else if("object"==typeof g){e=0;for(f in g)g.hasOwnProperty(f)&&e++}else e=(g+"").length;else e=0;return a.write(e)}};for(var m in l)dust.helpers[m]=l[m];return dust}); \ No newline at end of file diff --git a/package.json b/package.json index 26b8219..945132a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dustjs-helpers", - "version": "1.7.0", + "version": "1.7.1", "author": { "name": "Aleksander Williams", "url": "http://akdubya.github.com/dustjs"