aboutsummaryrefslogtreecommitdiff
path: root/node_modules/handlebars/lib/handlebars/helpers/with.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/handlebars/lib/handlebars/helpers/with.js')
-rw-r--r--node_modules/handlebars/lib/handlebars/helpers/with.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/node_modules/handlebars/lib/handlebars/helpers/with.js b/node_modules/handlebars/lib/handlebars/helpers/with.js
new file mode 100644
index 000000000..7418cd066
--- /dev/null
+++ b/node_modules/handlebars/lib/handlebars/helpers/with.js
@@ -0,0 +1,24 @@
+import {appendContextPath, blockParams, createFrame, 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;
+ if (options.data && options.ids) {
+ data = createFrame(options.data);
+ data.contextPath = appendContextPath(options.data.contextPath, options.ids[0]);
+ }
+
+ return fn(context, {
+ data: data,
+ blockParams: blockParams([context], [data && data.contextPath])
+ });
+ } else {
+ return options.inverse(this);
+ }
+ });
+}