Skip to content

Commit

Permalink
Merge pull request react-bootstrap#634 from AlexKVal/buildDocs
Browse files Browse the repository at this point in the history
Return <DOCTYPE!> back and little refactoring of docs/build.js
  • Loading branch information
mtscout6 committed May 12, 2015
2 parents 70c6efd + e663e82 commit 32ca419
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 45 deletions.
30 changes: 20 additions & 10 deletions docs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,33 @@ const license = path.join(repoRoot, 'LICENSE');
const readmeSrc = path.join(__dirname, 'README.docs.md');
const readmeDest = path.join(docsBuilt, 'README.md');

/**
* Generates HTML code for `fileName` page.
*
* @param {string} fileName Path for Router.Route
* @return {Promise} promise
* @internal
*/
function generateHTML(fileName) {
return new Promise((resolve, reject) => {
Router.run(routes, '/' + fileName, Handler => {
let html = React.renderToString(React.createElement(Handler));
html = '<!doctype html>' + html;
let write = fsp.writeFile(path.join(docsBuilt, fileName), html);
resolve(write);
});
});
}

export default function BuildDocs() {
console.log('Building: '.cyan + 'docs'.green);

return exec(`rimraf ${docsBuilt}`)
.then(() => fsp.mkdir(docsBuilt))
.then(() => {
let writes = Root
.getPages()
.map(fileName => new Promise((resolve, reject) => {
Router.run(routes, '/' + fileName, Handler => {
let RootHTML = React.renderToString(React.createElement(Handler));
let write = fsp.writeFile(path.join(docsBuilt, fileName), RootHTML);
resolve(write);
});
}));
let pagesGenerators = Root.getPages().map(generateHTML);

return Promise.all(writes.concat([
return Promise.all(pagesGenerators.concat([
exec(`webpack --config webpack.docs.js -p --bail`),
copy(license, docsBuilt),
copy(readmeSrc, readmeDest)
Expand Down
2 changes: 1 addition & 1 deletion docs/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (development) {

Router.run(routes, req.url, Handler => {
let html = React.renderToString(<Handler assetBaseUrl={target} />);
res.send(html);
res.send('<!doctype html>' + html);
});
});

Expand Down
44 changes: 10 additions & 34 deletions docs/src/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import Router from 'react-router';
const Root = React.createClass({
statics: {

/**
* Get the doctype the page expects to be rendered with
*
* @returns {string}
*/
getDoctype() {
return '<!doctype html>';
},

/**
* Get the list of pages that are renderable
*
Expand All @@ -25,21 +16,6 @@ const Root = React.createClass({
'getting-started.html',
'components.html'
];
},

renderToString(props) {
return Root.getDoctype() +
React.renderToString(<Root {...props} />);
},

/**
* Get the Base url this app sits at
* This url is appended to all app urls to make absolute url's within the app.
*
* @returns {string}
*/
getBaseUrl() {
return '/';
}
},

Expand Down Expand Up @@ -84,19 +60,19 @@ const Root = React.createClass({
};

return (
<html>
<head dangerouslySetInnerHTML={head} />
<html>
<head dangerouslySetInnerHTML={head} />

<body>
<Router.RouteHandler />
<body>
<Router.RouteHandler />

<script dangerouslySetInnerHTML={browserInitScriptObj} />
<script src={`${this.props.assetBaseUrl}/assets/bundle.js`} />
</body>
</html>
);
<script dangerouslySetInnerHTML={browserInitScriptObj} />
<script src={`${this.props.assetBaseUrl}/assets/bundle.js`} />
</body>
</html>
);
}
});


module.exports = Root;
export default Root;

0 comments on commit 32ca419

Please sign in to comment.