Move remaining type configs to topLevel DocsInfoConfigs

This commit is contained in:
Fabio Berger
2018-03-07 15:19:59 +01:00
parent 8517de128b
commit 9aec1feae3
8 changed files with 176 additions and 115 deletions

View File

@@ -11,21 +11,6 @@ import { utils } from '../utils/utils';
import { TypeDefinition } from './type_definition';
// Some types reference other libraries. For these types, we want to link the user to the relevant documentation.
const typeToUrl: { [typeName: string]: string } = {
Web3: constants.URL_WEB3_DOCS,
Provider: constants.URL_WEB3_PROVIDER_DOCS,
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
DecodedLogEntryEvent: constants.URL_WEB3_DECODED_LOG_ENTRY_EVENT,
LogEntryEvent: constants.URL_WEB3_LOG_ENTRY_EVENT,
};
const typePrefix: { [typeName: string]: string } = {
Provider: 'Web3',
DecodedLogEntryEvent: 'Web3',
LogEntryEvent: 'Web3',
};
const typeToSection: { [typeName: string]: string } = {
ExchangeWrapper: 'exchange',
TokenWrapper: 'token',
@@ -149,9 +134,20 @@ export function Type(props: TypeProps): any {
return [prev, ', ', curr];
});
const typeNameUrlIfExists = typeToUrl[typeName as string];
const typePrefixIfExists = typePrefix[typeName as string];
const sectionNameIfExists = typeToSection[typeName as string];
let typeNameUrlIfExists;
let typePrefixIfExists;
let sectionNameIfExists;
if (!_.isUndefined(props.docsInfo.typeConfigs)) {
typeNameUrlIfExists = !_.isUndefined(props.docsInfo.typeConfigs.typeNameToExternalLink)
? props.docsInfo.typeConfigs.typeNameToExternalLink[typeName as string]
: undefined;
typePrefixIfExists = !_.isUndefined(props.docsInfo.typeConfigs.typeNameToPrefix)
? props.docsInfo.typeConfigs.typeNameToPrefix[typeName as string]
: undefined;
sectionNameIfExists = !_.isUndefined(props.docsInfo.typeConfigs.typeNameToDocSection)
? props.docsInfo.typeConfigs.typeNameToDocSection[typeName as string]
: undefined;
}
if (!_.isUndefined(typeNameUrlIfExists)) {
typeName = (
<a

View File

@@ -6,6 +6,7 @@ import {
ContractsByVersionByNetworkId,
DocAgnosticFormat,
DocsInfoConfig,
DocsInfoTypeConfigs,
DocsMenu,
DoxityDocObj,
SectionsMap,
@@ -24,6 +25,7 @@ export class DocsInfo {
public sections: SectionsMap;
public sectionNameToMarkdown: { [sectionName: string]: string };
public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
public typeConfigs: DocsInfoTypeConfigs;
private _docsInfo: DocsInfoConfig;
constructor(config: DocsInfoConfig) {
this.id = config.id;
@@ -33,13 +35,14 @@ export class DocsInfo {
this.sections = config.sections;
this.sectionNameToMarkdown = config.sectionNameToMarkdown;
this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
this.typeConfigs = config.typeConfigs;
this._docsInfo = config;
}
public isPublicType(typeName: string): boolean {
if (_.isUndefined(this._docsInfo.publicTypes)) {
if (_.isUndefined(this._docsInfo.typeConfigs.publicTypes)) {
return false;
}
const isPublic = _.includes(this._docsInfo.publicTypes, typeName);
const isPublic = _.includes(this._docsInfo.typeConfigs.publicTypes, typeName);
return isPublic;
}
public getModulePathsIfExists(sectionName: string): string[] {

View File

@@ -7,11 +7,17 @@ export interface DocsInfoConfig {
sections: SectionsMap;
sectionNameToMarkdown: { [sectionName: string]: string };
visibleConstructors: string[];
subPackageName?: string;
publicTypes?: string[];
sectionNameToModulePath?: { [sectionName: string]: string[] };
menuSubsectionToVersionWhenIntroduced?: { [sectionName: string]: string };
contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
typeConfigs?: DocsInfoTypeConfigs;
}
export interface DocsInfoTypeConfigs {
typeNameToExternalLink?: { [typeName: string]: string };
publicTypes?: string[];
typeNameToPrefix?: { [typeName: string]: string };
typeNameToDocSection?: { [typeName: string]: string };
}
export interface DocsMenu {

View File

@@ -1,9 +1,3 @@
export const constants = {
TYPES_SECTION_NAME: 'types',
URL_WEB3_DOCS: 'https://github.com/ethereum/wiki/wiki/JavaScript-API',
URL_WEB3_DECODED_LOG_ENTRY_EVENT:
'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L123',
URL_WEB3_LOG_ENTRY_EVENT: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L127',
URL_WEB3_PROVIDER_DOCS: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L150',
URL_BIGNUMBERJS_GITHUB: 'http://mikemcl.github.io/bignumber.js',
};