This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathipsum.js
90 lines (85 loc) · 2.72 KB
/
ipsum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var express = require('express'),
data = require('./data.js'),
random = require('./random.js'),
pub_dir = __dirname + '/public',
levels = {
padawan: {
terms: data.commonTerms,
termCount: data.commonTerms.length
},
'grand-master': {
terms: data.extendedTerms,
termCount: data.extendedTerms.length
}
},
defaultIndexOptions = {
pageId: 'index',
paragraphs: [],
paragraphCount: 5,
startWith: true,
termLevel: 'padawan',
debugMesasge: ''
},
app = express.createServer(express.logger());
app.configure(function () {
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
app.configure('development', function () {
app.use(express.static(pub_dir));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function () {
var oneYear = 31557600000;
app.use(express.static(pub_dir, { maxAge: oneYear }));
app.use(express.errorHandler());
});
app.get('/disclaimer', function (request, response) {
response.render('disclaimer', {
pageId: 'disclaimer',
debugMesasge: ''
});
});
app.get('/', function (request, response) {
response.render('index', defaultIndexOptions);
});
app.post('/', function (request, response) {
var paragraphCount = parseInt(request.body['paragraph-count'], 10) || defaultIndexOptions.paragraphCount,
startWith = request.body['start-with'],
level = levels[request.body['term-level']] || levels[defaultIndexOptions.termLevel],
paragraphLength = 500,
paragraphs = [],
i, j,
paragraph,
sentenceLength,
term;
for (i = 0; i < paragraphCount; i++) {
paragraph = startWith ? 'Lucas ipsum dolor sit amet ' : '';
while (paragraph.length < paragraphLength) {
sentenceLength = startWith ? 10 : random.getRandomInteger(4, 10);
for (j = 0; j < sentenceLength; j++) {
term = level.terms[random.getRandomInteger(0, level.termCount)];
if (j === 0 && !startWith) {
term = term[0].toUpperCase() + term.slice(1);
}
paragraph += term + (j === sentenceLength - 1 ? '. ' : ' ');
}
startWith = false;
}
paragraphs.push(paragraph);
}
response.render('index', {
pageId: 'index',
paragraphs: paragraphs,
paragraphCount: paragraphCount,
startWith: request.body['start-with'],
termLevel: request.body['term-level'],
debugMessage: 'start-with = ' + request.body['start-with']
});
});
var port = process.env.PORT || 3000;
app.listen(port, function () {
console.log("Listening on " + port);
});