grub-fork/src-clj/grub/core.clj

68 lines
1.8 KiB
Clojure
Raw Normal View History

2013-07-24 17:39:02 +00:00
(ns grub.core
2013-07-24 18:38:14 +00:00
(:use [org.httpkit.server
:only [run-server with-channel on-receive send! websocket?]]
[compojure.handler :only [site]]
[compojure.core :only [defroutes GET POST]])
2013-07-24 17:39:02 +00:00
(:require [ring.middleware.reload :as reload]
2013-07-24 18:38:14 +00:00
[compojure.route :as route]
[hiccup
[page :refer [html5]]
2013-07-24 19:43:26 +00:00
[page :refer [include-js include-css]]]))
2013-07-24 18:38:14 +00:00
2013-07-24 17:39:02 +00:00
2013-07-24 18:38:14 +00:00
(defn async-handler [request]
(if-not (:websocket? request)
{:status 200 :body "WebSocket server"}
(with-channel request channel
(on-receive channel (fn [data]
(send! channel data)))
(send! channel {:status 200
:headers {"Content-Type" "text/plain"}
:body "Long polling?"}))))
2013-07-24 19:50:29 +00:00
(def test-grubs
["8 dl water"
"8 whole peppercorns"
"2 bay leaves"
"1 - 2 (150 g) onions"
"750 g potato"
"600 g salmon"
"1 t. salt"
"2 dl cream"
"1 dl dill"])
2013-07-24 18:38:14 +00:00
(defn index-page []
(html5
2013-07-24 19:43:26 +00:00
[:head
[:title "Grub"]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}]
(include-css "/css/bootstrap.css")
(include-css "/css/bootstrap-responsive.css")]
2013-07-24 18:38:14 +00:00
[:body
2013-07-24 19:43:26 +00:00
[:div.container
[:div.row-fluid
[:div.span8.offset2
2013-07-24 19:50:29 +00:00
[:h2 "Grub"]
[:table.table
[:tbody
(for [grub test-grubs]
[:tr [:td [:label.checkbox [:input {:type :checkbox} grub]]]])]]]]]
2013-07-24 19:43:26 +00:00
(include-js "http://code.jquery.com/jquery.js")
(include-js "/js/bootstrap.js")
(include-js "/js/main.js")]))
2013-07-24 18:38:14 +00:00
(defroutes routes
(GET "/ws" [] async-handler)
(GET "/" [] (index-page))
(route/files "/")
(route/not-found "<p>Page not found.</p>"))
2013-07-24 17:39:02 +00:00
2013-07-24 18:38:14 +00:00
(def app
(let [dev? true]
(if dev?
(reload/wrap-reload (site #'routes))
(site routes))))
2013-07-24 17:39:02 +00:00
2013-07-24 18:38:14 +00:00
(defn -main [& args]
(run-server app {:port 8080}))