forked from michaelmcmillan/citeproc-node-iojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciteproc-wrapper.js
67 lines (54 loc) · 1.7 KB
/
citeproc-wrapper.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
var fs = require('fs');
var CSL = require('./src/citeproc.js').CSL;
function Citeproc (citations, styleLocation, localeLocation, done) {
// Constructs the wrapper
this.construct = function () {
var self = this;
self.loadStyle(styleLocation, function (err) {
if (err) return done(err);
self.loadLocale(localeLocation, function (err) {
if (err) return done(err);
self.setupSys();
citeproc = new CSL.Engine(sys, style);
done(null, citeproc);
});
});
}
// The internal CSL.Engine object
var citeproc;
// Implements retrieveLocale and retrieveItem
var sys;
// Holds the content of a .csl file
var style;
// All the added references which will be formatted
var citations = citations;
// Holds the content of a locales-*-*.xml file
var locale;
// Rigs up the sys object for the internal citeproc
this.setupSys = function () {
sys = {
retrieveLocale: function (language) {
return locale;
},
retrieveItem: function (id) {
return citations[id];
}
};
}
this.loadLocale = function (file, done) {
fs.readFile(file, function (err, data) {
if (err) return done(err);
locale = data.toString();
return done();
});
}
this.loadStyle = function (file, done) {
fs.readFile(file, function (err, data) {
if (err) return done(err);
style = data.toString();
return done();
});
}
this.construct();
}
module.exports = Citeproc;