-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
65 lines (56 loc) · 1.26 KB
/
utils.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
'use strict';
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
/**
* Lazily required module dependencies
*/
require('extend-shallow', 'extend');
require('gulp-collection', 'collection');
require('is-valid-app', 'isValid');
require('stream-combiner', 'combine');
require('through2', 'through');
require = fn;
/**
* Additional utils
*/
utils.buffer = function() {
var files = [];
return utils.through.obj(function(file, enc, cb) {
files.push(file);
cb();
}, function(cb) {
var stream = this;
files.forEach(function(file) {
stream.push(file);
});
cb();
});
};
utils.listTemplate = function(plural, single) {
return [
`<h1>${plural}</h1>`,
`{{#each ${plural} as |items ${single}|}}`,
` <h2>{{${single}}}</h2>`,
` <ul>`,
` {{#each items as |item|}}`,
` <li>{{item.data.title}}: {{item.relative}}</li>`,
` {{/each}}`,
` </ul>`,
`{{/each}}`
].join('\n');
};
utils.itemTemplate = function(prop) {
return [
`<h1>${prop}: {{${prop}}}</h1>`,
`<ul>`,
` {{#each items as |item|}}`,
` <li>{{item.data.title}}: {{item.relative}}</li>`,
` {{/each}}`,
`</ul>`,
].join('\n');
};
/**
* Expose `utils` modules
*/
module.exports = utils;