forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.js
74 lines (63 loc) · 1.41 KB
/
misc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
var utils = require('./utils');
/**
* Expose `helpers`
*/
var helpers = module.exports;
/**
* Returns the first value if defined, otherwise the "default" value is returned.
*
* @param {any} `value`
* @param {any} `defaultValue`
* @return {String}
* @alias .or
* @api public
*/
helpers.default = function(value, defaultValue) {
return value == null
? defaultValue
: value;
};
/**
* Return the given value of `prop` from `this.options`. Given the context `{options: {a: {b: {c: 'ddd'}}}}`
*
* ```handlebars
* {{option "a.b.c"}}
* <!-- results => `ddd` -->
* ```
*
* @param {String} `prop`
* @return {any}
* @api public
*/
helpers.option = function(prop) {
var opts = (this && this.options) || {};
return utils.get(opts, prop);
};
/**
* Block helper that renders the block without taking any arguments.
*
* @param {Object} `options`
* @return {String}
* @block
* @api public
*/
helpers.noop = function(options) {
return options.fn(this);
};
/**
* Block helper that builds the context for the block
* from the options hash.
*
* @param {Object} `options` Handlebars provided options object.
* @contributor Vladimir Kuznetsov <https://github.com/mistakster>
* @block
* @api public
*/
helpers.withHash = function(options) {
if (options.hash && Object.keys(options.hash).length) {
return options.fn(options.hash);
} else {
return options.inverse(this);
}
};