Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate {@if} and {@idx} #102

Merged
merged 1 commit into from
Nov 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 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 @@ -139,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;
}
// Will be removed in 1.6
_deprecated("{@idx}");
if(body) {
return body(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
},

/**
Expand Down Expand Up @@ -204,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) {
// 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