diff --git a/.github/workflows/api-docs.yml b/.github/workflows/api-docs.yml index 1c9c51cee..c3b3cc417 100644 --- a/.github/workflows/api-docs.yml +++ b/.github/workflows/api-docs.yml @@ -26,14 +26,15 @@ jobs: dotnet-version: 7.0 dotnet-quality: 'ga' - - name: Setup DocFX - uses: crazy-max/ghaction-chocolatey@v2 - with: - args: install docfx + # - name: Setup DocFX + # uses: crazy-max/ghaction-chocolatey@v2 + # with: + # args: install docfx - name: DocFX Build working-directory: docfx run: | + dotnet tool install -g docfx rm ../docs -Recurse -Force -ErrorAction SilentlyContinue rm ../api -Recurse -Force -ErrorAction SilentlyContinue $env:DOCFX_SOURCE_BRANCH_NAME="${{ github.ref_name }}" diff --git a/Terminal.sln b/Terminal.sln index 58a9ace1a..4d1712f8e 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -15,6 +15,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E143FB1F-0B88-48CB-9086-72CDCECFCD22}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore + .github\workflows\api-docs.yml = .github\workflows\api-docs.yml .github\CODEOWNERS = .github\CODEOWNERS CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md CONTRIBUTING.md = CONTRIBUTING.md diff --git a/docfx/build.ps1 b/docfx/build.ps1 index b40d968ee..a4a22f548 100644 --- a/docfx/build.ps1 +++ b/docfx/build.ps1 @@ -5,6 +5,8 @@ $prevPwd = $PWD; Set-Location -ErrorAction Stop -LiteralPath $PSScriptRoot try { $PWD # output the current location + dotnet tool update -g docfx + dotnet build --configuration Release ../Terminal.sln rm ../docs -Recurse -Force -ErrorAction SilentlyContinue diff --git a/docfx/docfx.json b/docfx/docfx.json index bccdb04f7..ac15efdd1 100644 --- a/docfx/docfx.json +++ b/docfx/docfx.json @@ -91,7 +91,7 @@ "globalMetadata": { "_appTitle": "Terminal.Gui v2", "_appName": "Terminal.Gui v2", - "_appFaviconPath": "images/favicon.png", + "_appFaviconPath": "images/icon48.png", "_appLogoPath": "images/logo.png", "_appFooter": "Terminal.Gui - Part of the gui-cs Organization", "_enableSearch": true, @@ -108,6 +108,7 @@ }, "_gitUrlPattern": "github" }, + "markdownEngineName": "markdig", "globalMetadataFiles": [], "fileMetadataFiles": [], "postProcessors": ["ExtractSearchIndex"], diff --git a/docfx/plugins/memberpage-extras/ManagedReference.extension.js b/docfx/plugins/memberpage-extras/ManagedReference.extension.js new file mode 100644 index 000000000..2e43f43fd --- /dev/null +++ b/docfx/plugins/memberpage-extras/ManagedReference.extension.js @@ -0,0 +1,33 @@ +// 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('./ManagedReference.common.js'); + +exports.preTransform = function (model) { + transform(model); + + function transform(item) { + if (item.children) item.children.forEach(function(i) { + transform(i); + }); + } + + return model; +} + +exports.postTransform = function (model) { + var type = model.type.toLowerCase(); + var category = common.getCategory(type); + if (category == 'class') { + var typePropertyName = common.getTypePropertyName(type); + if (typePropertyName) { + model[typePropertyName] = true; + } + if (model.children && model.children.length > 0) { + model.isCollection = true; + common.groupChildren(model, 'class'); + } else { + model.isItem = true; + } + } + + return model; +} \ No newline at end of file diff --git a/docfx/plugins/memberpage-extras/toc.html.js b/docfx/plugins/memberpage-extras/toc.html.js new file mode 100644 index 000000000..a24a5b260 --- /dev/null +++ b/docfx/plugins/memberpage-extras/toc.html.js @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. +exports.transform = function (model) { + var groupNames = { + "constructor": { key: "constructorsInSubtitle" }, + "field": { key: "fieldsInSubtitle" }, + "property": { key: "propertiesInSubtitle" }, + "method": { key: "methodsInSubtitle" }, + "event": { key: "eventsInSubtitle" }, + "operator": { key: "operatorsInSubtitle" }, + "eii": { key: "eiisInSubtitle" }, + }; + + groupChildren(model); + transformItem(model, 1); + return model; + + function groupChildren(item) { + if (!item || !item.items || item.items.length == 0) { + return; + } + var grouped = {}; + var items = []; + item.items.forEach(function (element) { + groupChildren(element); + if (element.type) { + var type = element.isEii ? "eii" : element.type.toLowerCase(); + if (!grouped.hasOwnProperty(type)) { + if (!groupNames.hasOwnProperty(type)) { + groupNames[type] = { + name: element.type + }; + console.log(type + " is not predefined type, use its type name as display name.") + } + grouped[type] = []; + } + grouped[type].push(element); + } else { + items.push(element); + } + }, this); + + // With order defined in groupNames + for (var key in groupNames) { + if (groupNames.hasOwnProperty(key) && grouped.hasOwnProperty(key)) { + items.push({ + name: model.__global[groupNames[key].key] || groupNames[key].name, + items: grouped[key] + }) + } + } + + item.items = items; + } + + function transformItem(item, level) { + // set to null in case mustache looks up + item.topicHref = item.topicHref || null; + item.tocHref = item.tocHref || null; + item.name = item.name || null; + + item.level = level; + + // Add word break opportunities before dots + + if (item.name) + item.name = item.name.replace(/\./g, "\u200B."); + + if (item.items && item.items.length > 0) { + item.leaf = false; + var length = item.items.length; + for (var i = 0; i < length; i++) { + transformItem(item.items[i], level + 1); + }; + } else { + item.items = []; + item.leaf = true; + } + } +} \ No newline at end of file diff --git a/docfx/plugins/memberpage.2.59.4/ManagedReference.extension.js b/docfx/plugins/memberpage.2.59.4/ManagedReference.extension.js new file mode 100644 index 000000000..770c2938e --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/ManagedReference.extension.js @@ -0,0 +1,20 @@ +// 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('./ManagedReference.common.js'); + +exports.postTransform = function (model) { + var type = model.type.toLowerCase(); + var category = common.getCategory(type); + if (category == 'class') { + var typePropertyName = common.getTypePropertyName(type); + if (typePropertyName) { + model[typePropertyName] = true; + } + if (model.children && model.children.length > 0) { + model.isCollection = true; + common.groupChildren(model, 'class'); + } else { + model.isItem = true; + } + } + return model; +} \ No newline at end of file diff --git a/docfx/plugins/memberpage.2.59.4/ManagedReference.overwrite.js b/docfx/plugins/memberpage.2.59.4/ManagedReference.overwrite.js new file mode 100644 index 000000000..9e6f29e88 --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/ManagedReference.overwrite.js @@ -0,0 +1,10 @@ +// 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('./ManagedReference.common.js'); + +exports.getOptions = function (model) { + var ignoreChildrenBookmarks = model._splitReference && model.type && common.getCategory(model.type) === 'ns'; + + return { + "bookmarks": common.getBookmarks(model, ignoreChildrenBookmarks) + }; +} \ No newline at end of file diff --git a/docfx/plugins/memberpage.2.59.4/partials/class.tmpl.partial b/docfx/plugins/memberpage.2.59.4/partials/class.tmpl.partial new file mode 100644 index 000000000..e52fa611d --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/partials/class.tmpl.partial @@ -0,0 +1,59 @@ +{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} + +{{>partials/class.header}} +{{#children}} +{{#overload}} + +{{/overload}} +

