Merge pull request #244 from 0xProject/feature/connect-docs

Add Connect Docs
This commit is contained in:
Fabio Berger
2017-11-29 09:03:42 -06:00
committed by GitHub
13 changed files with 181 additions and 16 deletions

View File

@@ -18,7 +18,7 @@
"author": "Fabio Berger",
"license": "Apache-2.0",
"dependencies": {
"0x.js": "^0.27.1",
"0x.js": "0xproject/0x.js/packages/0x.js#0x.js@0.27.1",
"accounting": "^0.4.1",
"basscss": "^8.0.3",
"bignumber.js": "~4.1.0",

View File

@@ -41,6 +41,10 @@ const menuItemsBySection: MenuItemsBySection = {
title: '0x Smart Contracts',
path: WebsitePaths.SmartContracts,
},
{
title: '0x Connect',
path: WebsitePaths.Connect,
},
{
title: 'Whitepaper',
path: WebsitePaths.Whitepaper,

View File

@@ -34,7 +34,7 @@ interface TopBarProps {
menu?: DocsMenu;
menuSubsectionsBySection?: MenuSubsectionsBySection;
shouldFullWidth?: boolean;
docPath?: string;
docsInfo?: DocsInfo;
style?: React.CSSProperties;
isNightVersion?: boolean;
}
@@ -111,6 +111,13 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
>
<MenuItem style={{fontSize: styles.menuItem.fontSize}} primaryText="Smart Contracts" />
</Link>,
<Link
key="subMenuItem-0xconnect"
to={WebsitePaths.Connect}
className="text-decoration-none"
>
<MenuItem style={{fontSize: styles.menuItem.fontSize}} primaryText="0x Connect" />
</Link>,
<a
key="subMenuItem-standard-relayer-api"
target="_blank"
@@ -235,6 +242,11 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
<MenuItem className="py2">0x.js Docs</MenuItem>
</Link>
}
{!this.isViewingConnectDocs() &&
<Link to={WebsitePaths.Connect} className="text-decoration-none">
<MenuItem className="py2">0x Connect Docs</MenuItem>
</Link>
}
{!this.isViewingSmartContractsDocs() &&
<Link to={WebsitePaths.SmartContracts} className="text-decoration-none">
<MenuItem className="py2">Smart Contract Docs</MenuItem>
@@ -274,11 +286,12 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
);
}
private renderDocsMenu() {
if (!this.isViewing0xjsDocs() && !this.isViewingSmartContractsDocs() || _.isUndefined(this.props.menu)) {
if (!this.isViewing0xjsDocs() && !this.isViewingSmartContractsDocs() && !this.isViewingConnectDocs()
|| _.isUndefined(this.props.menu)) {
return;
}
const sectionTitle = this.isViewing0xjsDocs() ? '0x.js Docs' : 'Smart contract Docs';
const sectionTitle = `${this.props.docsInfo.displayName} Docs`;
return (
<div className="lg-hide md-hide">
<div className="pl1 py1" style={{backgroundColor: SECTION_HEADER_COLOR}}>{sectionTitle}</div>
@@ -288,7 +301,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
shouldDisplaySectionHeaders={false}
onMenuItemClick={this.onMenuButtonClick.bind(this)}
selectedVersion={this.props.docsVersion}
docPath={this.props.docPath}
docPath={this.props.docsInfo.websitePath}
versions={this.props.availableDocVersions}
/>
</div>
@@ -362,6 +375,9 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
private isViewing0xjsDocs() {
return _.includes(this.props.location.pathname, WebsitePaths.ZeroExJs);
}
private isViewingConnectDocs() {
return _.includes(this.props.location.pathname, WebsitePaths.Connect);
}
private isViewingSmartContractsDocs() {
return _.includes(this.props.location.pathname, WebsitePaths.SmartContracts);
}
@@ -370,6 +386,6 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
}
private shouldDisplayBottomBar() {
return this.isViewingWiki() || this.isViewing0xjsDocs() || this.isViewingFAQ() ||
this.isViewingSmartContractsDocs();
this.isViewingSmartContractsDocs() || this.isViewingConnectDocs();
}
}

View File

@@ -0,0 +1,97 @@
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
import * as React from 'react';
import {connect} from 'react-redux';
import {Dispatch, Store as ReduxStore} from 'redux';
import {Blockchain} from 'ts/blockchain';
import {DocsInfo} from 'ts/pages/documentation/docs_info';
import {
Documentation as DocumentationComponent,
DocumentationAllProps,
} from 'ts/pages/documentation/documentation';
import {Dispatcher} from 'ts/redux/dispatcher';
import {State} from 'ts/redux/reducer';
import {DocsInfoConfig, WebsitePaths} from 'ts/types';
import {typeDocUtils} from 'ts/utils/typedoc_utils';
/* tslint:disable:no-var-requires */
const IntroMarkdown = require('md/docs/connect/introduction');
const InstallationMarkdown = require('md/docs/connect/installation');
/* tslint:enable:no-var-requires */
const connectDocSections = {
introduction: 'introduction',
installation: 'installation',
httpClient: 'httpClient',
types: 'types',
};
const docsInfoConfig: DocsInfoConfig = {
displayName: '0x Connect',
subPackageName: 'connect',
packageUrl: 'https://github.com/0xProject/0x.js',
websitePath: WebsitePaths.Connect,
docsJsonRoot: 'https://s3.amazonaws.com/connect-docs-jsons',
menu: {
introduction: [
connectDocSections.introduction,
],
install: [
connectDocSections.installation,
],
httpClient: [
connectDocSections.httpClient,
],
types: [
connectDocSections.types,
],
},
sectionNameToMarkdown: {
[connectDocSections.introduction]: IntroMarkdown,
[connectDocSections.installation]: InstallationMarkdown,
},
// Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is
// currently no way to extract the re-exported types from index.ts via TypeDoc :(
publicTypes: [
'Client',
'FeesRequest',
'FeesResponse',
'OrderbookRequest',
'OrderbookResponse',
'OrdersRequest',
'TokenPairsItem',
'TokenPairsRequest',
],
sectionNameToModulePath: {
[connectDocSections.httpClient]: ['"src/http_client"'],
[connectDocSections.types]: ['"src/types"'],
},
menuSubsectionToVersionWhenIntroduced: {},
sections: connectDocSections,
visibleConstructors: [connectDocSections.httpClient],
convertToDocAgnosticFormatFn: typeDocUtils.convertToDocAgnosticFormat.bind(typeDocUtils),
};
const docsInfo = new DocsInfo(docsInfoConfig);
interface ConnectedState {
docsVersion: string;
availableDocVersions: string[];
docsInfo: DocsInfo;
}
interface ConnectedDispatch {
dispatcher: Dispatcher;
}
const mapStateToProps = (state: State, ownProps: DocumentationAllProps): ConnectedState => ({
docsVersion: state.docsVersion,
availableDocVersions: state.availableDocVersions,
docsInfo,
});
const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
dispatcher: new Dispatcher(dispatch),
});
export const Documentation: React.ComponentClass<DocumentationAllProps> =
connect(mapStateToProps, mapDispatchToProps)(DocumentationComponent);

