-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
74 lines (65 loc) · 1.65 KB
/
app.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
var kiwi = require('kiwi'),
sys = require('sys');
kiwi.seed('mongodb-native');
var app = require('express').createServer(),
quizProvider = require('./quizprovider-mongodb').newQuizProvider();
//app.configure(function(){
//app.use((MethodOverride);
//use(ContentLength);
//use(Logger);
//set('root', __dirname);
//})
app.get('/', function(req, res, params) {
quizProvider.findLatest(function(err, quizResult){
res.render('quiz-show.html.haml', {
locals: {
title: 'Latest Quiz',
quiz: quizResult
}
});
})
});
app.get('/quiz/new', function(req, res, params){
res.render('quiz-edit.html.haml', {
locals: {
title: 'New Quiz',
quiz: {
name: 'New Quiz',
publishOn: (new Date()).toString()
}
}
});
});
app.post('/quiz/new', function(req, res, params) {
quizProvider.save({
name: req.param('name'),
publishOn: new Date(req.param('publishOn'))
}, function(err, result){
res.render('quiz-show.html.haml', {
locals: {
slug: function(str) { return str.toLowerCase().replace(/\s/,"-"); },
title: 'Quiz',
quiz: result
}
});
});
});
app.get('/quiz/:id', function(req, res, params) {
quizProvider.findByName(params.name, function(err, quizResult){
res.render('quiz-show.html.haml', {
locals: {
title: 'Latest Quiz',
quiz: quizResult
}
});
})
});
app.get(/^\/(\w).css/, function(req, res, params) {
res.render(params[0] + '.css.sass', { layout: false });
});
app.dynamicHelpers({
slug: function(req, res, params){
return params[0].toLowerCase().replace(/\s/,"-");
}
});
app.listen(3000);