-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
145 lines (125 loc) · 3.7 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Only a test and example plugin. It demonstrates the usage of the apidoc hook system.
*
* Hook overview: https://github.com/apidoc/apidoc-core/hooks.md
*/
var app = {};
module.exports = {
init: function(_app) {
app = _app;
//
// Hooks
//
app.addHook('parser-find-elements', parserFindElements);
app.addHook('parser-find-element-apifoo', parserFindElementApiFoo);
// Hooks with priority
// Default is 100, you should select intervals in 10 steps.
// Priority is usefull to execute something before or after other plugins
// or overwrite their behavior.
// Example if 2 Plugins have the same priority:
// Both have priority 50 so Old will be ignored and overwritten with New
app.addHook('parser-find-element-apipriority', parserFindElementApiPriorityOld, 50);
app.addHook('parser-find-element-apipriority', parserFindElementApiPriorityNew, 50);
// Earlier will be executed first (priority 40)
// then New (from above with prio 50)
// and Later at last (60)
app.addHook('parser-find-element-apipriority', parserFindElementApiPriorityLater, 60);
app.addHook('parser-find-element-apipriority', parserFindElementApiPriorityEarlier, 40);
//
// Add Parsers (!!! experimental !!!)
//
app.parsers.apitest = {
parse : parseTest,
path : 'local',
method : 'insert'
};
app.parsers.apifoo = {
parse : parseFoo,
path : 'local',
method : 'insert'
};
app.parsers.apipriority = {
parse : parsePriority,
path : 'local',
method : 'insert'
};
}
};
/**
* Replace all current elements.
*/
function parserFindElements(elements, element, block, filename) {
// Here you can do something with all elements
if ( element.name === 'apitest' ) {
// Remove last
elements.pop();
// Do something.
element.content = 'Test is replaced!';
// Add new
elements.push(element);
}
return elements;
}
/**
* A specific element.
*/
function parserFindElementApiFoo(element, block, filename) {
// Here you can do something with one element
element.content = 'Foo is replaced!';
return element;
}
/**
* Old is never executed.
*/
function parserFindElementApiPriorityOld(element, block, filename) {
element.content = 'Not executed cause parserFindElementPriorityNew overwrite it.';
return element;
}
/**
* New will be executed.
*/
function parserFindElementApiPriorityNew(element, block, filename) {
element.content = element.content + ' New is executed.';
return element;
}
/**
* Earlier will be executed.
*/
function parserFindElementApiPriorityEarlier(element, block, filename) {
element.content = 'Earlier is executed.';
return element;
}
/**
* Later will be executed.
*/
function parserFindElementApiPriorityLater(element, block, filename) {
element.content = element.content + ' Later is executed.';
return element;
}
/**
* Simple parser. Add test to tree.
* Examples: https://github.com/apidoc/apidoc-core/tree/master/lib/parsers
*/
function parseTest(content) {
return {
test: content
};
}
/**
* Simple parser. Add foo to tree.
* Examples: https://github.com/apidoc/apidoc-core/tree/master/lib/parsers
*/
function parseFoo(content) {
return {
foo: content
};
}
/**
* Simple parser. Add priority to tree.
* Examples: https://github.com/apidoc/apidoc-core/tree/master/lib/parsers
*/
function parsePriority(content) {
return {
priority: content
};
}