UNPKG

888 BJavaScriptView Raw
1var fs = require('fs'),
2 path = require('path');
3
4module.exports = function(app, basepath, encoding) {
5 var ret = {};
6
7 encoding = encoding || 'utf8';
8 basepath = (basepath) ? path.normalize(basepath) : null;
9
10 ret.resolve = function(to, from) {
11 if (!app.fis){
12 throw new Error('yog-swig need load fis resource api');
13 }
14
15 var resolve = app.fis.resolve(to);
16 return path.resolve(basepath, resolve ? resolve : to);
17 };
18
19 ret.load = function(identifier, cb) {
20 if (!fs || (cb && !fs.readFile) || !fs.readFileSync) {
21 throw new Error('Unable to find file ' + identifier + ' because there is no filesystem to read from.');
22 }
23
24 if (cb) {
25 fs.readFile(identifier, encoding, cb);
26 return;
27 }
28 return fs.readFileSync(identifier, encoding);
29 };
30
31 return ret;
32};
\No newline at end of file