Files
handlebars.js/lib/handlebars/helpers/with.js
T
Jakob Linskeseder e534a911f3 Upgrade prettier to v2
Prettier v2 has the following breaking changes:
* enforces spaces between `function` and params
* enforces trailing commas by default
2022-10-29 21:49:15 +02:00

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);
}
});
}