-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.js
79 lines (59 loc) · 1.82 KB
/
instance.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
68
69
70
71
72
73
74
75
76
77
78
79
var async = require('async');
var findSite = require('./instance/find-site');
var reduceSiteData = require('./instance/reduce-site-data');
var Instance = function (options) {
options = options || {};
this.sites = options.sites;
};
var findSiteByDomain = function (domain) {
var site = findSite.bind(this)(function (site) {
return site.domain == domain;
});
if(!site) {
throw new Error('Attempted to find nonexistent site ' + domain);
}
return site;
};
Instance.prototype.siteExists = function (domain) {
var siteExists = true;
try {
findSiteByDomain.bind(this)(domain);
} catch (e) {
return false;
}
return siteExists;
};
Instance.prototype.getAssetsPath = function (domain) {
if (findSiteByDomain.bind(this)(domain)) {
return findSiteByDomain.bind(this)(domain).paths.assets;
}
};
Instance.prototype.getTemplatesPath = function (domain) {
if (findSiteByDomain.bind(this)(domain)) {
return findSiteByDomain.bind(this)(domain).paths.templates;
}
};
Instance.prototype.getPluginsPath = function (domain) {
if (findSiteByDomain.bind(this)(domain)) {
return findSiteByDomain.bind(this)(domain).paths.plugins;
}
};
Instance.prototype.getContentMaps = function (callback) {
return reduceSiteData.bind(this)('getContentMaps', callback);
};
Instance.prototype.getRouteMaps = function (callback) {
return reduceSiteData.bind(this)('getRouteMaps', callback);
};
Instance.prototype.getRewriteMaps = function (callback) {
return reduceSiteData.bind(this)('getRewriteMaps', callback);
};
Instance.prototype.getTemplateSources = function (domain, callback) {
var site = findSite.bind(this)(function (site) {
return site.domain == domain;
});
if(!site) {
return callback('Site not found', null);
}
return site.getTemplateSources(callback);
};
module.exports = Instance;