forked from prague-lambda/clojure-web-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.clj
44 lines (40 loc) · 1.52 KB
/
page.clj
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
(ns demo.page
(:require [demo.message :as msg])
(:use [hiccup core element form util page]))
(defn page [TITLE & BODY]
(html5 [:html
[:head
[:title TITLE]]
(into [:body] BODY)]))
(defn include-cljs []
(list (include-js "/js/goog/base.js")
(include-js "/main.js")
(javascript-tag "goog.require (\"demo.repl\");")
(javascript-tag "goog.require (\"demo.refresh\");")))
(defn list-chatrooms [MAP]
(page "Simple chatroom"
;; list rooms
(for [[name room] (sort-by first MAP)]
[:p (link-to (str "room/" (url-encode name)) name) "[" (count room) "]"])
;; add a form to create new room
[:form {:method "post" :action "new-room"}
"Room name:" (text-field "room-id") (submit-button "Enter")]))
(defn render-room [NAME LOGS AUTHOR]
(page (str "Room " NAME)
(include-cljs)
[:h1 NAME " room"]
;; input part
[:form {:method "post" :action (str "/room/" (url-encode NAME))}
(text-field :author (or AUTHOR "Anonymous")) [:br]
(text-area {:rows 5 :cols 40} :body) [:br]
(submit-button {:id "submit-message"} "Submit")]
;; messages
[:div#messages {:data-message-room NAME}
(when LOGS
(map #(-> %
(update-in [1 :author] escape-html)
(update-in [1 :body] escape-html)
msg/render-message)
(rseq LOGS)))]
[:p
(link-to "/" "Back to main page")]))