-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(ComponentDoc): refactor, add sidebar navigation
- Loading branch information
Alexander Fedyashov
committed
Sep 12, 2017
1 parent
d288f3b
commit 4e5dc6c
Showing
8 changed files
with
182 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ coverage/ | |
dist/ | ||
docs/build/ | ||
docs/app/docgenInfo.json | ||
docs/app/menuInfo.json | ||
dll/ | ||
|
||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { Header } from 'semantic-ui-react' | ||
|
||
import { neverUpdate } from 'docs/app/HOC' | ||
|
||
const headerStyle = { marginBottom: '0.25em' } | ||
|
||
const ComponentDocHeader = ({ description, name }) ( | ||
<Header as='h1' style={headerStyle}> | ||
{name} | ||
<Header.Subheader>{description}</Header.Subheader> | ||
</Header> | ||
) | ||
|
||
ComponentDocHeader.propTypes = { | ||
description: PropTypes.string, | ||
name: PropTypes.string, | ||
} | ||
|
||
export default neverUpdate(ComponentDocHeader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import gutil from 'gulp-util' | ||
import _ from 'lodash' | ||
import path from 'path' | ||
import through from 'through2' | ||
|
||
import config from '../../config' | ||
import { parseDocExample, parseDocSection } from './util' | ||
|
||
const examplesPath = `${config.paths.docsSrc()}/Examples/` | ||
|
||
export default (filename) => { | ||
const defaultFilename = 'menuInfo.json' | ||
const result = {} | ||
const pluginName = 'gulp-menugen' | ||
let finalFile | ||
let latestFile | ||
|
||
function bufferContents(file, enc, cb) { | ||
latestFile = file | ||
|
||
if (file.isNull()) { | ||
cb(null, file) | ||
return | ||
} | ||
|
||
if (file.isStream()) { | ||
cb(new gutil.PluginError(pluginName, 'Streaming is not supported')) | ||
return | ||
} | ||
|
||
try { | ||
const relativePath = file.path.replace(examplesPath, '') | ||
const [,component,section] = _.split(relativePath, '/') | ||
|
||
if(section === 'index.js') { | ||
result[component] = parseDocExample(file.contents) | ||
cb() | ||
return | ||
} | ||
const { examples } = parseDocSection(file.contents) | ||
|
||
result[component][section]['examples'] = examples | ||
// result[component][section] = 100 | ||
cb() | ||
} catch (err) { | ||
const pluginError = new gutil.PluginError(pluginName, err) | ||
pluginError.message += `\nFile: ${file.path}.` | ||
this.emit('error', pluginError) | ||
} | ||
} | ||
|
||
function endStream(cb) { | ||
finalFile = latestFile.clone({ contents: false }) | ||
finalFile.path = path.join(latestFile.base, (filename || defaultFilename)) | ||
finalFile.contents = new Buffer(JSON.stringify(result, null, 2)) | ||
this.push(finalFile) | ||
cb() | ||
} | ||
|
||
return through.obj(bufferContents, endStream) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export parseDefaultValue from './parseDefaultValue' | ||
export parseDocBlock from './parseDocBlock' | ||
export parseDocExample from './parseDocExample' | ||
export parseDocSection from './parseDocSection' | ||
export parseType from './parseType' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _ from 'lodash' | ||
import { parse } from "babylon"; | ||
import traverse from "babel-traverse"; | ||
|
||
|
||
export default (buffer) => { | ||
const ast = parse(buffer.toString(), { | ||
sourceType: 'module', | ||
plugins: [ | ||
"classProperties", | ||
"jsx", | ||
] | ||
}); | ||
const sections = {} | ||
|
||
traverse(ast, { | ||
ImportDeclaration: (path) => { | ||
const specifier = _.first(path.get('specifiers')) | ||
|
||
if(!specifier.isImportDefaultSpecifier()) return | ||
|
||
const name = _.get(specifier, 'node.local.name') | ||
const source = _.get(path, 'node.source.value') | ||
|
||
if(_.startsWith(source, './')) { | ||
sections[name] = { | ||
name, | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return sections | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import _ from 'lodash' | ||
import { parse } from "babylon"; | ||
import traverse from "babel-traverse"; | ||
|
||
export default (buffer) => { | ||
const ast = parse(buffer.toString(), { | ||
sourceType: 'module', | ||
plugins: [ | ||
"classProperties", | ||
"jsx", | ||
] | ||
}); | ||
const section = { | ||
examples: [] | ||
} | ||
let position = 0 | ||
|
||
traverse(ast, { | ||
JSXOpeningElement: (path) => { | ||
const attrs = _.map(_.get(path, 'node.attributes'), (a) => { | ||
return { | ||
name: _.get(a, 'name.name'), | ||
value: _.get(a, 'value.value') | ||
} | ||
}) | ||
const name = _.get(path, 'node.name.name') | ||
|
||
if(name === 'ExampleSection') { | ||
const title = _.find(attrs, { name: 'title'}) | ||
section.name = title.name | ||
return | ||
} | ||
|
||
if(name === 'ComponentExample') { | ||
const title = _.find(attrs, { name: 'title'}) | ||
if(title) { | ||
const examplePath = _.find(attrs, { name: 'examplePath'}).value | ||
|
||
section.examples.push({ title: title.value, path: examplePath }) | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return section | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters