Skip to content

Commit 20e0226

Browse files
author
Seth Kinast
committed
Deprecate {@if} and {@idx}
1 parent 91ec158 commit 20e0226

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

lib/dust-helpers.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
(function(dust){
22

3-
//using the built in logging method of dust when accessible
4-
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {};
3+
// Use dust's built-in logging when available
4+
var _log = dust.log ? function(msg, level) {
5+
level = level || "INFO";
6+
dust.log(msg, level);
7+
} : function() {};
8+
9+
var _deprecatedCache = {};
10+
function _deprecated(target) {
11+
if(_deprecatedCache[target]) { return; }
12+
_log("Deprecation warning: " + target + " is deprecated and will be removed in a future version of dustjs-helpers", "WARN");
13+
_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" + target.replace(/\W+/g, ""), "WARN");
14+
_deprecatedCache[target] = true;
15+
}
516

617
function isSelect(context) {
718
var value = context.current();
@@ -139,22 +150,23 @@ var helpers = {
139150
if (context.stack.index === context.stack.of - 1) {
140151
return chunk;
141152
}
142-
if(body) {
143-
return bodies.block(chunk, context);
144-
}
145-
else {
146-
return chunk;
153+
if (body) {
154+
return body(chunk, context);
155+
} else {
156+
return chunk;
147157
}
148158
},
149159

150160
"idx": function(chunk, context, bodies) {
151161
var body = bodies.block;
152-
if(body) {
153-
return bodies.block(chunk, context.push(context.stack.index));
154-
}
155-
else {
156-
return chunk;
157-
}
162+
// Will be removed in 1.6
163+
_deprecated("{@idx}");
164+
if(body) {
165+
return body(chunk, context.push(context.stack.index));
166+
}
167+
else {
168+
return chunk;
169+
}
158170
},
159171

160172
/**
@@ -204,12 +216,16 @@ var helpers = {
204216
cond argument should evaluate to a valid javascript expression
205217
**/
206218

207-
"if": function( chunk, context, bodies, params ){
219+
"if": function( chunk, context, bodies, params ) {
208220
var body = bodies.block,
209-
skip = bodies['else'];
210-
if( params && params.cond){
211-
var cond = params.cond;
212-
cond = dust.helpers.tap(cond, chunk, context);
221+
skip = bodies['else'],
222+
cond;
223+
224+
if(params && params.cond) {
225+
// Will be removed in 1.6
226+
_deprecated("{@if}");
227+
228+
cond = dust.helpers.tap(params.cond, chunk, context);
213229
// eval expressions with given dust references
214230
if(eval(cond)){
215231
if(body) {

0 commit comments

Comments
 (0)