-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
86 lines (83 loc) · 2.58 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
var fileSystem = require("fs");
var handlebars = require("handlebars");
var layouts = require("handlebars-layouts");
var momentHandler = require("handlebars.moment");
var moment = require("moment");
var humanizeDuration = require("humanize-duration");
var gravatar = require("gravatar");
function getPhoto(resume) {
var result = null;
if (resume.basics && resume.basics.email) {
resume.basics.gravatar = gravatar.url(resume.basics.email, {
s: "100",
r: "pg",
d: "mm"
});
}
if (resume.basics.picture || resume.basics.gravatar) {
result = resume.basics.picture ? resume.basics.picture : resume.basics.gravatar;
}
return result;
}
function render(resume) {
// Register helpers
momentHandler.registerHelpers(handlebars);
handlebars.registerHelper("dateRange", function(startDate, endDate, format) {
var result = "";
if (startDate) {
var momentStartDate = moment.utc(startDate);
if (momentStartDate.isValid()) {
result += momentStartDate.format(format) + " - ";
}
if (endDate) {
var momentEndDate = moment.utc(endDate);
if (momentEndDate.isValid()) {
result += momentEndDate.format(format);
}
} else {
result += "Present";
}
} else {
if (endDate) {
var momentEndDate = moment.utc(endDate);
if (momentEndDate.isValid()) {
result += momentEndDate.format(format);
}
} else {
result += "Present";
}
}
return result;
});
handlebars.registerHelper("dateDuration", function(startDate, endDate, options) {
var result = "";
if (startDate) {
var start = moment.utc(startDate);
var end = moment.utc();
if (endDate)
end = moment.utc(endDate);
if (options) {
optionsObject = (JSON.parse(options));
//console.log(optionsObject);
}
result = humanizeDuration(moment.duration(end.diff(start)), optionsObject);
}
return result;
});
handlebars.registerHelper("toLower", function(input) {
return input.toLowerCase();
});
handlebars.registerHelper(layouts(handlebars));
// Register partials
handlebars.registerPartial("layout", fileSystem.readFileSync(__dirname + "/layout.hbs", "utf8"));
// Compile template
var template = fileSystem.readFileSync(__dirname + "/resume.hbs", "utf-8");
// resume object injection
resume.photo = getPhoto(resume);
// Use internal stylesheet
resume.css = fileSystem.readFileSync(__dirname + "/style.css", "utf-8");
return handlebars.compile(template)(resume);
}
module.exports = {
render: render
};