-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.js
65 lines (48 loc) · 1.71 KB
/
utils.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
var dceConfig = require('../../dce-config.js'),
_ = require('underscore'),
fs = require('fs');
exports.getFileFromSlug = function(slug) {
var fileJSON = false,
file = docpadInstance.getFile({url: slug});
if (file) {
fileJSON = file.toJSON();
}
return fileJSON;
};
exports.getDefaultCollectionName = function() {
var defaultCollectionName = false;
if (_.isEmpty(dceConfig.collectionsAvailableForEdit) === false) {
defaultCollectionName = dceConfig.collectionsAvailableForEdit[0];
}
return defaultCollectionName;
};
exports.getAvailableCollections = function() {
var collections = null;
if (_.isEmpty(dceConfig.collectionsAvailableForEdit) === false) {
collections = {};
//Track down the items for the requested collections
for (var i=0; i<dceConfig.collectionsAvailableForEdit.length; i++) {
var collectionName = dceConfig.collectionsAvailableForEdit[i];
collections[collectionName] = getCollectionItems(collectionName);
}
}
return collections;
};
exports.getCollectionList = function() {
var collectionList = [];
if (_.isEmpty(dceConfig.collectionsAvailableForEdit) === false) {
collectionList = dceConfig.collectionsAvailableForEdit;
}
return collectionList;
};
exports.getCollectionItems = function(collectionName) {
var collectionItemsJSON = null,
collectionItems = docpadInstance.getCollection(collectionName);
if (collectionItems) {
collectionItemsJSON = collectionItems.toJSON();
}
return collectionItemsJSON;
};
exports.trim = function(string) {
return string.replace(/^\s*|\s*$/g, '');
};