forked from rkt2spc/jsonresume-theme-rocketspacer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (34 loc) · 1.2 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
// Dependencies
const path = require('path');
const fs = require('fs');
const ejs = require('ejs');
// Constants
const NODE_ENV = process.env.NODE_ENV || 'development';
// Helpers
const helpers = require('./helpers');
// Production render method
const productionRender = (() => {
// Pre-building template
const filename = path.join(__dirname, 'views/resume.ejs');
const template = ejs.compile(fs.readFileSync(filename, 'utf8'), {
filename : filename,
context : Object.assign({}, helpers),
});
const css = fs.readFileSync(path.join(__dirname, 'assets/stylesheets/style.css'), 'utf8');
// Return function that use the pre-built template
return (resume) => template({ css, resume });
})();
// Development render method
const developmentRender = (resume) => {
const filename = path.join(__dirname, 'views/resume.ejs');
const template = ejs.compile(fs.readFileSync(filename, 'utf8'), {
filename : filename,
context : Object.assign({}, helpers),
});
const css = fs.readFileSync(path.join(__dirname, 'assets/stylesheets/style.css'), 'utf8');
return template({ css, resume });
};
// Exports
module.exports = {
render: NODE_ENV !== 'development' ? productionRender : developmentRender,
};