[Website] Fix typehint parsing and add header between description and props/methods
This commit is contained in:
parent
09b43d7284
commit
032449c54c
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var DocsSidebar = require('DocsSidebar');
|
var DocsSidebar = require('DocsSidebar');
|
||||||
|
var H = require('Header');
|
||||||
var Header = require('Header');
|
var Header = require('Header');
|
||||||
var Marked = require('Marked');
|
var Marked = require('Marked');
|
||||||
var React = require('React');
|
var React = require('React');
|
||||||
|
@ -14,6 +15,9 @@ var slugify = require('slugify');
|
||||||
var ComponentDoc = React.createClass({
|
var ComponentDoc = React.createClass({
|
||||||
renderType: function(type) {
|
renderType: function(type) {
|
||||||
if (type.name === 'enum') {
|
if (type.name === 'enum') {
|
||||||
|
if (typeof type.value === 'string') {
|
||||||
|
return type.value;
|
||||||
|
}
|
||||||
return 'enum(' + type.value.map((v => v.value)).join(', ') + ')';
|
return 'enum(' + type.value.map((v => v.value)).join(', ') + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +85,7 @@ var ComponentDoc = React.createClass({
|
||||||
<Marked>
|
<Marked>
|
||||||
{content.description}
|
{content.description}
|
||||||
</Marked>
|
</Marked>
|
||||||
|
<H level={3}>Props</H>
|
||||||
{this.renderProps(content.props, content.composes)}
|
{this.renderProps(content.props, content.composes)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -100,6 +105,19 @@ var APIDoc = React.createClass({
|
||||||
.join('\n');
|
.join('\n');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderTypehintRec: function(typehint) {
|
||||||
|
if (typehint.type === 'simple') {
|
||||||
|
return typehint.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typehint.type === 'generic') {
|
||||||
|
return this.renderTypehintRec(typehint.value[0]) + '<' + this.renderTypehintRec(typehint.value[1]) + '>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(typehint);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
renderTypehint: function(typehint) {
|
renderTypehint: function(typehint) {
|
||||||
try {
|
try {
|
||||||
var typehint = JSON.parse(typehint);
|
var typehint = JSON.parse(typehint);
|
||||||
|
@ -107,11 +125,7 @@ var APIDoc = React.createClass({
|
||||||
return typehint;
|
return typehint;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typehint.type === 'simple') {
|
return this.renderTypehintRec(typehint);
|
||||||
return typehint.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ':(' + JSON.stringify(typehint);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMethod: function(method) {
|
renderMethod: function(method) {
|
||||||
|
@ -161,8 +175,8 @@ var APIDoc = React.createClass({
|
||||||
<Marked>
|
<Marked>
|
||||||
{this.removeCommentsFromDocblock(content.docblock)}
|
{this.removeCommentsFromDocblock(content.docblock)}
|
||||||
</Marked>
|
</Marked>
|
||||||
|
<H level={3}>Methods</H>
|
||||||
{this.renderMethods(content.methods)}
|
{this.renderMethods(content.methods)}
|
||||||
<pre>{JSON.stringify(content, null, 2)}</pre>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue