From 794b155827868d67f1cec45bbe8c3a3e4be02597 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 18 Mar 2018 18:44:52 +0100 Subject: Add support for displaying exported functions --- .../react-docs/src/components/documentation.tsx | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'packages/react-docs/src/components/documentation.tsx') diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx index b46358159..67523dcc3 100644 --- a/packages/react-docs/src/components/documentation.tsx +++ b/packages/react-docs/src/components/documentation.tsx @@ -25,6 +25,7 @@ import { SolidityMethod, SupportedDocJson, TypeDefinitionByName, + TypescriptFunction, TypescriptMethod, } from '../types'; import { constants } from '../utils/constants'; @@ -33,7 +34,7 @@ import { utils } from '../utils/utils'; import { Badge } from './badge'; import { Comment } from './comment'; import { EventDefinition } from './event_definition'; -import { MethodBlock } from './method_block'; +import { SignatureBlock } from './signature_block'; import { SourceLink } from './source_link'; import { Type } from './type'; import { TypeDefinition } from './type_definition'; @@ -216,8 +217,12 @@ export class Documentation extends React.Component { - const isConstructor = false; - return this._renderMethodBlocks(method, sectionName, isConstructor, typeDefinitionByName); + return this._renderSignatureBlocks(method, sectionName, typeDefinitionByName); + }); + + const sortedFunctions = _.sortBy(docSection.functions, 'name'); + const functionDefs = _.map(sortedFunctions, func => { + return this._renderSignatureBlocks(func, sectionName, typeDefinitionByName); }); const sortedEvents = _.sortBy(docSection.events, 'name'); @@ -262,6 +267,12 @@ export class Documentation extends React.Component{methodDefs} )} + {docSection.functions.length > 0 && ( +
+

Functions

+
{functionDefs}
+
+ )} {!_.isUndefined(docSection.events) && docSection.events.length > 0 && (
@@ -318,7 +329,7 @@ export class Documentation extends React.Component { - return this._renderMethodBlocks(constructor, sectionName, constructor.isConstructor, typeDefinitionByName); + return this._renderSignatureBlocks(constructor, sectionName, typeDefinitionByName); }); return
{constructorDefs}
; } @@ -340,14 +351,13 @@ export class Documentation extends React.Component ); } - private _renderMethodBlocks( - method: SolidityMethod | TypescriptMethod, + private _renderSignatureBlocks( + method: SolidityMethod | TypescriptFunction | TypescriptMethod, sectionName: string, - isConstructor: boolean, typeDefinitionByName: TypeDefinitionByName, ): React.ReactNode { return ( - Date: Thu, 22 Mar 2018 13:32:14 +0000 Subject: Use isEmpty --- packages/react-docs/src/components/documentation.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/react-docs/src/components/documentation.tsx') diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx index 67523dcc3..14fe175cf 100644 --- a/packages/react-docs/src/components/documentation.tsx +++ b/packages/react-docs/src/components/documentation.tsx @@ -248,26 +248,26 @@ export class Documentation extends React.Component {docSection.comment && } - {docSection.constructors.length > 0 && + {!_.isEmpty(docSection.constructors) && this.props.docsInfo.isVisibleConstructor(sectionName) && (

Constructor

{this._renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)}
)} - {docSection.properties.length > 0 && ( + {!_.isEmpty(docSection.properties) && (

Properties

{propertyDefs}
)} - {docSection.methods.length > 0 && ( + {!_.isEmpty(docSection.methods) && (

Methods

{methodDefs}
)} - {docSection.functions.length > 0 && ( + {!_.isEmpty(docSection.functions) && (

Functions

{functionDefs}
-- cgit v1.2.3