1 import {isEmpty, isFunction} from '../utils';
3 export default function(instance) {
4 instance.registerHelper('if', function(conditional, options) {
5 if (isFunction(conditional)) { conditional = conditional.call(this); }
7 // Default behavior is to render the positive path if the value is truthy and not empty.
8 // The `includeZero` option may be set to treat the condtional as purely not empty based on the
9 // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
10 if ((!options.hash.includeZero && !conditional) || isEmpty(conditional)) {
11 return options.inverse(this);
13 return options.fn(this);
17 instance.registerHelper('unless', function(conditional, options) {
18 return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});