forked from prose/prose
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplates.js
35 lines (29 loc) · 815 Bytes
/
templates.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
var fs = require('fs');
var _ = require('underscore');
var paths = require('./dist/templates')
// Builds html partials into a distributable object to keep index.html clean
var templates = paths.reduce(function(memo, file) {
var val = _.template(file.html, {variable: 'data'})
var dir = file.dir;
var id = file.id;
if (dir[0].length > 1) {
function assign(obj, arr, value) {
var lastIndex = arr.length - 1;
for (var i = 0; i < lastIndex; ++ i) {
var key = arr[i];
if (!(key in obj)) {
obj[key] = {}
}
obj = obj[key];
}
obj[arr[lastIndex]] = value;
}
dir.push(id);
assign(memo, dir, val);
} else {
// This file is contained in the root dir
memo[id] = val;
}
return memo;
}, {});
module.exports = templates;