[Docs] Add a 'run this example' link to AlertIOS docs, plus supporting code to add more links progressively

This commit is contained in:
Joshua Sierles 2015-06-30 23:39:49 +02:00
parent eee630827a
commit 5af8849aa4
3 changed files with 35 additions and 3 deletions

View File

@ -264,6 +264,20 @@ var APIDoc = React.createClass({
}); });
var HeaderWithGithub = React.createClass({ var HeaderWithGithub = React.createClass({
renderRunnableLink: function() {
if (this.props.metadata && this.props.metadata.runnable) {
return (
<a
className="run-example"
target="_blank"
href={'https://rnplay.org/apps/l3Zi2g?route='+this.props.metadata.title+'&file=' + this.props.metadata.title+ "Example.js"}>
Run this example
</a>
);
}
},
render: function() { render: function() {
return ( return (
<H level={3} toSlug={this.props.title}> <H level={3} toSlug={this.props.title}>
@ -272,6 +286,7 @@ var HeaderWithGithub = React.createClass({
href={'https://github.com/facebook/react-native/blob/master/' + this.props.path}> href={'https://github.com/facebook/react-native/blob/master/' + this.props.path}>
Edit on GitHub Edit on GitHub
</a> </a>
{this.renderRunnableLink()}
{this.props.title} {this.props.title}
</H> </H>
); );
@ -296,7 +311,7 @@ var Autodocs = React.createClass({
); );
}, },
renderExample: function(docs) { renderExample: function(docs, metadata) {
if (!docs.example) { if (!docs.example) {
return; return;
} }
@ -306,6 +321,7 @@ var Autodocs = React.createClass({
<HeaderWithGithub <HeaderWithGithub
title="Examples" title="Examples"
path={docs.example.path} path={docs.example.path}
metadata={metadata}
/> />
<Prism> <Prism>
{docs.example.content.replace(/^[\s\S]*?\*\//, '').trim()} {docs.example.content.replace(/^[\s\S]*?\*\//, '').trim()}
@ -330,7 +346,7 @@ var Autodocs = React.createClass({
<h1>{metadata.title}</h1> <h1>{metadata.title}</h1>
{content} {content}
{this.renderFullDescription(docs)} {this.renderFullDescription(docs)}
{this.renderExample(docs)} {this.renderExample(docs, metadata)}
<div className="docs-prevnext"> <div className="docs-prevnext">
{metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>&larr; Prev</a>} {metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>&larr; Prev</a>}
{metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next &rarr;</a>} {metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next &rarr;</a>}

View File

@ -44,6 +44,16 @@ function getExample(componentName) {
}; };
} }
// Determines whether a component should have a link to a runnable example
function isRunnable(componentName) {
if (componentName === 'AlertIOS') {
return true;
}
return false;
}
// Hide a component from the sidebar by making it return false from // Hide a component from the sidebar by making it return false from
// this function // this function
function shouldDisplayInSidebar(componentName) { function shouldDisplayInSidebar(componentName) {
@ -99,6 +109,7 @@ function componentsToMarkdown(type, json, filepath, i, styles) {
'permalink: docs/' + slugify(componentName) + '.html', 'permalink: docs/' + slugify(componentName) + '.html',
'next: ' + next, 'next: ' + next,
'sidebar: ' + shouldDisplayInSidebar(componentName), 'sidebar: ' + shouldDisplayInSidebar(componentName),
'runnable:' + isRunnable(componentName),
'---', '---',
JSON.stringify(json, null, 2), JSON.stringify(json, null, 2),
].filter(function(line) { return line; }).join('\n'); ].filter(function(line) { return line; }).join('\n');

View File

@ -973,6 +973,12 @@ div[data-twttr-id] iframe {
float: right; float: right;
} }
.run-example {
font-size: 15px;
float: right;
margin-right: 20px;
}
#content { #content {
display: none; display: none;
} }
@ -1043,4 +1049,3 @@ div[data-twttr-id] iframe {
margin: 0; margin: 0;
} }
} }