diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-06 23:45:25 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-06 23:45:25 +0800 |
commit | 60d95475ebcfc868e54f90350fcca09e45b976ff (patch) | |
tree | 57cb34dadd0835a027624280f854f5c0d02dc68d /packages/react-docs/src/ts/components | |
parent | c8ace2edc017969f405ffaa1293620850ed5fc05 (diff) | |
download | dexon-0x-contracts-60d95475ebcfc868e54f90350fcca09e45b976ff.tar.gz dexon-0x-contracts-60d95475ebcfc868e54f90350fcca09e45b976ff.tar.zst dexon-0x-contracts-60d95475ebcfc868e54f90350fcca09e45b976ff.zip |
Move DocsInfo out of the components folder
Diffstat (limited to 'packages/react-docs/src/ts/components')
8 files changed, 7 insertions, 127 deletions
diff --git a/packages/react-docs/src/ts/components/docs_info.ts b/packages/react-docs/src/ts/components/docs_info.ts deleted file mode 100644 index 509bba89e..000000000 --- a/packages/react-docs/src/ts/components/docs_info.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { MenuSubsectionsBySection } from '@0xproject/react-shared'; -import compareVersions = require('compare-versions'); -import * as _ from 'lodash'; - -import { - ContractsByVersionByNetworkId, - DocAgnosticFormat, - DocsInfoConfig, - DocsMenu, - DoxityDocObj, - SectionsMap, - SupportedDocJson, - TypeDocNode, -} from '../types'; -import { doxityUtils } from '../utils/doxity_utils'; -import { typeDocUtils } from '../utils/typedoc_utils'; - -export class DocsInfo { - public id: string; - public type: SupportedDocJson; - public displayName: string; - public packageUrl: string; - public menu: DocsMenu; - public sections: SectionsMap; - public sectionNameToMarkdown: { [sectionName: string]: string }; - public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; - private _docsInfo: DocsInfoConfig; - constructor(config: DocsInfoConfig) { - this.id = config.id; - this.type = config.type; - this.displayName = config.displayName; - this.packageUrl = config.packageUrl; - this.sections = config.sections; - this.sectionNameToMarkdown = config.sectionNameToMarkdown; - this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId; - this._docsInfo = config; - } - public isPublicType(typeName: string): boolean { - if (_.isUndefined(this._docsInfo.publicTypes)) { - return false; - } - const isPublic = _.includes(this._docsInfo.publicTypes, typeName); - return isPublic; - } - public getModulePathsIfExists(sectionName: string): string[] { - const modulePathsIfExists = this._docsInfo.sectionNameToModulePath[sectionName]; - return modulePathsIfExists; - } - public getMenu(selectedVersion?: string): { [section: string]: string[] } { - if (_.isUndefined(selectedVersion) || _.isUndefined(this._docsInfo.menuSubsectionToVersionWhenIntroduced)) { - return this._docsInfo.menu; - } - - const finalMenu = _.cloneDeep(this._docsInfo.menu); - if (_.isUndefined(finalMenu.contracts)) { - return finalMenu; - } - - // TODO: refactor to include more sections then simply the `contracts` section - finalMenu.contracts = _.filter(finalMenu.contracts, (contractName: string) => { - const versionIntroducedIfExists = this._docsInfo.menuSubsectionToVersionWhenIntroduced[contractName]; - if (!_.isUndefined(versionIntroducedIfExists)) { - const existsInSelectedVersion = compareVersions(selectedVersion, versionIntroducedIfExists) >= 0; - return existsInSelectedVersion; - } else { - return true; - } - }); - 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 { - if (this.type === SupportedDocJson.Doxity) { - return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj); - } else { - return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this); - } - } -} diff --git a/packages/react-docs/src/ts/components/documentation.tsx b/packages/react-docs/src/ts/components/documentation.tsx index f5a117797..5c261a39b 100644 --- a/packages/react-docs/src/ts/components/documentation.tsx +++ b/packages/react-docs/src/ts/components/documentation.tsx @@ -15,6 +15,7 @@ import CircularProgress from 'material-ui/CircularProgress'; import * as React from 'react'; import { scroller } from 'react-scroll'; +import { DocsInfo } from '../docs_info'; import { AddressByContractName, DocAgnosticFormat, @@ -30,7 +31,6 @@ import { utils } from '../utils/utils'; import { Badge } from './badge'; import { Comment } from './comment'; -import { DocsInfo } from './docs_info'; import { EventDefinition } from './event_definition'; import { MethodBlock } from './method_block'; import { SourceLink } from './source_link'; diff --git a/packages/react-docs/src/ts/components/event_definition.tsx b/packages/react-docs/src/ts/components/event_definition.tsx index 8289650f5..68f60ddf9 100644 --- a/packages/react-docs/src/ts/components/event_definition.tsx +++ b/packages/react-docs/src/ts/components/event_definition.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { Event, EventArg } from '../types'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { Type } from './type'; export interface EventDefinitionProps { diff --git a/packages/react-docs/src/ts/components/interface.tsx b/packages/react-docs/src/ts/components/interface.tsx index 1c99495d7..92883089a 100644 --- a/packages/react-docs/src/ts/components/interface.tsx +++ b/packages/react-docs/src/ts/components/interface.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import { CustomType, TypeDocTypes } from '../types'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { MethodSignature } from './method_signature'; import { Type } from './type'; diff --git a/packages/react-docs/src/ts/components/method_block.tsx b/packages/react-docs/src/ts/components/method_block.tsx index 5ed7f42a1..529b9f9c7 100644 --- a/packages/react-docs/src/ts/components/method_block.tsx +++ b/packages/react-docs/src/ts/components/method_block.tsx @@ -6,7 +6,7 @@ import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } fro import { typeDocUtils } from '../utils/typedoc_utils'; import { Comment } from './comment'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { MethodSignature } from './method_signature'; import { SourceLink } from './source_link'; diff --git a/packages/react-docs/src/ts/components/method_signature.tsx b/packages/react-docs/src/ts/components/method_signature.tsx index e21d82287..6a394dd6d 100644 --- a/packages/react-docs/src/ts/components/method_signature.tsx +++ b/packages/react-docs/src/ts/components/method_signature.tsx @@ -5,7 +5,7 @@ import * as ReactDOM from 'react-dom'; import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from '../types'; import { constants } from '../utils/constants'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { Type } from './type'; export interface MethodSignatureProps { diff --git a/packages/react-docs/src/ts/components/type.tsx b/packages/react-docs/src/ts/components/type.tsx index 780d87eae..504570aad 100644 --- a/packages/react-docs/src/ts/components/type.tsx +++ b/packages/react-docs/src/ts/components/type.tsx @@ -8,7 +8,7 @@ import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types'; import { constants } from '../utils/constants'; import { utils } from '../utils/utils'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { TypeDefinition } from './type_definition'; // Some types reference other libraries. For these types, we want to link the user to the relevant documentation. diff --git a/packages/react-docs/src/ts/components/type_definition.tsx b/packages/react-docs/src/ts/components/type_definition.tsx index 944a31f95..20a24495b 100644 --- a/packages/react-docs/src/ts/components/type_definition.tsx +++ b/packages/react-docs/src/ts/components/type_definition.tsx @@ -7,7 +7,7 @@ import { utils } from '../utils/utils'; import { Comment } from './comment'; import { CustomEnum } from './custom_enum'; -import { DocsInfo } from './docs_info'; +import { DocsInfo } from '../docs_info'; import { Enum } from './enum'; import { Interface } from './interface'; import { MethodSignature } from './method_signature'; |