/
app.coffee
executable file
·63 lines (51 loc) · 1.24 KB
/
app.coffee
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
# Open Microblogger
# June 23, 2013
app = require( 'zygote' ).config
port: 4444,
dbname: 'omb2',
dbuser: 'brian',
dbpass: '',
dbhost: 'localhost',
dbport: 5432
class Post extends app.Model
class Home extends app.View
constructor: ->
super
@controller = new Posts @model, @
class Show extends app.View
constructor: ( model, req, res, id ) ->
super
@controller = new PostsShow @model, @, id
class PostsShow extends app.Controller
constructor: ( Post, View, id ) ->
super
Post.find( id )
render: ->
@view.render()
class Posts extends app.Controller
constructor: ( Post ) ->
super
Post.find()
render: ->
@view.render()
app.get '/', ( req, res ) ->
@model = new Post
@view = new Home @model, req, res
app.get '/:id', ( req, res, id ) ->
@model = new Post
@view = new Show @model, req, res, id
app.post '/post/new', ( req, res ) ->
@fullBody = '';
req.on 'data', (chunk) =>
@fullBody += chunk.toString()
req.on 'end', =>
@data = JSON.parse @fullBody
@model = new Post
@post = @model.create @data
res.end 'ok'
$('#post-save').click =>
@model = new Post
@model.save()
$( '#post-title' ).val ''
$( '.modal' ).removeClass 'active'
$( '.modal-bg' ).remove()