Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update

  • Loading branch information...
commit 99d17e5363cd90234cc7e22ea44e09a1e7d2952d 1 parent 9f54475
@heow authored
View
2  README.md
@@ -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]:
View
2  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"]
View
8 src/example0.clj
@@ -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]
@@ -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")))}) )
View
4 src/example2.clj
@@ -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"))
View
7 src/example3.clj
@@ -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]
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.