Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2011 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1504221 to your computer and use it in GitHub Desktop.
Save anonymous/1504221 to your computer and use it in GitHub Desktop.
(ns mobybymobi.core
(:use noir.core)
(:require [noir.server :as server]))
(defpage "/welcome" []
"Welcome to Noir!")
(defpartial todo-item [{:keys [id title due]}]
[:li {:id id} ;;maps define html attributes
[:h3 title]
[:span.due due]]) ;;add a class
(defpartial todos-list [items]
[:ul#todoItems ;; set the id attribute
(map todo-item items)])
(todos-list [{:id "todo1"
:title "Get Milk"
:due "today"}])
(defpage "/todos" {}
(let [items (all-todos)]
(layout
[:h1 "Todo list!"]
(todos-list items))))
(defpage [:post "/todos"] {:keys [title due]}
(if-let [todo-id (add-todo title due)]
(response/json {:id todo-id
:title title
:due-date due-date})
(response/empty)))
(defpage "/todo/remove/:id" {todo-id :id}
(if (remove-todo todo-id)
(response/json {:id todo-id})
(response/empty)))
(defpage "/login" {}
(session/put! :admin true)
(layout
[:p "Are you logged in?"]
[:p (session/get :admin)]))
(defpage "/cookie" []
(cookie/put! :noir "stuff")
(let [v (cookie/get :noir)]
(layout
[:p "You created a cookie:"]
[:p "Value " v])))
(defpage "/validate" []
(vali/rule (= 3 3)
[:math "3 != 3"])
(vali/rule (= 1 2)
[:math "1 != 2"])
(layout
[:p "Let's check your math: "]
[:p (str (vali/get-errors :math))]))
(server/start 8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment