-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata.js
More file actions
47 lines (40 loc) · 871 Bytes
/
data.js
File metadata and controls
47 lines (40 loc) · 871 Bytes
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
'use strict';
var debug = require('../debug');
var utils = require('../utils');
/**
* Define data to be used for rendering templates.
*
* ```sh
* $ app --data=foo:bar
* # {foo: 'bar'}
*
* $ app --data=foo.bar:baz
* # {foo: {bar: 'baz'}}
*
* $ app --data=foo:bar,baz
* # {foo: ['bar', 'baz']}}
* ```
* @name data
* @api public
*/
module.exports = function(app, base) {
return function(val, key, config, next) {
debug.field(key, val);
if (utils.show(val)) {
console.log(utils.formatValue(app.cache.data));
next();
return;
}
if (typeof app.data === 'function') {
app.data(val);
} else {
for (var prop in val) {
app.emit('data', prop, val[prop]);
}
app.cache.data = utils.merge({}, app.cache.data, val);
val = app.cache.data;
}
config[key] = val;
next();
};
};