Sha256: 8761fb4fbc5a1a4c9d51124dd006325afddc8e914124009e9ee4d5c561261057

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

Contents

import {isEmpty, isFunction} from '../utils';

export default function(instance) {
  instance.registerHelper('if', function(conditional, options) {
    if (isFunction(conditional)) { conditional = conditional.call(this); }

    // Default behavior is to render the positive path if the value is truthy and not empty.
    // The `includeZero` option may be set to treat the condtional as purely not empty based on the
    // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
    if ((!options.hash.includeZero && !conditional) || isEmpty(conditional)) {
      return options.inverse(this);
    } else {
      return options.fn(this);
    }
  });

  instance.registerHelper('unless', function(conditional, options) {
    return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});
  });
}

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/handlebars/lib/handlebars/helpers/if.js
locomotivecms-3.4.0 app/javascript/node_modules/handlebars/lib/handlebars/helpers/if.js
lanes-0.8.0 node_modules/handlebars/lib/handlebars/helpers/if.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/handlebars/lib/handlebars/helpers/if.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/handlebars/lib/handlebars/helpers/if.js