forked from stay-sharp/hosts_for_google_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-helper.js
27 lines (27 loc) · 873 Bytes
/
generate-helper.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
module.exports = function (generateEntry, generateComment) {
return function (data) {
var output = '', blocks = [];
output += generateComment(data.header) + '\n';
data.hosts.forEach(function (block) {
var tmp = '';
tmp += generateComment(data.block_header.replace(/{NAME}/g, block.name));
block.items.forEach(function (item) {
if (item.comment != undefined) {
tmp += generateComment(item.comment);
} else {
if (item.domain !== undefined) tmp += generateEntry(item.ip, item.domain) + '\n';
else {
item.domains.forEach(function (domain) {
tmp += generateEntry(item.ip, domain) + '\n';
});
}
}
});
tmp += generateComment(data.block_footer.replace(/{NAME}/g, block.name));
blocks.push(tmp);
});
output += blocks.join('\n');
output += '\n' + generateComment(data.footer);
return output;
};
};