diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-29 05:11:04 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-29 05:11:04 +0800 |
commit | 72a00ac2df47ff793d74c2a82c7f403f501e784a (patch) | |
tree | 082d38d2ed5a36ec4b8f7e0bd156841ca86cf005 /packages/website/ts/pages/documentation/docs_info.ts | |
parent | fcddd503b76283266946dc1f04b299d0606c90bb (diff) | |
download | dexon-sol-tools-72a00ac2df47ff793d74c2a82c7f403f501e784a.tar.gz dexon-sol-tools-72a00ac2df47ff793d74c2a82c7f403f501e784a.tar.zst dexon-sol-tools-72a00ac2df47ff793d74c2a82c7f403f501e784a.zip |
Refactor the topLevel documentation react components for 0x.js and Smart contracts into a single component
Diffstat (limited to 'packages/website/ts/pages/documentation/docs_info.ts')
-rw-r--r-- | packages/website/ts/pages/documentation/docs_info.ts | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/packages/website/ts/pages/documentation/docs_info.ts b/packages/website/ts/pages/documentation/docs_info.ts index 326ebb31c..f607c2185 100644 --- a/packages/website/ts/pages/documentation/docs_info.ts +++ b/packages/website/ts/pages/documentation/docs_info.ts @@ -1,6 +1,14 @@ import compareVersions = require('compare-versions'); import * as _ from 'lodash'; -import {DocsInfoConfig, DocsMenu, SectionsMap} from 'ts/types'; +import { + DocAgnosticFormat, + DocsInfoConfig, + DocsMenu, + DoxityDocObj, + MenuSubsectionsBySection, + SectionsMap, + TypeDocNode, +} from 'ts/types'; export class DocsInfo { public packageName: string; @@ -49,4 +57,49 @@ export class DocsInfo { }); return finalMenu; } + public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection { + const menuSubsectionsBySection = {} as MenuSubsectionsBySection; + if (_.isUndefined(docAgnosticFormat)) { + return menuSubsectionsBySection; + } + + const docSections = _.keys(this.sections); + _.each(docSections, sectionName => { + const docSection = docAgnosticFormat[sectionName]; + if (_.isUndefined(docSection)) { + return; // no-op + } + + if (!_.isUndefined(this.sections.types) && sectionName === this.sections.types) { + const sortedTypesNames = _.sortBy(docSection.types, 'name'); + const typeNames = _.map(sortedTypesNames, t => t.name); + menuSubsectionsBySection[sectionName] = typeNames; + } else { + let eventNames: string[] = []; + if (!_.isUndefined(docSection.events)) { + const sortedEventNames = _.sortBy(docSection.events, 'name'); + eventNames = _.map(sortedEventNames, m => m.name); + } + const sortedMethodNames = _.sortBy(docSection.methods, 'name'); + const methodNames = _.map(sortedMethodNames, m => m.name); + menuSubsectionsBySection[sectionName] = [...methodNames, ...eventNames]; + } + }); + return menuSubsectionsBySection; + } + public getTypeDefinitionsByName(docAgnosticFormat: DocAgnosticFormat) { + if (_.isUndefined(this.sections.types)) { + return {}; + } + + const typeDocSection = docAgnosticFormat[this.sections.types]; + const typeDefinitionByName = _.keyBy(typeDocSection.types, 'name'); + return typeDefinitionByName; + } + public isVisibleConstructor(sectionName: string): boolean { + return _.includes(this.docsInfo.visibleConstructors, sectionName); + } + public convertToDocAgnosticFormat(docObj: DoxityDocObj|TypeDocNode): DocAgnosticFormat { + return this.docsInfo.convertToDocAgnosticFormatFn(docObj, this); + } } |