-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-parent.js
49 lines (46 loc) · 1.09 KB
/
get-parent.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
/**
* @function getParent
* @parent documentjs.tags.helpers
* @param {Array.<String>} types
* @param {DocProps} scope
* @param {Object.<String,DocProps>} objects
*/
var getParent = function(types, scope, objects){
if(types === "*"){
return scope;
}
while ( scope && scope.type && types.indexOf(scope.type) == -1 ) {
scope = objects[scope.parent];
}
return scope;
};
/**
* @function andName
* @parent documentjs.tags.helpers
* @param {{}} options
* @option {Array|String} parents Allowable parents
* @option {Array.<String>} useName use the name if parent is one of these items
* @option {DocProps} scope
* @option {DocMap} docMap
* @option {String} name
*
*/
getParent.andName = function(options){
var parent = getParent(options.parents, options.scope, options.docMap);
if(!parent) {
return {name: options.name, parent: null}
} else {
if(options.useName.indexOf(parent.type) >= 0) {
return {
name: parent.name + "." + options.name,
parent: parent.name
};
} else {
return {
name: options.name,
parent: parent.name
};
}
}
};
module.exports = getParent;