View File

@@ -20,7 +20,7 @@ const IntroMarkdown = require('md/docs/smart_contracts/introduction');
const sections = constants.smartContractDocSections;
const docsInfoConfig: DocsInfoConfig = {
packageName: '0x Smart Contracts',
displayName: '0x Smart Contracts',
packageUrl: 'https://github.com/0xProject/contracts',
websitePath: WebsitePaths.SmartContracts,
docsJsonRoot: 'https://s3.amazonaws.com/smart-contracts-docs-json',

View File

@@ -39,8 +39,9 @@ const zeroExJsDocSections = {
};
const docsInfoConfig: DocsInfoConfig = {
packageName: '0x.js',
displayName: '0x.js',
packageUrl: 'https://github.com/0xProject/0x.js',
subPackageName: '0x.js',
websitePath: WebsitePaths.ZeroExJs,
docsJsonRoot: 'https://s3.amazonaws.com/0xjs-docs-jsons',
menu: {

View File

@@ -87,6 +87,12 @@ const LazySmartContractsDocumentation = createLazyComponent(
/* webpackChunkName: "smartContractDocs" */'ts/containers/smart_contracts_documentation',
),
);
const LazyConnectDocumentation = createLazyComponent(
'Documentation',
async () => System.import<any>(
/* webpackChunkName: "connectDocs" */'ts/containers/connect_documentation',
),
);
const store: ReduxStore<State> = createStore(reducer);
render(
@@ -103,6 +109,7 @@ render(
<Route path={`${WebsitePaths.About}`} component={About as any} />
<Route path={`${WebsitePaths.Wiki}`} component={Wiki as any} />
<Route path={`${WebsitePaths.ZeroExJs}/:version?`} component={LazyZeroExJSDocumentation} />
<Route path={`${WebsitePaths.Connect}/:version?`} component={LazyConnectDocumentation} />
<Route
path={`${WebsitePaths.SmartContracts}/:version?`}
component={LazySmartContractsDocumentation}

View File

@@ -11,8 +11,9 @@ import {
} from 'ts/types';
export class DocsInfo {
public packageName: string;
public displayName: string;
public packageUrl: string;
public subPackageName?: string;
public websitePath: string;
public docsJsonRoot: string;
public menu: DocsMenu;
@@ -20,8 +21,9 @@ export class DocsInfo {
public sectionNameToMarkdown: {[sectionName: string]: string};
private docsInfo: DocsInfoConfig;
constructor(config: DocsInfoConfig) {
this.packageName = config.packageName;
this.displayName = config.displayName;
this.packageUrl = config.packageUrl;
this.subPackageName = config.subPackageName;
this.websitePath = config.websitePath;
this.docsJsonRoot = config.docsJsonRoot;
this.sections = config.sections;
@@ -45,6 +47,11 @@ export class DocsInfo {
}
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)) {

View File

@@ -111,7 +111,7 @@ export class Documentation extends
this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
return (
<div>
<DocumentTitle title={`${this.props.docsInfo.packageName} Documentation`}/>
<DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`}/>
<TopBar
blockchainIsLoaded={false}
location={this.props.location}
@@ -120,7 +120,7 @@ export class Documentation extends
menu={this.props.docsInfo.getMenu(this.props.docsVersion)}
menuSubsectionsBySection={menuSubsectionsBySection}
shouldFullWidth={true}
docPath={this.props.docsInfo.websitePath}
docsInfo={this.props.docsInfo}
/>
{_.isUndefined(this.state.docAgnosticFormat) ?
<div
@@ -164,7 +164,7 @@ export class Documentation extends
<div id={SCROLL_TOP_ID} />
<h1 className="md-pl2 sm-pl3">
<a href={this.props.docsInfo.packageUrl} target="_blank">
{this.props.docsInfo.packageName}
{this.props.docsInfo.displayName}
</a>
</h1>
{this.renderDocumentation()}
@@ -335,6 +335,7 @@ export class Documentation extends
version={this.props.docsVersion}
source={property.source}
baseUrl={this.props.docsInfo.packageUrl}
subPackageName={this.props.docsInfo.subPackageName}
/>
}
{property.comment &&

View File

@@ -95,6 +95,7 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
version={this.props.libraryVersion}
source={(method as TypescriptMethod).source}
baseUrl={this.props.docsInfo.packageUrl}
subPackageName={this.props.docsInfo.subPackageName}
/>
}
{method.comment &&

View File

@@ -1,3 +1,4 @@
import * as _ from 'lodash';
import {colors} from 'material-ui/styles';
import * as React from 'react';
import {Source} from 'ts/types';
@@ -7,14 +8,22 @@ interface SourceLinkProps {
source: Source;
baseUrl: string;
version: string;
subPackageName: string;
}
const SUB_PKG = '0x.js';
const packagesWithNamespace = [
'connect',
];
export function SourceLink(props: SourceLinkProps) {
const src = props.source;
const url = props.baseUrl;
const sourceCodeUrl = `${url}/blob/${SUB_PKG}%40${props.version}/packages/${SUB_PKG}/${src.fileName}#L${src.line}`;
const pkg = props.subPackageName;
let tagPrefix = pkg;
if (_.includes(packagesWithNamespace, pkg)) {
tagPrefix = `@0xproject/${pkg}`;
}
const sourceCodeUrl = `${url}/blob/${tagPrefix}%40${props.version}/packages/${pkg}/${src.fileName}#L${src.line}`;
return (
<div className="pt2" style={{fontSize: 14}}>
<a

View File

@@ -662,6 +662,7 @@ export enum WebsitePaths {
About = '/about',
Whitepaper = '/pdfs/0x_white_paper.pdf',
SmartContracts = '/docs/contracts',
Connect = '/docs/connect',
}
export interface DocsMenu {
@@ -673,7 +674,7 @@ export interface SectionsMap {
}
export interface DocsInfoConfig {
packageName: string;
displayName: string;
packageUrl: string;
websitePath: string;
docsJsonRoot: string;
@@ -682,6 +683,7 @@ export interface DocsInfoConfig {
sectionNameToMarkdown: {[sectionName: string]: string};
visibleConstructors: string[];
convertToDocAgnosticFormatFn: (docObj: DoxityDocObj|TypeDocNode, docsInfo?: any) => DocAgnosticFormat;
subPackageName?: string;
publicTypes?: string[];
sectionNameToModulePath?: {[sectionName: string]: string[]};
menuSubsectionToVersionWhenIntroduced?: {[sectionName: string]: string};

View File

@@ -2,6 +2,26 @@
# yarn lockfile v1
"0x.js@0xproject/0x.js/packages/0x.js#0x.js@0.27.1":
version "0.27.1"
resolved "https://registry.yarnpkg.com/0x.js/-/0x.js-0.27.1.tgz#e0dff70e257efbb7f54dddb55dddf2dce0b971ab"
dependencies:
"@0xproject/assert" "^0.0.6"
"@0xproject/json-schemas" "^0.6.9"
bignumber.js "~4.1.0"
bintrees "^1.0.2"
bn.js "4.11.8"
compare-versions "^3.0.1"
es6-promisify "^5.0.0"
ethereumjs-abi "^0.6.4"
ethereumjs-blockstream "^2.0.6"
ethereumjs-util "^5.1.1"
find-versions "^2.0.0"
js-sha3 "^0.6.1"
lodash "^4.17.4"
uuid "^3.1.0"
web3 "^0.20.0"
"@types/accounting@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@types/accounting/-/accounting-0.4.1.tgz#865d9f5694fd7c438fba34eb4bc82eec6f34cdd5"