mirror of
https://github.com/status-im/react-native.git
synced 2025-01-29 18:54:58 +00:00
Add examples at the end of the doc pages
This commit is contained in:
parent
c8c4b41827
commit
a4a551c571
@ -13,6 +13,7 @@ var DocsSidebar = require('DocsSidebar');
|
|||||||
var H = require('Header');
|
var H = require('Header');
|
||||||
var Header = require('Header');
|
var Header = require('Header');
|
||||||
var Marked = require('Marked');
|
var Marked = require('Marked');
|
||||||
|
var Prism = require('Prism');
|
||||||
var React = require('React');
|
var React = require('React');
|
||||||
var Site = require('Site');
|
var Site = require('Site');
|
||||||
var slugify = require('slugify');
|
var slugify = require('slugify');
|
||||||
@ -285,6 +286,24 @@ var Autodocs = React.createClass({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderExample: function(docs) {
|
||||||
|
if (!docs.example) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<HeaderWithGithub
|
||||||
|
title="Examples"
|
||||||
|
path={docs.example.path}
|
||||||
|
/>
|
||||||
|
<Prism>
|
||||||
|
{docs.example.content.replace(/^[\s\S]*\*\//, '').trim()}
|
||||||
|
</Prism>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var metadata = this.props.metadata;
|
var metadata = this.props.metadata;
|
||||||
var docs = JSON.parse(this.props.children);
|
var docs = JSON.parse(this.props.children);
|
||||||
@ -301,6 +320,7 @@ var Autodocs = React.createClass({
|
|||||||
<h1>{metadata.title}</h1>
|
<h1>{metadata.title}</h1>
|
||||||
{content}
|
{content}
|
||||||
{this.renderFullDescription(docs)}
|
{this.renderFullDescription(docs)}
|
||||||
|
{this.renderExample(docs)}
|
||||||
<div className="docs-prevnext">
|
<div className="docs-prevnext">
|
||||||
{metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>← Prev</a>}
|
{metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>← Prev</a>}
|
||||||
{metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next →</a>}
|
{metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next →</a>}
|
||||||
|
@ -25,6 +25,17 @@ function getNameFromPath(filepath) {
|
|||||||
return filepath;
|
return filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExample(componentName) {
|
||||||
|
var path = '../Examples/UIExplorer/' + componentName + 'Example.js';
|
||||||
|
if (!fs.existsSync(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
path: path,
|
||||||
|
content: fs.readFileSync(path).toString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function componentsToMarkdown(type, json, filepath, i, styles) {
|
function componentsToMarkdown(type, json, filepath, i, styles) {
|
||||||
var componentName = getNameFromPath(filepath);
|
var componentName = getNameFromPath(filepath);
|
||||||
|
|
||||||
@ -38,6 +49,7 @@ function componentsToMarkdown(type, json, filepath, i, styles) {
|
|||||||
if (styles) {
|
if (styles) {
|
||||||
json.styles = styles;
|
json.styles = styles;
|
||||||
}
|
}
|
||||||
|
json.example = getExample(componentName);
|
||||||
|
|
||||||
var res = [
|
var res = [
|
||||||
'---',
|
'---',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user