Created
August 30, 2010 19:13
-
-
Save bobo/557879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns SimpleTasks.core | |
(:use compojure.core | |
hiccup.core,hiccup.form-helpers | |
ring.adapter.jetty, ring.middleware.params, ring.middleware.session)) | |
(defn display [] | |
(html [:h1 "hello world!"])) | |
(defn render-form [] | |
(html | |
(form-to [:post "/form" ] | |
"Add task" | |
[:br] | |
(text-field :task) | |
(submit-button "save")))) | |
(defn handle-form [params] | |
{:body (str "stored" (params "task")) | |
:session {:tasks (params "task")}}) | |
(defn view [session] | |
(html [:h1 (str "tasks: " (:tasks session))])) | |
(defroutes myroutes | |
(GET "/" [] (display)) | |
(GET "/form" [] (render-form)) | |
(GET "/view" {session :session} (view session)) | |
(POST "/form" {params :params} (handle-form params))) | |
(wrap! myroutes :session) | |
(defonce server (run-jetty #'myroutes | |
{:join? false | |
:port 8080})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment