1 // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
2 var common = require('./common.js');
3 var classCategory = 'class';
4 var namespaceCategory = 'ns';
6 exports.transform = function (model) {
8 if (!model) return null;
11 handleItem(model, model._gitContribute, model._gitUrlPattern);
13 model.children.forEach(function (item) {
14 handleItem(item, model._gitContribute, model._gitUrlPattern);
19 switch (model.type.toLowerCase()) {
21 model.isNamespace = true;
22 if (model.children) groupChildren(model, namespaceCategory);
30 if (model.children) groupChildren(model, classCategory);
31 model[getTypePropertyName(model.type)] = true;
41 exports.getBookmarks = function (model, ignoreChildren) {
42 if (!model || !model.type || model.type.toLowerCase() === "namespace") return null;
46 if (typeof ignoreChildren == 'undefined' || ignoreChildren === false) {
48 model.children.forEach(function (item) {
49 bookmarks[item.uid] = common.getHtmlId(item.uid);
50 if (item.overload && item.overload.uid) {
51 bookmarks[item.overload.uid] = common.getHtmlId(item.overload.uid);
57 // Reference's first level bookmark should have no anchor
58 bookmarks[model.uid] = "";
62 exports.groupChildren = groupChildren;
63 exports.getTypePropertyName = getTypePropertyName;
64 exports.getCategory = getCategory;
66 function groupChildren(model, category) {
67 if (!model || !model.type) {
70 var typeChildrenItems = getDefinitions(category);
73 model.children.forEach(function (c) {
77 var type = c.type.toLowerCase();
79 if (!grouped.hasOwnProperty(type)) {
82 // special handle for field
83 if (type === "field" && c.syntax) {
84 c.syntax.fieldValue = c.syntax.return;
85 c.syntax.return = undefined;
87 // special handle for property
88 if ((type === "property" || type === "attachedproperty") && c.syntax) {
89 c.syntax.propertyValue = c.syntax.return;
90 c.syntax.return = undefined;
92 // special handle for event
93 if ((type === "event" || type === "attachedevent") && c.syntax) {
94 c.syntax.eventType = c.syntax.return;
95 c.syntax.return = undefined;
97 grouped[type].push(c);
101 for (var key in typeChildrenItems) {
102 if (typeChildrenItems.hasOwnProperty(key) && grouped.hasOwnProperty(key)) {
103 var typeChildrenItem = typeChildrenItems[key];
104 var items = grouped[key];
105 if (items && items.length > 0) {
107 for (var itemKey in typeChildrenItem) {
108 if (typeChildrenItem.hasOwnProperty(itemKey)) {
109 item[itemKey] = typeChildrenItem[itemKey];
112 item.children = items;
118 model.children = children;
121 function getTypePropertyName(type) {
125 var loweredType = type.toLowerCase();
126 var definition = getDefinition(loweredType);
128 return definition.typePropertyName;
134 function getCategory(type) {
135 var classItems = getDefinitions(classCategory);
136 if (classItems.hasOwnProperty(type)) {
137 return classCategory;
140 var namespaceItems = getDefinitions(namespaceCategory);
141 if (namespaceItems.hasOwnProperty(type)) {
142 return namespaceCategory;
147 function getDefinition(type) {
148 var classItems = getDefinitions(classCategory);
149 if (classItems.hasOwnProperty(type)) {
150 return classItems[type];
152 var namespaceItems = getDefinitions(namespaceCategory);
153 if (namespaceItems.hasOwnProperty(type)) {
154 return namespaceItems[type];
159 function getDefinitions(category) {
160 var namespaceItems = {
161 "class": { inClass: true, typePropertyName: "inClass", id: "classes" },
162 "struct": { inStruct: true, typePropertyName: "inStruct", id: "structs" },
163 "interface": { inInterface: true, typePropertyName: "inInterface", id: "interfaces" },
164 "enum": { inEnum: true, typePropertyName: "inEnum", id: "enums" },
165 "delegate": { inDelegate: true, typePropertyName: "inDelegate", id: "delegates" }
168 "constructor": { inConstructor: true, typePropertyName: "inConstructor", id: "constructors" },
169 "field": { inField: true, typePropertyName: "inField", id: "fields" },
170 "property": { inProperty: true, typePropertyName: "inProperty", id: "properties" },
171 "attachedproperty": { inAttachedProperty: true, typePropertyName: "inAttachedProperty", id: "attachedProperties" },
172 "method": { inMethod: true, typePropertyName: "inMethod", id: "methods" },
173 "event": { inEvent: true, typePropertyName: "inEvent", id: "events" },
174 "attachedevent": { inAttachedEvent: true, typePropertyName: "inAttachedEvent", id: "attachedEvents" },
175 "operator": { inOperator: true, typePropertyName: "inOperator", id: "operators" },
176 "eii": { inEii: true, typePropertyName: "inEii", id: "eii" }
178 if (category === 'class') {
181 if (category === 'ns') {
182 return namespaceItems;
184 console.err("category '" + category + "' is not valid.");
188 function handleItem(vm, gitContribute, gitUrlPattern) {
189 // get contribution information
190 vm.docurl = common.getImproveTheDocHref(vm, gitContribute, gitUrlPattern);
191 vm.sourceurl = common.getViewSourceHref(vm, null, gitUrlPattern);
193 // set to null incase mustache looks up
194 vm.summary = vm.summary || null;
195 vm.remarks = vm.remarks || null;
197 vm.sinceTizen = vm.sinceTizen || null;
198 vm.precondition = vm.precondition || null;
199 vm.postcondition = vm.postcondition || null;
200 vm.feature = vm.feature || null;
201 vm.privlevel = vm.privlevel || null;
202 vm.privilege = vm.privilege || null;
204 vm.conceptual = vm.conceptual || null;
205 vm.syntax = vm.syntax || null;
206 vm.implements = vm.implements || null;
207 vm.example = vm.example || null;
208 common.processSeeAlso(vm);
210 // id is used as default template's bookmark
211 vm.id = common.getHtmlId(vm.uid);
212 if (vm.overload && vm.overload.uid) {
213 vm.overload.id = common.getHtmlId(vm.overload.uid);
216 if (vm.supported_platforms) {
217 vm.supported_platforms = transformDictionaryToArray(vm.supported_platforms);
220 if (vm.requirements) {
221 var type = vm.type.toLowerCase();
222 if (type == "method") {
223 vm.requirements_method = transformDictionaryToArray(vm.requirements);
225 vm.requirements = transformDictionaryToArray(vm.requirements);
230 if (shouldHideTitleType(vm)) {
231 vm.hideTitleType = true;
233 vm.hideTitleType = false;
236 if (shouldHideSubtitle(vm)) {
237 vm.hideSubtitle = true;
239 vm.hideSubtitle = false;
243 function shouldHideTitleType(vm) {
244 var type = vm.type.toLowerCase();
245 return ((type === 'namespace' && langs.length == 1 && (langs[0] === 'objectivec' || langs[0] === 'java' || langs[0] === 'c'))
246 || ((type === 'class' || type === 'enum') && langs.length == 1 && langs[0] === 'c'));
249 function shouldHideSubtitle(vm) {
250 var type = vm.type.toLowerCase();
251 return (type === 'class' || type === 'namespace') && langs.length == 1 && langs[0] === 'c';
254 function transformDictionaryToArray(dic) {
256 for (var key in dic) {
257 if (dic.hasOwnProperty(key)) {
258 array.push({ "name": key, "value": dic[key] })