Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Refactor and document APIs #1053

Merged
merged 23 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b46a59b
Add basic version of new documentation.js transformer
KyleAMathews May 28, 2017
ab7ba98
Change api 'addFieldToNode' to 'createNodeField'
KyleAMathews May 29, 2017
45f7a31
Fix up node creation and add some simple tests
KyleAMathews May 30, 2017
1067771
Get basic docs page for action creators up
KyleAMathews May 30, 2017
0e39282
change deletePageByPath to just deletePage also sort action creators …
KyleAMathews May 30, 2017
d27833d
Change 'upsertPage' to 'createPage' and document it
KyleAMathews May 30, 2017
8a7575d
Only hide parent object description if its a desctructured object + i…
KyleAMathews May 30, 2017
61b79ff
Update action type
KyleAMathews May 30, 2017
776f77d
Support third level of parameters
KyleAMathews May 30, 2017
8863d25
Document createNode
KyleAMathews May 30, 2017
3697716
change 'addNodeToParent' to 'createParentChildLink' and document
KyleAMathews May 30, 2017
9e1c25a
Change 'addPageDependency' to 'createPageDependency' and document
KyleAMathews May 30, 2017
a8108ab
rename internal APIs
KyleAMathews May 30, 2017
5b0528b
Add links from function names at top to reference
KyleAMathews May 30, 2017
cba9b46
Ignore yarn.lock
KyleAMathews May 30, 2017
3ad7e09
Don't change the changelog...
KyleAMathews May 30, 2017
3c77aa3
Document and slightly modify node APIs
KyleAMathews May 31, 2017
6acd904
Factor out a FunctionsList component for rendering function docs
KyleAMathews May 31, 2017
6d536b3
Add browser/ssr docs and make a few tweaks to APIs
KyleAMathews May 31, 2017
62461fe
Add API specification document
KyleAMathews May 31, 2017
b5d634c
Actually add docs for node/browser/ssr
KyleAMathews May 31, 2017
e6600ab
Tweaks
KyleAMathews May 31, 2017
385bc78
Add README for gatsby-transformer-documentationjs
KyleAMathews May 31, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Factor out a FunctionsList component for rendering function docs
  • Loading branch information
KyleAMathews committed May 31, 2017
commit 6acd9048c422e3d6f29e14382010df72f2bf7971
137 changes: 137 additions & 0 deletions www/src/components/function-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React from "react"

import { rhythm, scale } from "../utils/typography"

const Param = (param, depth = 0) => {
// the plugin parameter is used internally but not
// something a user should use.
if (param.name == `plugin`) {
return null
}

return (
<div
key={`param ${JSON.stringify(param)}`}
css={{
marginLeft: `${depth * 1.05}rem`,
...(depth > 0 && scale((depth === 1 ? -1 : -1.5) / 5)),
}}
>
<h5
css={{
margin: 0,
...(depth > 0 && scale((depth === 1 ? 0 : -0.5) / 5)),
}}
>
{param.name === `$0` ? `destructured object` : param.name}
{` `}
{param.type &&
param.name !== `$0` &&
<span css={{ color: `#73725f` }}>{`{${param.type.name}}`}</span>}
</h5>
{param.description &&
<div
css={{ marginBottom: rhythm(-1 / 4) }}
dangerouslySetInnerHTML={{
__html: param.description.childMarkdownRemark.html,
}}
/>}
{param.properties &&
<div css={{ marginTop: rhythm(1 / 2) }}>
{param.properties.map(param => Param(param, depth + 1))}
</div>}
</div>
)
}

export default ({ functions }) => (
<div>
{functions.map(({ node }, i) => (
<div
id={node.name}
key={`reference list ${node.name}`}
css={{ marginBottom: rhythm(1) }}
>
{i !== 0 && <hr />}
<h3><a href={`#${node.name}`}><code>{node.name}</code></a></h3>
<div
dangerouslySetInnerHTML={{
__html: node.description.childMarkdownRemark.html,
}}
/>
{node.params.length > 0 &&
<div>
<h4>Parameters</h4>
{node.params.map(Param)}
</div>}

{node.examples.length > 0 &&
<div>
<h4 css={{ marginTop: rhythm(1) }}>Example</h4>
{` `}
{node.examples.map((example, i) => (
<pre key={`${node.name} example ${i}`}>
<code
className="language-javascript"
dangerouslySetInnerHTML={{
__html: example.highlighted,
}}
/>
</pre>
))}
</div>}
</div>
))}
</div>
)

