-
Notifications
You must be signed in to change notification settings - Fork 3
/
categories.js
99 lines (85 loc) · 2.58 KB
/
categories.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* JSdoc plugin that allows categorization of classes
*/
exports.defineTags = function(dictionary) {
dictionary.defineTag('category', {
mustHaveValue: true,
onTagged: function(doclet, tag) {
if(env.conf.categoryList.indexOf(tag.value) !== -1)
{
doclet.category = tag.value.split('/');
doclet.categoryString = tag.value;
doclet.categoryNestingLevel = doclet.category.length - 1;
}
else
{
console.error('ERROR Undefined category "' + tag.value + '"');
throw 'Undefined category';
}
}
});
};
exports.handlers = {
parseBegin: function() {
loadConfiguration();
}
};
exports.processCategories = function (categories)
{
return processCats(JSON.parse(JSON.stringify(categories)));
};
function processCats (categories, level, parent)
{
if(!level)
{
parent = "";
level = 1;
}
var processedCats = {};
for (var category in categories)
{
if(categories.hasOwnProperty(category) && category.indexOf(parent) === 0 && category.split('/').length == level)
{
// Determine category name at this level
var catName;
if(level > 1)
{
var splitCat = category.split('/');
catName = splitCat[splitCat.length - 1];
}
else
{
catName = category;
}
// Copy data of the category
var categoryData = categories[category];
var newCategoryObject = {};
for(key in categoryData)
{
if(categoryData.hasOwnProperty(key))
{
newCategoryObject[key] = categoryData[key];
}
}
processedCats[catName] = newCategoryObject;
// Recurse into next level
delete categories[category]; // To speed up the process
var children = processCats(categories, level + 1, category);
if (Object.keys(children).length) processedCats[catName].children = children;
}
}
return processedCats;
}
function loadConfiguration () {
try
{
var fs = require('jsdoc/fs');
var confFileContents = fs.readFileSync(env.conf.categoryfile, 'utf8');
env.conf.categories = JSON.parse( (confFileContents || "{}" ) );
env.conf.categoryList = Object.keys(env.conf.categories);
}
catch (e)
{
throw 'Could not load category file';
}
}