-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (52 loc) · 1.69 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
/**
* Created by Sayed on 15-06-2017.
* This file will be invoked when someone loads the plugin
*/
var htmlTemplate = require('angular-template');
var juice = require('juice');
var fs = require('fs');
var defTemplate = '<div></div>';
module.exports = {
html: {
options: {
prefix: 'ng',
//extension: 'html',//not native to angular-template
includeDirs: [__dirname+'/mails/']
},
setOptions: function (options) {
this.options = options;
},
load: function (html, data, options) {
data = data || {};
options = options || this.options;
defTemplate = htmlTemplate(html, data, options);
return defTemplate;
}
},
//using juice: https://github.com/Automattic/juice
css: {
options: {
},
config: function (options) {
this.options = options;
},
add: function (css, html) {
html = html || defTemplate;
if(css.toString().match(/\.css$/i)) return this.addCssFile(css, html);
css = css.indexOf('<style>')>=0 ?css :'<style>'+css+'</style>';
var result = juice(css+''+html);
defTemplate = result;
return result;
},
addCssFile: function (filePath, html) {
console.log('adding css from file:', filePath);
var css = fs.readFileSync(filePath).toString();
return this.add(css, html);
},
document: function (cheerioDoc, options) {
options = options || this.options;
defTemplate = juice.juiceResources(cheerioDoc, options);
return defTemplate;
}
}
};