-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadtemplate.js
61 lines (51 loc) · 1.84 KB
/
loadtemplate.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
/*
* Usage: /default/purchase_confirm/eng - returns template,
*/
exports.loadtemplatehtml = function(templateid, geo){
console.log("Load html Template...");
/*
* Load properties file into template
*/
var velocity = require('velocityjs');
var fs = require('fs');
var PropertiesReader = require('properties-reader');
if (geo == "en")
var properties = PropertiesReader('../templates/emailtemplate.properties'); // eng
else
var properties = PropertiesReader('../templates/emailtemplate_' + geo + '.properties');
var templatefile = "../email.templates/bss.shim/" + templateid + "_html.vm"; // purchase
if(!fs.existsSync(templatefile)) {
console.log("File not found");
return "";
}
var emailVM = fs.readFileSync(templatefile, 'utf8');
var asts = velocity.parse(emailVM);
var macros = null;
var results = (new velocity.Compile(asts)).render(properties._properties,macros);
console.log(results);
return results;
};
exports.loadtemplatetext = function(templateid, geo){
console.log("Load text Template...");
/*
* Load properties file into template
*/
var velocity = require('velocityjs');
var fs = require('fs');
var PropertiesReader = require('properties-reader');
if (geo == "en")
var properties = PropertiesReader('../templates/emailtemplate.properties'); // eng
else
var properties = PropertiesReader('../templates/emailtemplate_' + geo + '.properties');
var templatefile = "../email.templates/bss.shim/" + templateid + "_text.vm"; // purchase
if(!fs.existsSync(templatefile)) {
console.log("File not found");
return "";
}
var emailVM = fs.readFileSync(templatefile, 'utf8');
var asts = velocity.parse(emailVM);
var macros = null;
var results = (new velocity.Compile(asts)).render(properties._properties,macros);
console.log(results);
return results;
};