|
1 | 1 | (function(dust){ |
2 | 2 |
|
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 | +} |
5 | 16 |
|
6 | 17 | function isSelect(context) { |
7 | 18 | var value = context.current(); |
@@ -139,22 +150,23 @@ var helpers = { |
139 | 150 | if (context.stack.index === context.stack.of - 1) { |
140 | 151 | return chunk; |
141 | 152 | } |
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; |
147 | 157 | } |
148 | 158 | }, |
149 | 159 |
|
150 | 160 | "idx": function(chunk, context, bodies) { |
151 | 161 | 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 | + } |
158 | 170 | }, |
159 | 171 |
|
160 | 172 | /** |
@@ -204,12 +216,16 @@ var helpers = { |
204 | 216 | cond argument should evaluate to a valid javascript expression |
205 | 217 | **/ |
206 | 218 |
|
207 | | - "if": function( chunk, context, bodies, params ){ |
| 219 | + "if": function( chunk, context, bodies, params ) { |
208 | 220 | 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); |
213 | 229 | // eval expressions with given dust references |
214 | 230 | if(eval(cond)){ |
215 | 231 | if(body) { |
|
0 commit comments