{{>partials/classSubtitle}}

+{{#children.0}} + + + + + + + + + {{/children.0}} + {{#children}} + + + + + {{/children}} + {{#children.0}} + +
{{__global.name}}{{__global.description}}
+ + {{{summary}}}
+{{/children.0}} +{{/children}} +{{#extensionMethods.0}} +

{{__global.extensionMethods}}

+{{/extensionMethods.0}} +{{#extensionMethods}} +
+ {{#definition}} + + {{/definition}} + {{^definition}} + + {{/definition}} +
+{{/extensionMethods}} +{{#seealso.0}} +

{{__global.seealso}}

+
+{{/seealso.0}} +{{#seealso}} + {{#isCref}} +
{{{type.specName.0.value}}}
+ {{/isCref}} + {{^isCref}} +
{{{url}}}
+ {{/isCref}} +{{/seealso}} +{{#seealso.0}} +
+{{/seealso.0}} diff --git a/docfx/plugins/memberpage.2.59.4/partials/collection.tmpl.partial b/docfx/plugins/memberpage.2.59.4/partials/collection.tmpl.partial new file mode 100644 index 000000000..9bfb661ad --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/partials/collection.tmpl.partial @@ -0,0 +1,234 @@ +{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} + +

{{>partials/title}}

+
{{{summary}}}
+
{{{conceptual}}}
+ +{{#children}} +{{#children}} +{{^_disableContribution}} +{{#docurl}} + + | + {{__global.improveThisDoc}} +{{/docurl}} +{{#sourceurl}} + + {{__global.viewSource}} +{{/sourceurl}} +{{/_disableContribution}} +{{#overload}} + +{{/overload}} +

{{name.0.value}}

+
{{{summary}}}
+
{{{conceptual}}}
+
{{__global.declaration}}
+{{#syntax}} +
+
{{syntax.content.0.value}}
+
+{{#parameters.0}} +
{{__global.parameters}}
+ + + + + + + + + +{{/parameters.0}} +{{#parameters}} + + + + + +{{/parameters}} +{{#parameters.0}} + +
{{__global.type}}{{__global.name}}{{__global.description}}
{{{type.specName.0.value}}}{{{id}}}{{{description}}}
+{{/parameters.0}} +{{#return}} +
{{__global.returns}}
+ + + + + + + + + + + + + +
{{__global.type}}{{__global.description}}
{{{type.specName.0.value}}}{{{description}}}
+{{/return}} +{{#typeParameters.0}} +
{{__global.typeParameters}}
+ + + + + + + + +{{/typeParameters.0}} +{{#typeParameters}} + + + + +{{/typeParameters}} +{{#typeParameters.0}} + +
{{__global.name}}{{__global.description}}
{{{id}}}{{{description}}}
+{{/typeParameters.0}} +{{#fieldValue}} +
{{__global.fieldValue}}
+ + + + + + + + + + + + + +
{{__global.type}}{{__global.description}}
{{{type.specName.0.value}}}{{{description}}}
+{{/fieldValue}} +{{#propertyValue}} +
{{__global.propertyValue}}
+ + + + + + + + + + + + + +
{{__global.type}}{{__global.description}}
{{{type.specName.0.value}}}{{{description}}}
+{{/propertyValue}} +{{#eventType}} +
{{__global.eventType}}
+ + + + + + + + + + + + + +
{{__global.type}}{{__global.description}}
{{{type.specName.0.value}}}{{{description}}}
+{{/eventType}} +{{/syntax}} +{{#overridden}} +
{{__global.overrides}}
+
+{{/overridden}} +{{#implements.0}} +
{{__global.implements}}
+{{/implements.0}} +{{#implements}} + {{#definition}} +
+ {{/definition}} + {{^definition}} +
+ {{/definition}} +{{/implements}} +{{#remarks}} +
{{__global.remarks}}
+
{{{remarks}}}
+{{/remarks}} +{{#example.0}} +
{{__global.examples}}
+{{/example.0}} +{{#example}} +{{{.}}} +{{/example}} +{{#exceptions.0}} +
{{__global.exceptions}}
+ + + + + + + + +{{/exceptions.0}} +{{#exceptions}} + + + + +{{/exceptions}} +{{#exceptions.0}} + +
{{__global.type}}{{__global.condition}}
{{{type.specName.0.value}}}{{{description}}}
+{{/exceptions.0}} +{{#seealso.0}} +
{{__global.seealso}}
+
+{{/seealso.0}} +{{#seealso}} + {{#isCref}} +
{{{type.specName.0.value}}}
+ {{/isCref}} + {{^isCref}} +
{{{url}}}
+ {{/isCref}} +{{/seealso}} +{{#seealso.0}} +
+{{/seealso.0}} +{{/children}} +{{/children}} +{{#extensionMethods.0}} +

{{__global.extensionMethods}}

+{{/extensionMethods.0}} +{{#extensionMethods}} +
+ {{#definition}} + + {{/definition}} + {{^definition}} + + {{/definition}} +
+{{/extensionMethods}} +{{#seealso.0}} +

{{__global.seealso}}

+
+{{/seealso.0}} +{{#seealso}} + {{#isCref}} +
{{{type.specName.0.value}}}
+ {{/isCref}} + {{^isCref}} +
{{{url}}}
+ {{/isCref}} +{{/seealso}} +{{#seealso.0}} +
+{{/seealso.0}} diff --git a/docfx/plugins/memberpage.2.59.4/partials/customMREFContent.tmpl.partial b/docfx/plugins/memberpage.2.59.4/partials/customMREFContent.tmpl.partial new file mode 100644 index 000000000..95c0538b6 --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/partials/customMREFContent.tmpl.partial @@ -0,0 +1,7 @@ +{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} +{{#isCollection}} +{{>partials/collection}} +{{/isCollection}} +{{#isItem}} +{{>partials/item}} +{{/isItem}} diff --git a/docfx/plugins/memberpage.2.59.4/partials/item.tmpl.partial b/docfx/plugins/memberpage.2.59.4/partials/item.tmpl.partial new file mode 100644 index 000000000..ecce961b5 --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/partials/item.tmpl.partial @@ -0,0 +1,3 @@ +{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} + +{{>partials/class.header}} \ No newline at end of file diff --git a/docfx/plugins/memberpage.2.59.4/plugins/HtmlAgilityPack.dll b/docfx/plugins/memberpage.2.59.4/plugins/HtmlAgilityPack.dll new file mode 100644 index 000000000..702463753 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/HtmlAgilityPack.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.Common.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.Common.dll new file mode 100644 index 000000000..77bf24974 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.Common.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.MemberLevelManagedReference.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.MemberLevelManagedReference.dll new file mode 100644 index 000000000..6399faa80 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Build.MemberLevelManagedReference.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Common.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Common.dll new file mode 100644 index 000000000..687b00b6d Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Common.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.Common.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.Common.dll new file mode 100644 index 000000000..fe0e76a63 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.Common.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.ManagedReference.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.ManagedReference.dll new file mode 100644 index 000000000..27e07c1b5 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.DataContracts.ManagedReference.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.MarkdownLite.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.MarkdownLite.dll new file mode 100644 index 000000000..c7089f073 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.MarkdownLite.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Plugins.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Plugins.dll new file mode 100644 index 000000000..df8fb6d22 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.Plugins.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.YamlSerialization.dll b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.YamlSerialization.dll new file mode 100644 index 000000000..387f6ea50 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Microsoft.DocAsCode.YamlSerialization.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/Newtonsoft.Json.dll b/docfx/plugins/memberpage.2.59.4/plugins/Newtonsoft.Json.dll new file mode 100644 index 000000000..83777b989 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/Newtonsoft.Json.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Buffers.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Buffers.dll new file mode 100644 index 000000000..f2d83c514 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Buffers.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Collections.Immutable.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Collections.Immutable.dll new file mode 100644 index 000000000..f5513ca02 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Collections.Immutable.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.AttributedModel.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.AttributedModel.dll new file mode 100644 index 000000000..4acc216e1 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.AttributedModel.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Convention.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Convention.dll new file mode 100644 index 000000000..ef3669bb2 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Convention.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Hosting.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Hosting.dll new file mode 100644 index 000000000..a446fe6e0 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Hosting.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Runtime.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Runtime.dll new file mode 100644 index 000000000..a05bfe9c8 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.Runtime.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.TypedParts.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.TypedParts.dll new file mode 100644 index 000000000..cfae95d0c Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Composition.TypedParts.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Memory.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Memory.dll new file mode 100644 index 000000000..5d1947056 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Memory.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Numerics.Vectors.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Numerics.Vectors.dll new file mode 100644 index 000000000..08659724d Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Numerics.Vectors.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/System.Runtime.CompilerServices.Unsafe.dll b/docfx/plugins/memberpage.2.59.4/plugins/System.Runtime.CompilerServices.Unsafe.dll new file mode 100644 index 000000000..1908d925a Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/System.Runtime.CompilerServices.Unsafe.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/YamlDotNet.dll b/docfx/plugins/memberpage.2.59.4/plugins/YamlDotNet.dll new file mode 100644 index 000000000..9a4a07137 Binary files /dev/null and b/docfx/plugins/memberpage.2.59.4/plugins/YamlDotNet.dll differ diff --git a/docfx/plugins/memberpage.2.59.4/plugins/docfx.plugins.config b/docfx/plugins/memberpage.2.59.4/plugins/docfx.plugins.config new file mode 100644 index 000000000..0a581df37 --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/plugins/docfx.plugins.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docfx/plugins/memberpage.2.59.4/toc.html.js b/docfx/plugins/memberpage.2.59.4/toc.html.js new file mode 100644 index 000000000..68502d56e --- /dev/null +++ b/docfx/plugins/memberpage.2.59.4/toc.html.js @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. +exports.transform = function (model) { + var groupNames = { + "constructor": { key: "constructorsInSubtitle" }, + "field": { key: "fieldsInSubtitle" }, + "property": { key: "propertiesInSubtitle" }, + "method": { key: "methodsInSubtitle" }, + "event": { key: "eventsInSubtitle" }, + "operator": { key: "operatorsInSubtitle" }, + }; + + groupChildren(model); + transformItem(model, 1); + return model; + + function groupChildren(item) { + if (!item || !item.items || item.items.length == 0) { + return; + } + var grouped = {}; + var items = []; + item.items.forEach(function (element) { + groupChildren(element); + if (element.type) { + var type = element.type.toLowerCase(); + if (!grouped.hasOwnProperty(type)) { + if (!groupNames.hasOwnProperty(type)) { + groupNames[type] = { + name: element.type + }; + console.log(type + " is not predefined type, use its type name as display name.") + } + grouped[type] = []; + } + grouped[type].push(element); + } else { + items.push(element); + } + }, this); + + // With order defined in groupNames + for (var key in groupNames) { + if (groupNames.hasOwnProperty(key) && grouped.hasOwnProperty(key)) { + items.push({ + name: model.__global[groupNames[key].key] || groupNames[key].name, + items: grouped[key] + }) + } + } + + item.items = items; + } + + function transformItem(item, level) { + // set to null in case mustache looks up + item.topicHref = item.topicHref || null; + item.tocHref = item.tocHref || null; + item.name = item.name || null; + + item.level = level; + + if (item.items && item.items.length > 0) { + item.leaf = false; + var length = item.items.length; + for (var i = 0; i < length; i++) { + transformItem(item.items[i], level + 1); + }; + } else { + item.items = []; + item.leaf = true; + } + } +}