Skip to content

Commit d935f45

Browse files
committed
Improvements in the docs generation
1 parent 74824cb commit d935f45

5 files changed

Lines changed: 87 additions & 11 deletions

File tree

website/core/DocsSidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var Metadata = require('Metadata');
99
var DocsSidebar = React.createClass({
1010
getCategories: function() {
1111
var metadatas = Metadata.files.filter(function(metadata) {
12-
return metadata.layout === 'docs';
12+
return metadata.layout === 'docs' || metadata.layout === 'autodocs';
1313
});
1414

1515
// Build a hashmap of article_id -> metadata

website/layout/AutodocsLayout.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @providesModule AutodocsLayout
3+
* @jsx React.DOM
4+
*/
5+
6+
var DocsSidebar = require('DocsSidebar');
7+
var Header = require('Header');
8+
var Marked = require('Marked');
9+
var React = require('React');
10+
var Site = require('Site');
11+
12+
13+
var Autodocs = React.createClass({
14+
renderProp: function(name, prop) {
15+
return (
16+
<div className="prop">
17+
<Header level={4} className="propTitle" toSlug={name}>
18+
{name}
19+
{' '}
20+
<span className="propType">{prop.type.name}</span></Header>
21+
<Marked>{prop.description}</Marked>
22+
</div>
23+
);
24+
},
25+
renderProps: function(props) {
26+
var result = Object.keys(props).sort().map((name) =>
27+
this.renderProp(name, props[name])
28+
);
29+
30+
return <div className="props">{result}</div>;
31+
},
32+
render: function() {
33+
var metadata = this.props.metadata;
34+
var content = JSON.parse(this.props.children);
35+
return (
36+
<Site section="docs">
37+
<section className="content wrap documentationContent">
38+
<DocsSidebar metadata={metadata} />
39+
<div className="inner-content">
40+
<a id="content" />
41+
<h1>{metadata.title}</h1>
42+
<Marked>
43+
{content.description}
44+
</Marked>
45+
{this.renderProps(content.props)}
46+
<div className="docs-prevnext">
47+
{metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>&larr; Prev</a>}
48+
{metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next &rarr;</a>}
49+
</div>
50+
</div>
51+
</section>
52+
</Site>
53+
);
54+
}
55+
});
56+
57+
module.exports = Autodocs;

website/server/convert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function backtickify(str) {
3030
function execute() {
3131
var MD_DIR = '../docs/';
3232

33-
var files = glob.sync('src/react-native/docs/*.*')
33+
var files = glob.sync('src/react-native/docs/*.*');
3434
files.forEach(function(file) {
3535
try {
3636
fs.unlinkSync(file);

website/server/extractDocs.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,20 @@ function docsToMarkdown(filepath, i) {
1818
return docs.resolver.findExportedReactCreateClassCall(node, recast) ||
1919
docs.resolver.findAllReactCreateClassCalls(node, recast)[0];
2020
}
21-
)
21+
);
2222

2323
var componentName = getNameFromPath(filepath);
2424

2525
var res = [
2626
'---',
2727
'id: ' + slugify(componentName),
2828
'title: ' + componentName,
29-
'layout: docs',
29+
'layout: autodocs',
3030
'category: Components',
3131
'permalink: docs/' + slugify(componentName) + '.html',
3232
components[i + 1] && ('next: ' + slugify(getNameFromPath(components[i + 1]))),
3333
'---',
34-
' ',
35-
json.description,
36-
' ',
37-
'# Props',
38-
'```',
39-
JSON.stringify(json.props, null, 2),
40-
'```',
34+
JSON.stringify(json, null, 2),
4135
].filter(function(line) { return line; }).join('\n');
4236
return res;
4337
}
@@ -49,6 +43,7 @@ var components = [
4943
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
5044
'../Libraries/Components/ScrollView/ScrollView.ios.js',
5145
'../Libraries/Text/Text.js',
46+
'../Libraries/Image/Image.ios.js',
5247
'../Libraries/Components/TextInput/TextInput.ios.js',
5348
'../Libraries/Components/Touchable/TouchableHighlight.js',
5449
'../Libraries/Components/Touchable/TouchableWithoutFeedback.js',

website/src/react-native/css/react-native.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,29 @@ div[data-twttr-id] iframe {
895895
text-align: center;
896896
}
897897

898+
899+
.props {
900+
background-color: hsl(198, 100%, 96%);
901+
}
902+
903+
.prop:nth-child(2n) {
904+
background-color: hsl(198, 100%, 94%);
905+
}
906+
907+
.propTitle {
908+
font-weight: bold;
909+
}
910+
911+
.prop {
912+
padding: 5px 10px;
913+
}
914+
915+
.propType {
916+
font-weight: normal;
917+
font-size: 15px;
918+
}
919+
920+
898921
#content {
899922
display: none;
900923
}
@@ -965,3 +988,4 @@ div[data-twttr-id] iframe {
965988
margin: 0;
966989
}
967990
}
991+

0 commit comments

Comments
 (0)