Skip to content

Commit ac39dd2

Browse files
escatonmarkelog
authored andcommitted
Reintroduce "react-router"
Closes gh-36
1 parent e0cc13b commit ac39dd2

File tree

18 files changed

+117
-325
lines changed

18 files changed

+117
-325
lines changed

app/createPages.jsx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import fs from 'fs';
22
import path from 'path';
33
import renderHtml from './lib/renderHtml';
44
import React from 'react';
5+
import Router from 'react-router';
56
import AppView from './views/AppView';
67
import dataStore from './stores/dataStore';
7-
import navigation from './actions/navigation';
8-
import locationStore from './stores/locationStore';
98
import collectData from './lib/collectData';
109

1110
export default collectData().then(/** @param {JscsModel} data */ function(data) {
@@ -19,38 +18,35 @@ export default collectData().then(/** @param {JscsModel} data */ function(data)
1918
dataStore.setData(data);
2019

2120
var pathsToRender = [
22-
'index.html',
23-
'overview.html',
24-
'contributing.html',
25-
'rules.html',
26-
'changelog.html'
21+
'index',
22+
'overview',
23+
'contributing',
24+
'rules',
25+
'changelog'
2726
].concat(data.getRules().map(/** @param {RuleModel} rule */ function(rule) {
28-
return 'rule/' + rule.getName() + '.html';
27+
return 'rule/' + rule.getName();
2928
}));
3029

3130
pathsToRender.forEach(function(filePath) {
32-
navigation.navigateToPath(filePath);
33-
34-
var html = renderHtml({
35-
title: locationStore.getTitle(),
36-
content: React.renderToString(React.createElement(AppView)),
37-
dataPath: locationStore.renderPath('assets', 'data', '.js'),
38-
scriptPath: locationStore.renderPath('assets', 'bundle', '.js'),
39-
stylePath: locationStore.renderPath('assets', 'bundle', '.css'),
40-
locationState: JSON.stringify({
41-
page: locationStore.getPage(),
42-
data: locationStore.getData()
43-
})
44-
});
45-
46-
var filename = outputDir + '/' + filePath;
47-
var dirname = path.dirname(filename);
48-
if (!fs.existsSync(dirname)) {
49-
fs.mkdirSync(dirname);
50-
}
5131

52-
fs.writeFileSync(filename, html);
32+
Router.run(AppView, '/' + (filePath === 'index' ? '' : filePath), function (Handler, state) {
33+
var html = renderHtml({
34+
title: 'JSCS',
35+
content: React.renderToString(<Handler/>),
36+
dataPath: '/assets/data.js',
37+
scriptPath: '/assets/bundle.js',
38+
stylePath: '/assets/bundle.css'
39+
});
40+
41+
var filename = outputDir + '/' + filePath + '.html';
42+
var dirname = path.dirname(filename);
43+
if (!fs.existsSync(dirname)) {
44+
fs.mkdirSync(dirname);
45+
}
46+
47+
fs.writeFileSync(filename, html);
48+
console.log(filename);
49+
});
5350

54-
console.log(filePath);
5551
});
5652
});

app/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Router from 'react-router';
23
import dataStore from './stores/dataStore';
34
import JscsModel from './models/JscsModel';
45

@@ -8,4 +9,6 @@ if (typeof window.__jscsData !== 'undefined') {
89

910
var AppView = require('./views/AppView');
1011

11-
React.render(<AppView />, document.getElementById('root'));
12+
Router.run(AppView, Router.HistoryLocation, function (Handler) {
13+
React.render(<Handler/>, document.getElementById('root'));
14+
});

app/lib/html.tpl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
</head>
88
<body>
9-
<div id="root">
10-
{%content%}
11-
</div>
12-
<script type="application/javascript">
13-
window.__locationState = {%locationState%};
14-
</script>
9+
<div id="root">{%content%}</div>
1510
<script type="application/javascript" src="{%dataPath%}"></script>
1611
<script type="application/javascript" src="{%scriptPath%}"></script>
1712
</body>

app/lib/renderHtml.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function renderHtml({title, content, dataPath, scriptPath, stylePath, locationSt
88
.replace('{%dataPath%}', dataPath)
99
.replace('{%scriptPath%}', scriptPath)
1010
.replace('{%stylePath%}', stylePath)
11-
.replace('{%locationState%}', locationState)
1211
.replace('{%content%}', content);
1312
}
1413

app/mixins/PageTitle.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var mixin = {
2+
componentWillMount() {
3+
var title = this.getTitle();
4+
if (typeof document !== 'undefined') {
5+
document.title = title;
6+
}
7+
this.context.router._title = title;
8+
},
9+
getTitle() {
10+
var page = this.getRoutes()[1].name;
11+
if (page === 'index') {
12+
return 'JSCS: JavaScript Code Style checker';
13+
} else {
14+
var title = '';
15+
if (page === 'rule') {
16+
title = this.props.params.ruleName + ' rule';
17+
} else {
18+
title = page.substr(0, 1).toUpperCase() + page.substr(1);
19+
}
20+
return 'JSCS - ' + title;
21+
}
22+
}
23+
};
24+
25+
export default mixin;

app/prepareData.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'fs';
22
import renderHtml from './lib/renderHtml';
33
import React from 'react';
44
import dataStore from './stores/dataStore';
5-
import locationStore from './stores/locationStore';
65
import collectData from './lib/collectData';
76

87
export default collectData().then(/** @param {JscsModel} data */ function(data) {

app/stores/locationStore.jsx

Lines changed: 0 additions & 161 deletions
This file was deleted.

app/views/AppView/RouteView.jsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)