UNPKG

1.14 kBPlain TextView Raw
1;; A Twitter like web app
2;; Requires express js.
3
4;; The express server
5(var express (require "express"))
6(var app (express))
7(app.listen 3000)
8
9;; Templates we will be using
10;; Base template common to all pages.
11;; Note that strings in lispyscript are multiline.
12
13(template base (title header body)
14"<!DOCTYPE html>
15<html>
16<head>
17 <title>" title "</title>
18</head>
19<body>
20 <h1>" header "</h1>"
21 body
22"</body>
23</html>")
24
25;; index page template. (the body part)
26
27(template index ()
28"<h2>Enter Tweet</h2>
29<form action='/send' method='POST'>
30 <input type='text' length='140' name='tweet'/>
31 <input type='submit' value='Tweet'/>
32</form>
33<h2>All Tweets</h2>"
34(template-repeat tweets "<div>" elem "</div>"))
35
36
37(var tweets [])
38
39(app.get "/"
40 (function (req res)
41 (res.send (base "Our Own Twitter" "Our Own Twitter" (index)))))
42
43(app.post "/send" (express.bodyParser)
44 (function (req res)
45 (if (&& req.body req.body.tweet)
46 (do
47 (tweets.push req.body.tweet)
48 (res.redirect "/"))
49 (res.send {status: "nok", message: "No tweet Received"}))))
50
51(app.get "/tweets"
52 (function (req res)
53 (res.send tweets)))
54