Skip to content

Commit 3be8dcc

Browse files
committed
Initial import
0 parents  commit 3be8dcc

File tree

16 files changed

+574
-0
lines changed

16 files changed

+574
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
data

app.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
var express = require('express');
3+
var path = require('path');
4+
var favicon = require('serve-favicon');
5+
var logger = require('morgan');
6+
var cookieParser = require('cookie-parser');
7+
var bodyParser = require('body-parser');
8+
9+
var routes = require('./routes/index');
10+
var diff = require('./routes/diff');
11+
12+
var app = express();
13+
14+
// view engine setup
15+
app.set('views', path.join(__dirname, 'views'));
16+
app.set('view engine', 'jade');
17+
18+
// uncomment after placing your favicon in /public
19+
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
20+
app.use(logger('dev'));
21+
app.use(bodyParser.json());
22+
app.use(bodyParser.urlencoded({ extended: false }));
23+
app.use(cookieParser());
24+
app.use(express.static(path.join(__dirname, 'public')));
25+
26+
app.use('/', routes);
27+
app.use('/diff', diff);
28+
29+
// catch 404 and forward to error handler
30+
app.use(function (req, res, next) {
31+
var err = new Error('Not Found');
32+
err.status = 404;
33+
next(err);
34+
});
35+
36+
// error handlers
37+
38+
// development error handler
39+
// will print stacktrace
40+
if (app.get('env') === 'development') {
41+
app.use(function (err, req, res, next) {
42+
res.status(err.status || 500);
43+
res.render('error', {
44+
message: err.message,
45+
error: err
46+
});
47+
});
48+
}
49+
50+
// production error handler
51+
// no stacktraces leaked to user
52+
app.use(function (err, req, res, next) {
53+
res.status(err.status || 500);
54+
res.render('error', {
55+
message: err.message,
56+
error: {}
57+
});
58+
});
59+
60+
61+
module.exports = app;

bin/www

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('diffofhtmls:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "diffofhtmls",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www"
7+
},
8+
"dependencies": {
9+
"body-parser": "~1.13.2",
10+
"cookie-parser": "~1.3.5",
11+
"debug": "~2.2.0",
12+
"diff": "^2.2.1",
13+
"express": "~4.13.1",
14+
"jade": "~1.11.0",
15+
"morgan": "~1.6.1",
16+
"serve-favicon": "~2.3.0"
17+
}
18+
}

public/images/w3c.svg

+25
Loading

public/images/whatwg.svg

+4
Loading

public/stylesheets/style.css

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
html {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
body {
7+
margin: 0;
8+
padding: 0;
9+
background: #fff;
10+
color: #333;
11+
font-family: sans-serif;
12+
}
13+
14+
header,
15+
main,
16+
footer {
17+
padding: 1rem 2rem;
18+
}
19+
20+
a {
21+
color: #00f;
22+
}
23+
24+
header {
25+
background: #333;
26+
color: #fff;
27+
}
28+
29+
header a {
30+
color: #fff;
31+
}
32+
33+
.globalLogo {
34+
float: left;
35+
}
36+
37+
.globalNav {
38+
float: right;
39+
}
40+
41+
.globalNav ul {
42+
margin: 0;
43+
padding: 0;
44+
}
45+
46+
.globalNav li {
47+
float: left;
48+
margin: 0;
49+
padding-left: 2rem;
50+
list-style: none;
51+
}
52+
53+
header:after {
54+
clear: both;
55+
content: '';
56+
height: 0;
57+
display: block;
58+
}
59+
60+
61+
footer {
62+
background: #333;
63+
color: #fff;
64+
}
65+
66+
footer a {
67+
color: #fff;
68+
}
69+
70+
71+
.icons .whatwg,
72+
.icons .w3c {
73+
margin-left:.5rem;
74+
height: .75em;
75+
vertical-align: baseline;
76+
}

routes/diff.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
var path = require('path');
3+
var express = require('express');
4+
var router = express.Router();
5+
var utils = require('./utils');
6+
7+
router.param('chapter', function (req, res, next, chapter) {
8+
req.chapter = chapter;
9+
10+
// TODO ensure chapter exists
11+
next();
12+
});
13+
14+
router.param('section', function (req, res, next, section) {
15+
req.section = section;
16+
17+
// TODO ensure section exists
18+
next();
19+
});
20+
21+
router.get('/:chapter/:section', function (req, res, next) {
22+
var chapterPath = req.chapter;
23+
var sectionPath = req.section;
24+
var htmlPath = chapterPath + '/' + sectionPath;
25+
26+
utils.findSection(htmlPath).then(function (section) {
27+
if (!section || (!section.whatwg && !section.w3c)) {
28+
var err = new Error('There are no such section');
29+
next(err);
30+
return;
31+
}
32+
33+
Promise.all([
34+
utils.loadSectionHTML('whatwg', htmlPath),
35+
utils.loadSectionHTML('w3c', htmlPath),
36+
]).then(function (data) {
37+
var whatwg = data[0];
38+
var w3c = data[1];
39+
40+
var diffs = utils.computeDiff(whatwg, w3c);
41+
42+
res.render('diff', {
43+
title: 'Diff of ' + section.heading + ' | ' + section.parent.heading,
44+
section: section,
45+
diffs: diffs,
46+
});
47+
}).catch(function (err) {
48+
next(err);
49+
});
50+
}).catch(function (err) {
51+
next(err);
52+
});
53+
});
54+
55+
module.exports = router;

routes/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
var express = require('express');
3+
var router = express.Router();
4+
var utils = require('./utils');
5+
6+
7+
router.get('/about', function (req, res, next) {
8+
res.render('about', {
9+
title: 'About',
10+
});
11+
});
12+
13+
14+
router.get('/', function (req, res, next) {
15+
utils.loadIndexJSON().then(function(index) {
16+
res.render('index', {
17+
title: 'Top',
18+
index: index
19+
});
20+
}).catch(function(err) {
21+
next(err);
22+
});
23+
});
24+
25+
module.exports = router;

0 commit comments

Comments
 (0)