-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (26 loc) · 1007 Bytes
/
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
"use strict";
var DataURI = require('datauri'),
hogan = require('hogan.js'),
path = require('path'),
fs = require('fs');
DataURI.prototype.templateAdapter = function (templateContent, param, engine) {
engine = engine || hogan;
if (!param || typeof param !== 'function') {
var template = engine.compile(templateContent);
return template.render.bind(template);
}
return param.bind(param, templateContent);
};
DataURI.prototype.template = function () {
var data = (arguments.length > 2) ? arguments[2] : arguments[1],
templateEngine = this.templateAdapter(
fs.readFileSync(arguments[0], 'utf-8'),
arguments[1],
(arguments.length > 2) && arguments[1]
);
data = data || {};
data.dataURISchema = this.content;
data.classNameSuffix = path.basename(this.fileName, path.extname(this.fileName));
return templateEngine(data);
};
module.exports = DataURI;