Skip to content

Commit

Permalink
Deprecate {@if} and {@idx}
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Nov 12, 2014
1 parent 35bf5eb commit 43ef65a
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
(function(dust){

//using the built in logging method of dust when accessible
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {};
// Use dust's built-in logging when available
var _log = dust.log ? function(msg, level) {
level = level || "INFO";
dust.log(msg, level);
} : function() {};

var _deprecatedCache = {};
function _deprecated(target) {
if(_deprecatedCache[target]) { return; }
_log("Deprecation warning: " + target + " is deprecated and will be removed in a future version of dustjs-helpers", "WARN");
_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" + target.replace(/\W+/g, ""), "WARN");
_deprecatedCache[target] = true;
}

function isSelect(context) {
var value = context.current();
Expand Down Expand Up @@ -74,10 +85,9 @@ function coerce (value, type, context) {
switch (type || typeof(value)) {
case 'number': return +value;
case 'string': return String(value);
case 'boolean': {
case 'boolean':
value = (value === 'false' ? false : value);
return Boolean(value);
}
case 'date': return new Date(value);
case 'context': return context.get(value);
}
Expand Down Expand Up @@ -140,22 +150,23 @@ var helpers = {
if (context.stack.index === context.stack.of - 1) {
return chunk;
}
if(body) {
return bodies.block(chunk, context);
}
else {
return chunk;
if (body) {
return body(chunk, context);
} else {
return chunk;
}
},

"idx": function(chunk, context, bodies) {
var body = bodies.block;
if(body) {
return bodies.block(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
if(body) {
// Deprecated in 1.4. Will be removed in 1.6
_deprecated("{@idx}");
return body(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
},

/**
Expand Down Expand Up @@ -205,12 +216,16 @@ var helpers = {
cond argument should evaluate to a valid javascript expression
**/

"if": function( chunk, context, bodies, params ){
"if": function( chunk, context, bodies, params ) {
var body = bodies.block,
skip = bodies['else'];
if( params && params.cond){
var cond = params.cond;
cond = dust.helpers.tap(cond, chunk, context);
skip = bodies['else'],
cond;

if(params && params.cond) {
// Deprecated in 1.4. Will be removed in 1.6
_deprecated("{@if}");

cond = dust.helpers.tap(params.cond, chunk, context);
// eval expressions with given dust references
if(eval(cond)){
if(body) {
Expand Down

0 comments on commit 43ef65a

Please sign in to comment.