Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit d601eaf

Browse files
committed
Run Prettier over all code
1 parent 5487243 commit d601eaf

14 files changed

+73
-72
lines changed

examples/dynamic/app.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ app.engine('js', reactViews.createEngine());
88

99
app.use(express.static(__dirname + '/public'));
1010

11-
app.get('/', function (req, res) {
11+
app.get('/', function(req, res) {
1212
var initialState = {
1313
items: [
1414
'document your code',
1515
'drop the kids off at the pool',
16-
'</script><script>alert(666)</script>'
16+
'</script><script>alert(666)</script>',
1717
],
18-
text: ''
18+
text: '',
1919
};
20-
res.render('Html', { data: initialState });
20+
res.render('Html', {data: initialState});
2121
});
2222

2323
var port = process.env.PORT || 3000;
24-
app.listen(port, function () {
24+
app.listen(port, function() {
2525
console.log('Dynamic react example listening on port ' + port);
2626
});

examples/dynamic/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"author": "Chris Johnson <[email protected]>",
66
"private": true,
77
"scripts": {
8-
"start": "browserify -t [ babelify --presets [ es2015 react ] --standalone main views/main.js -o public/main.js ] && node app.js"
8+
"start":
9+
"browserify -t [ babelify --presets [ es2015 react ] --standalone main views/main.js -o public/main.js ] && node app.js"
910
},
1011
"dependencies": {
1112
"babel-preset-es2015": "^6.24.1",

examples/dynamic/views/Content.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ class TodoApp extends React.Component {
3333
<TodoList items={this.state.items} />
3434
<form className="form-inline" onSubmit={this.handleSubmit}>
3535
<div className="form-group">
36-
<input type="text" className="form-control" placeholder="Write task" onChange={this.onChange} value={this.state.text} />
36+
<input
37+
type="text"
38+
className="form-control"
39+
placeholder="Write task"
40+
onChange={this.onChange}
41+
value={this.state.text}
42+
/>
3743
&nbsp;
3844
</div>
39-
<button className="btn btn-primary">{'Add #' + (this.state.items.length + 1)}</button>
45+
<button className="btn btn-primary">
46+
{'Add #' + (this.state.items.length + 1)}
47+
</button>
4048
</form>
4149
</div>
4250
);

examples/dynamic/views/Html.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ var ReactDOMServer = require('react-dom/server');
33
var Content = require('./Content');
44

55
class Html extends React.Component {
6-
76
render() {
87
var data = this.props.data;
98

109
// render the content as a dynamic react component
11-
var contentHtml = ReactDOMServer.renderToString(<Content {...data}/>);
10+
var contentHtml = ReactDOMServer.renderToString(<Content {...data} />);
1211

1312
/**
1413
* re-render the content as json,
@@ -48,25 +47,27 @@ class Html extends React.Component {
4847
* If avoidance is impossible,
4948
* know what you are doing and good luck.
5049
*/
51-
var initScript = 'main(' + JSON.stringify(data).replace(/script/g, 'scr"+"ipt') + ')';
50+
var initScript =
51+
'main(' + JSON.stringify(data).replace(/script/g, 'scr"+"ipt') + ')';
5252

5353
return (
5454
<html lang="en">
5555
<head>
56-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
57-
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
56+
<meta name="viewport" content="width=device-width, initial-scale=1" />
57+
<link
58+
rel="stylesheet"
59+
href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"
60+
/>
5861
</head>
5962
<body>
60-
<div id="content" dangerouslySetInnerHTML={{__html: contentHtml}}/>
63+
<div id="content" dangerouslySetInnerHTML={{__html: contentHtml}} />
6164

62-
<script src="/main.js"></script>
65+
<script src="/main.js" />
6366
<script dangerouslySetInnerHTML={{__html: initScript}} />
64-
6567
</body>
6668
</html>
6769
);
6870
}
69-
7071
}
7172

7273
module.exports = Html;

examples/dynamic/views/main.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ var React = require('react');
22
var ReactDOM = require('react-dom');
33
var Content = require('./Content');
44

5-
module.exports = function (data, containerId) {
5+
module.exports = function(data, containerId) {
66
var container = document.getElementById(containerId || 'content');
7-
ReactDOM.render(
8-
<Content {...data} />,
9-
container
10-
);
7+
ReactDOM.render(<Content {...data} />, container);
118
};

examples/simple/app.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Module dependencies.
43
*/
@@ -9,7 +8,7 @@ var user = require('./routes/user');
98
var http = require('http');
109
var path = require('path');
1110
var errorHandler = require('errorhandler');
12-
var logger = require('morgan')
11+
var logger = require('morgan');
1312

1413
// This should refer to the local React and gets installed via `npm install` in
1514
// the example.
@@ -36,6 +35,6 @@ app.locals.qaz = 'qut';
3635
app.get('/', routes.index);
3736
app.get('/users', user.list);
3837

39-
http.createServer(app).listen(app.get('port'), function(){
38+
http.createServer(app).listen(app.get('port'), function() {
4039
console.log('Express server listening on port ' + app.get('port'));
4140
});

examples/simple/routes/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
/*
32
* GET home page.
43
*/
54

6-
exports.index = function(req, res){
7-
res.render('index', { title: 'Express', foo: {bar:'baz'} });
5+
exports.index = function(req, res) {
6+
res.render('index', {title: 'Express', foo: {bar: 'baz'}});
87
};

examples/simple/routes/user.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
/*
32
* GET users listing.
43
*/
54

6-
exports.list = function(req, res){
7-
res.send("respond with a resource");
8-
};
5+
exports.list = function(req, res) {
6+
res.send('respond with a resource');
7+
};

index.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ var DEFAULT_OPTIONS = {
1818
beautify: false,
1919
transformViews: true,
2020
babel: {
21-
presets: [
22-
'react',
23-
'es2015',
24-
],
21+
presets: ['react', 'es2015'],
2522
},
2623
};
2724

@@ -35,14 +32,15 @@ function createEngine(engineOptions) {
3532
// Defer babel registration until the first request so we can grab the view path.
3633
if (!moduleDetectRegEx) {
3734
// Path could contain regexp characters so escape it first.
38-
// options.settings.views could be a single string or an array
35+
// options.settings.views could be a single string or an array
3936
moduleDetectRegEx = new RegExp(
40-
[].concat(options.settings.views)
41-
.map(viewPath => '^' + _escaperegexp(viewPath))
42-
.join('|')
43-
);
37+
[]
38+
.concat(options.settings.views)
39+
.map(viewPath => '^' + _escaperegexp(viewPath))
40+
.join('|')
41+
);
4442
}
45-
43+
4644
if (engineOptions.transformViews && !registered) {
4745
// Passing a RegExp to Babel results in an issue on Windows so we'll just
4846
// pass the view path.

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
22
"name": "express-react-views",
33
"version": "0.10.4",
4-
"description": "This is an Express view engine which renders React components on server. It renders static markup and *does not* support mounting those views on the client.",
5-
"keywords": [
6-
"express",
7-
"view engine",
8-
"react"
9-
],
4+
"description":
5+
"This is an Express view engine which renders React components on server. It renders static markup and *does not* support mounting those views on the client.",
6+
"keywords": ["express", "view engine", "react"],
107
"main": "index.js",
118
"scripts": {
129
"lint": "eslint .",

test/es5-component.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ var createClass = require('create-react-class');
44

55
function countTo(n) {
66
var a = [];
7-
for (var i = 0; i < n; i++ ) {
7+
for (var i = 0; i < n; i++) {
88
a.push(i + 1);
99
}
1010
return a.join(', ');
1111
}
1212

1313
var Index = createClass({
1414
propTypes: {
15-
title: PropTypes.string
15+
title: PropTypes.string,
1616
},
1717

1818
render: function() {
@@ -26,7 +26,7 @@ var Index = createClass({
2626
</p>
2727
</div>
2828
);
29-
}
29+
},
3030
});
3131

3232
module.exports = Index;

test/es6-component.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const PropTypes = require('prop-types');
33

44
function countTo(n) {
55
var a = [];
6-
for (var i = 0; i < n; i++ ) {
6+
for (var i = 0; i < n; i++) {
77
a.push(i + 1);
88
}
99
return a.join(', ');
@@ -25,7 +25,7 @@ class Index extends React.Component {
2525
}
2626

2727
Index.propTypes = {
28-
title: PropTypes.string
28+
title: PropTypes.string,
2929
};
3030

3131
module.exports = Index;

test/es6-flow-component.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const React = require('react');
22
const PropTypes = require('prop-types');
33

44
// Contrived example to show how one might use Flow type annotations
5-
function countTo(n:number):string {
5+
function countTo(n: number): string {
66
var a = [];
7-
for (var i = 0; i < n; i++ ) {
7+
for (var i = 0; i < n; i++) {
88
a.push(i + 1);
99
}
1010
return a.join(', ');
@@ -26,7 +26,7 @@ class Index extends React.Component {
2626
}
2727

2828
Index.propTypes = {
29-
title: PropTypes.string
29+
title: PropTypes.string,
3030
};
3131

3232
module.exports = Index;

test/index.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var viewEngine = require('..');
44
var viewOptions = {
55
settings: {
66
env: 'development',
7-
views: __dirname
8-
}
7+
views: __dirname,
8+
},
99
};
1010

1111
function testComponent(path, cb) {
@@ -21,18 +21,20 @@ function testComponent(path, cb) {
2121
});
2222
}
2323

24-
async.series([
25-
function testES5Module(next) {
26-
testComponent(__dirname + '/es5-component.jsx', next);
27-
},
28-
function testES6Module(next) {
29-
testComponent(__dirname + '/es6-component.jsx', next);
30-
},
31-
function testES6FlowModule(next) {
32-
testComponent(__dirname + '/es6-flow-component.jsx', next);
24+
async.series(
25+
[
26+
function testES5Module(next) {
27+
testComponent(__dirname + '/es5-component.jsx', next);
28+
},
29+
function testES6Module(next) {
30+
testComponent(__dirname + '/es6-component.jsx', next);
31+
},
32+
function testES6FlowModule(next) {
33+
testComponent(__dirname + '/es6-flow-component.jsx', next);
34+
},
35+
],
36+
function done() {
37+
console.log('All tests pass!');
38+
process.exit(0);
3339
}
34-
], function done() {
35-
console.log('All tests pass!');
36-
process.exit(0);
37-
});
38-
40+
);

0 commit comments

Comments
 (0)