This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ManagedReference.common.js
258 lines (227 loc) · 8.31 KB
/
ManagedReference.common.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var common = require('./common.js');
var classCategory = 'class';
var namespaceCategory = 'ns';
exports.transform = function (model) {
if (!model) return null;
langs = model.langs;
handleItem(model, model._gitContribute, model._gitUrlPattern);
if (model.children) {
model.children.forEach(function (item) {
handleItem(item, model._gitContribute, model._gitUrlPattern);
});
}
if (model.type) {
switch (model.type.toLowerCase()) {
case 'namespace':
model.isNamespace = true;
if (model.children) groupChildren(model, namespaceCategory);
model[getTypePropertyName(model.type)] = true;
break;
case 'class':
case 'interface':
case 'struct':
case 'delegate':
case 'enum':
model.isClass = true;
if (model.children) groupChildren(model, classCategory);
model[getTypePropertyName(model.type)] = true;
break;
default:
break;
}
}
return model;
}
exports.getBookmarks = function (model, ignoreChildren) {
if (!model || !model.type || model.type.toLowerCase() === "namespace") return null;
var bookmarks = {};
if (typeof ignoreChildren == 'undefined' || ignoreChildren === false) {
if (model.children) {
model.children.forEach(function (item) {
bookmarks[item.uid] = common.getHtmlId(item.uid);
if (item.overload && item.overload.uid) {
bookmarks[item.overload.uid] = common.getHtmlId(item.overload.uid);
}
});
}
}
// Reference's first level bookmark should have no anchor
bookmarks[model.uid] = "";
return bookmarks;
}
exports.groupChildren = groupChildren;
exports.getTypePropertyName = getTypePropertyName;
exports.getCategory = getCategory;
function groupChildren(model, category) {
if (!model || !model.type) {
return;
}
var typeChildrenItems = getDefinitions(category);
var grouped = {};
model.children.forEach(function (c) {
if (c.isEii) {
var type = "eii";
} else {
var type = c.type.toLowerCase();
}
if (!grouped.hasOwnProperty(type)) {
grouped[type] = [];
}
// special handle for field
if (type === "field" && c.syntax) {
c.syntax.fieldValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for property
if ((type === "property" || type === "attachedproperty") && c.syntax) {
c.syntax.propertyValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for event
if ((type === "event" || type === "attachedevent") && c.syntax) {
c.syntax.eventType = c.syntax.return;
c.syntax.return = undefined;
}
grouped[type].push(c);
})
var children = [];
for (var key in typeChildrenItems) {
if (typeChildrenItems.hasOwnProperty(key) && grouped.hasOwnProperty(key)) {
var typeChildrenItem = typeChildrenItems[key];
var items = grouped[key];
if (items && items.length > 0) {
var item = {};
for (var itemKey in typeChildrenItem) {
if (typeChildrenItem.hasOwnProperty(itemKey)) {
item[itemKey] = typeChildrenItem[itemKey];
}
}
item.children = items;
children.push(item);
}
}
}
model.children = children;
}
function getTypePropertyName(type) {
if (!type) {
return undefined;
}
var loweredType = type.toLowerCase();
var definition = getDefinition(loweredType);
if (definition) {
return definition.typePropertyName;
}
return undefined;
}
function getCategory(type) {
var classItems = getDefinitions(classCategory);
if (classItems.hasOwnProperty(type)) {
return classCategory;
}
var namespaceItems = getDefinitions(namespaceCategory);
if (namespaceItems.hasOwnProperty(type)) {
return namespaceCategory;
}
return undefined;
}
function getDefinition(type) {
var classItems = getDefinitions(classCategory);
if (classItems.hasOwnProperty(type)) {
return classItems[type];
}
var namespaceItems = getDefinitions(namespaceCategory);
if (namespaceItems.hasOwnProperty(type)) {
return namespaceItems[type];
}
return undefined;
}
function getDefinitions(category) {
var namespaceItems = {
"namespace": { inNamespace: true, typePropertyName: "inNamespace", id: "namespaces" },
"class": { inClass: true, typePropertyName: "inClass", id: "classes" },
"struct": { inStruct: true, typePropertyName: "inStruct", id: "structs" },
"interface": { inInterface: true, typePropertyName: "inInterface", id: "interfaces" },
"enum": { inEnum: true, typePropertyName: "inEnum", id: "enums" },
"delegate": { inDelegate: true, typePropertyName: "inDelegate", id: "delegates" }
};
var classItems = {
"constructor": { inConstructor: true, typePropertyName: "inConstructor", id: "constructors" },
"field": { inField: true, typePropertyName: "inField", id: "fields" },
"property": { inProperty: true, typePropertyName: "inProperty", id: "properties" },
"attachedproperty": { inAttachedProperty: true, typePropertyName: "inAttachedProperty", id: "attachedProperties" },
"method": { inMethod: true, typePropertyName: "inMethod", id: "methods" },
"event": { inEvent: true, typePropertyName: "inEvent", id: "events" },
"attachedevent": { inAttachedEvent: true, typePropertyName: "inAttachedEvent", id: "attachedEvents" },
"operator": { inOperator: true, typePropertyName: "inOperator", id: "operators" },
"eii": { inEii: true, typePropertyName: "inEii", id: "eii" }
};
if (category === 'class') {
return classItems;
}
if (category === 'ns') {
return namespaceItems;
}
console.err("category '" + category + "' is not valid.");
return undefined;
}
function handleItem(vm, gitContribute, gitUrlPattern) {
// get contribution information
vm.docurl = common.getImproveTheDocHref(vm, gitContribute, gitUrlPattern);
vm.sourceurl = common.getViewSourceHref(vm, null, gitUrlPattern);
// set to null incase mustache looks up
vm.summary = vm.summary || null;
vm.remarks = vm.remarks || null;
vm.conceptual = vm.conceptual || null;
vm.syntax = vm.syntax || null;
vm.implements = vm.implements || null;
vm.example = vm.example || null;
common.processSeeAlso(vm);
// id is used as default template's bookmark
vm.id = common.getHtmlId(vm.uid);
if (vm.overload && vm.overload.uid) {
vm.overload.id = common.getHtmlId(vm.overload.uid);
}
if (vm.supported_platforms) {
vm.supported_platforms = transformDictionaryToArray(vm.supported_platforms);
}
if (vm.requirements) {
var type = vm.type.toLowerCase();
if (type == "method") {
vm.requirements_method = transformDictionaryToArray(vm.requirements);
} else {
vm.requirements = transformDictionaryToArray(vm.requirements);
}
}
if (vm && langs) {
if (shouldHideTitleType(vm)) {
vm.hideTitleType = true;
} else {
vm.hideTitleType = false;
}
if (shouldHideSubtitle(vm)) {
vm.hideSubtitle = true;
} else {
vm.hideSubtitle = false;
}
}
function shouldHideTitleType(vm) {
var type = vm.type.toLowerCase();
return ((type === 'namespace' && langs.length == 1 && (langs[0] === 'objectivec' || langs[0] === 'java' || langs[0] === 'c'))
|| ((type === 'class' || type === 'enum') && langs.length == 1 && langs[0] === 'c'));
}
function shouldHideSubtitle(vm) {
var type = vm.type.toLowerCase();
return (type === 'class' || type === 'namespace') && langs.length == 1 && langs[0] === 'c';
}
function transformDictionaryToArray(dic) {
var array = [];
for (var key in dic) {
if (dic.hasOwnProperty(key)) {
array.push({ "name": key, "value": dic[key] })
}
}
return array;
}
}