export const pageQuery = graphql`
fragment FunctionList on DocumentationJs {
name
description {
childMarkdownRemark {
html
}
}
returns {
title
}
examples {
raw
highlighted
}
params {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
}
}
}
}
`
141 changes: 9 additions & 132 deletions www/src/pages/docs/bound-action-creators.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
import React from "react"
import { rhythm, scale } from "../../utils/typography"

const Param = (param, depth = 0) => {
// the plugin parameter is used internally but not
// something a user should use.
if (param.name == `plugin`) {
return null
}

return (
<div
key={`param ${JSON.stringify(param)}`}
css={{
marginLeft: `${depth * 1.05}rem`,
...(depth > 0 && scale((depth === 1 ? -1 : -1.5) / 5)),
}}
>
<h5
css={{
margin: 0,
...(depth > 0 && scale((depth === 1 ? 0 : -0.5) / 5)),
}}
>
{param.name === `$0` ? `destructured object` : param.name}
{` `}
{param.type &&
param.name !== `$0` &&
<span css={{ color: `#73725f` }}>{`{${param.type.name}}`}</span>}
</h5>
{param.description &&
<div
css={{ marginBottom: rhythm(-1 / 4) }}
dangerouslySetInnerHTML={{
__html: param.description.childMarkdownRemark.html,
}}
/>}
{param.properties &&
<div css={{ marginTop: rhythm(1 / 2) }}>
{param.properties.map(param => Param(param, depth + 1))}
</div>}
</div>
)
}
import Functions from "../../components/function-list"
import { rhythm, scale } from "../../utils/typography"

class ActionCreatorsDocs extends React.Component {
render() {
Expand All @@ -58,52 +18,17 @@ class ActionCreatorsDocs extends React.Component {
passed a collection of "Bound Action Creators" (functions which create and dispatch Redux actions when called)
which you can use to manipulate state on your site.
</p>
<h2>Functions</h2>
<h2 css={{ marginBottom: rhythm(1 / 2) }}>Functions</h2>
<ul css={{ ...scale(-1 / 5) }}>
{this.props.data.allDocumentationJs.edges.map(({ node }, i) => (
<li key={`function list ${node.name}`}>
<a href={`#${node.name}`}>{node.name}</a>
</li>
))}
<li key={`function list ${node.name}`}>
<a href={`#${node.name}`}>{node.name}</a>
</li>
))}
</ul>
<hr />
<h2>Reference</h2>
{this.props.data.allDocumentationJs.edges.map(({ node }, i) => (
<div
id={node.name}
key={`reference list ${node.name}`}
css={{ marginBottom: rhythm(1) }}
>
{i !== 0 && <hr />}
<h3><a href={`#${node.name}`}><code>{node.name}</code></a></h3>
<div
dangerouslySetInnerHTML={{
__html: node.description.childMarkdownRemark.html,
}}
/>
{node.params.length > 0 &&
<div>
<h4>Parameters</h4>
{node.params.map(Param)}
</div>}

{node.examples.length > 0 &&
<div>
<h4 css={{ marginTop: rhythm(1) }}>Example</h4>
{` `}
{node.examples.map((example, i) => (
<pre key={`${node.name} example ${i}`}>
<code
className="language-javascript"
dangerouslySetInnerHTML={{
__html: example.highlighted,
}}
/>
</pre>
))}
</div>}
</div>
))}
<Functions functions={this.props.data.allDocumentationJs.edges} />
</div>
)
}
Expand All @@ -116,56 +41,8 @@ query ActionCreatorDocsQuery {
allDocumentationJs(id: {regex: "/src.*actions.js/"}, sortBy: {fields: [name]}) {
edges {
node {
id
memberof
name
id
scope
description {
childMarkdownRemark {
html
}
}
returns {
title
}
examples {
raw
highlighted
}
params {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
}
}
}
...FunctionList
}
}
}
Expand Down
Loading