summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/helpers/with.js
blob: bb352c5454b8e402983d2f7969286939602b2c94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {isEmpty, isFunction} from '../utils';

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

    let fn = options.fn;

    if (!isEmpty(context)) {
      let data = options.data;

      return fn(context, {
        data: data,
        blockParams: [context]
      });
    } else {
      return options.inverse(this);
    }
  });
}