Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heow Goodman committed Nov 8, 2011
1 parent 9f54475 commit 99d17e5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -114,7 +114,7 @@ Keyword params changes the input parameters from string-based to keyword based.
{"name" "Hello world"} ; params without keyword-params
{:name "Hello world"} ; params with keyword-params

#### destructuring syntax ####
#### destructuring syntax ####

The routes have a [startling new syntax][9]:

Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,5 +1,5 @@
(defproject compojure-cookies-example "1.0.0-SNAPSHOT"
:main example0
:main example3
:description "Idiomatic usage of Compojure using sessionless cookies."
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
Expand Down
8 changes: 4 additions & 4 deletions src/example0.clj
Expand Up @@ -8,7 +8,7 @@
(defn main-page [cookies]
(str "Hi there "
(if (empty? (:value (cookies "name")))
"<form method='post' action='/'> What's your name? <input type='text' name='name' class='name' maxlength='10' /><input type='submit' name='submit' value='ok' /></form>"
"<form method='post' action='/'> What's your name? <input type='text' name='name' /><input type='submit' /></form>"
(:value (cookies "name")))))

(defn process-form [params cookies]
Expand All @@ -27,6 +27,6 @@
(def app (-> #'routes wrap-cookies wrap-keyword-params wrap-params))

(defn -main []
(run-jetty routes {:port (if (nil? (System/getenv "PORT"))
8000 ; localhost or heroku?
(Integer/parseInt (System/getenv "PORT")))}) )
(run-jetty app {:port (if (nil? (System/getenv "PORT"))
8000 ; localhost or heroku?
(Integer/parseInt (System/getenv "PORT")))}) )
4 changes: 2 additions & 2 deletions src/example2.clj
Expand Up @@ -5,9 +5,9 @@

(defroutes routes
(POST "/" [name] (str "Thanks " name))
(GET "/" [] "<form method='post' action='/'> What's your name? <input type='text' name='name' class='name' maxlength='10' /><input type='submit' name='submit' value='ok' /></form>"))
(GET "/" [] "<form method='post' action='/'> What's your name? <input type='text' name='name' /><input type='submit' /></form>"))

(def app (-> #'routes wrap-params))
(def app (wrap-params routes))

(defn -main []
(run-jetty app {:port (if (nil? (System/getenv "PORT"))
Expand Down
7 changes: 3 additions & 4 deletions src/example3.clj
Expand Up @@ -5,11 +5,10 @@
[ring.middleware.params :only [wrap-params]]
[ring.middleware.keyword-params :only [wrap-keyword-params]]))

(defn main-page [cookies uri]
(println "URI: " uri)
(defn main-page [cookies]
(str "Hi there "
(if (empty? (:value (cookies "name")))
"<form method='post' action='/'> What's your name? <input type='text' name='name' class='name' maxlength='10' /><input type='submit' name='submit' value='ok' /></form>"
"<form method='post' action='/'> What's your name? <input type='text' name='name' /><input type='submit' /></form>"
(:value (cookies "name")))))

(defn process-form [params cookies]
Expand All @@ -23,7 +22,7 @@

(defroutes routes
(POST "/" {params :params cookies :cookies} (process-form params cookies))
(GET "/" {cookies :cookies uri :headers} (main-page cookies uri)))
(GET "/" {cookies :cookies} (main-page cookies)))

(def app (-> #'routes wrap-cookies wrap-keyword-params wrap-params))

Expand Down

0 comments on commit 99d17e5

Please sign in to comment.