e534a911f3
Prettier v2 has the following breaking changes: * enforces spaces between `function` and params * enforces trailing commas by default
27 lines
616 B
JavaScript
27 lines
616 B
JavaScript
import { Exception } from '@handlebars/parser';
|
|
import { isEmpty, isFunction } from '../utils';
|
|
|
|
export default function (instance) {
|
|
instance.registerHelper('with', function (context, options) {
|
|
if (arguments.length != 2) {
|
|
throw new Exception('#with requires exactly one argument');
|
|
}
|
|
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);
|
|
}
|
|
});
|
|
}
|