aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-20 00:14:58 +0800
committerGitHub <noreply@github.com>2018-07-20 00:14:58 +0800
commit9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9 (patch)
treef96d1aa76c7e5aa9e3311d5cdbd0d31c8ec8d7fb /packages/react-docs/src
parent3de88d5345c7a4549bc69e2ca28f0601f5d42189 (diff)
parentd8898cf9a30cc349868afcf2b78e6369e57aa726 (diff)
downloaddexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar.gz
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar.bz2
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar.lz
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar.xz
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.tar.zst
dexon-sol-tools-9b6476a6b7db8db7b0fc6bbf9306c01566fb47a9.zip
Merge pull request #844 from 0xProject/support-multiple-doc-md
Support version-specific doc ref markdown sections
Diffstat (limited to 'packages/react-docs/src')
-rw-r--r--packages/react-docs/src/components/documentation.tsx16
-rw-r--r--packages/react-docs/src/docs_info.ts5
-rw-r--r--packages/react-docs/src/types.ts6
3 files changed, 23 insertions, 4 deletions
diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx
index a4e6f4f6e..ff33220d2 100644
--- a/packages/react-docs/src/components/documentation.tsx
+++ b/packages/react-docs/src/components/documentation.tsx
@@ -12,6 +12,7 @@ import {
import * as _ from 'lodash';
import CircularProgress from 'material-ui/CircularProgress';
import * as React from 'react';
+import * as semver from 'semver';
import { DocsInfo } from '../docs_info';
import {
@@ -180,7 +181,20 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
return renderedSections;
}
private _renderSection(typeDefinitionByName: TypeDefinitionByName, sectionName: string): React.ReactNode {
- const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdown[sectionName];
+ const markdownVersions = _.keys(this.props.docsInfo.sectionNameToMarkdownByVersion);
+ const eligibleVersions = _.filter(markdownVersions, mdVersion => {
+ return semver.lte(mdVersion, this.props.selectedVersion);
+ });
+ if (_.isEmpty(eligibleVersions)) {
+ throw new Error(
+ `No eligible markdown sections found for ${this.props.docsInfo.displayName} version ${
+ this.props.selectedVersion
+ }.`,
+ );
+ }
+ const sortedEligibleVersions = eligibleVersions.sort(semver.rcompare.bind(semver));
+ const closestVersion = sortedEligibleVersions[0];
+ const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdownByVersion[closestVersion][sectionName];
if (!_.isUndefined(markdownFileIfExists)) {
return (
<MarkdownSection
diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts
index 5d46dbda6..b37942da6 100644
--- a/packages/react-docs/src/docs_info.ts
+++ b/packages/react-docs/src/docs_info.ts
@@ -9,6 +9,7 @@ import {
DocsInfoTypeConfigs,
DocsMenu,
DoxityDocObj,
+ SectionNameToMarkdownByVersion,
SectionsMap,
SupportedDocJson,
TypeDefinitionByName,
@@ -24,7 +25,7 @@ export class DocsInfo {
public packageUrl: string;
public menu: DocsMenu;
public sections: SectionsMap;
- public sectionNameToMarkdown: { [sectionName: string]: string };
+ public sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion;
public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
public typeConfigs: DocsInfoTypeConfigs;
private readonly _docsInfo: DocsInfoConfig;
@@ -34,7 +35,7 @@ export class DocsInfo {
this.displayName = config.displayName;
this.packageUrl = config.packageUrl;
this.sections = config.sections;
- this.sectionNameToMarkdown = config.sectionNameToMarkdown;
+ this.sectionNameToMarkdownByVersion = config.sectionNameToMarkdownByVersion;
this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
this.typeConfigs = config.typeConfigs;
this._docsInfo = config;
diff --git a/packages/react-docs/src/types.ts b/packages/react-docs/src/types.ts
index f4e61edc9..cbc774c2e 100644
--- a/packages/react-docs/src/types.ts
+++ b/packages/react-docs/src/types.ts
@@ -1,3 +1,7 @@
+export interface SectionNameToMarkdownByVersion {
+ [version: string]: { [sectionName: string]: string };
+}
+
export interface DocsInfoConfig {
id: string;
type: SupportedDocJson;
@@ -5,7 +9,7 @@ export interface DocsInfoConfig {
packageUrl: string;
menu: DocsMenu;
sections: SectionsMap;
- sectionNameToMarkdown: { [sectionName: string]: string };
+ sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion;
visibleConstructors: string[];
sectionNameToModulePath?: { [sectionName: string]: string[] };
menuSubsectionToVersionWhenIntroduced?: { [sectionName: string]: string };