Permalink
Browse files

* Implemented sessions to be usable, or actually compojure mojo

  • Loading branch information...
1 parent 9de1403 commit f772840fb31b158db1f2c7b15e39b7f76e50c53a clicki committed Mar 24, 2010
Showing with 33 additions and 3 deletions.
  1. +1 −0 data/examples/request.clj
  2. +24 −0 data/examples/session.clj
  3. +8 −3 src/clicki.clj
@@ -0,0 +1 @@
+(c.template/layout (:uri request) "Request" [:pre (pr request)])
@@ -0,0 +1,24 @@
+(let [uri (:uri request)]
+ (if (-> request :params :session-value)
+ [
+ {:session (assoc (:session request) :session-value (-> request :params :session-value))}
+ {:body (c.template/layout
+ uri
+ "Session Example"
+ [:p "Your last session was set to: " (-> request :session :session-value)]
+ [:p "Your session was set to: " (-> request :params :session-value)]
+ [:p
+ "Set your session value to "
+ [:a {:href (str uri "?session-value=42")} 42]
+ " or to "
+ [:a {:href (str uri "?session-value=42")} 23] "."])}
+ ]
+ (c.template/layout
+ uri
+ "Session Example"
+ [:p "Your session is set to: " (-> request :session :session-value)]
+ [:p
+ "Set your session value to "
+ [:a {:href (str uri "?session-value=42")} 42]
+ " or to "
+ [:a {:href (str uri "?session-value=42")} 23] "."])))
View
@@ -1,4 +1,5 @@
(ns clicki
+ (:use clojure.stacktrace)
(:use config)
(:use compojure)
(:use net.licenser.sandbox)
@@ -51,7 +52,9 @@
(loop [exp (read r false eof) res nil]
(if (not= exp eof)
(recur (read r false eof) ((sb exp 'request) {'*out* out} request))
- (str (if res (.append out res) out)))))))
+ (if (empty? (str out))
+ res
+ (str (if res (.append out res) out))))))))
(defn run-file
[ns file request]
@@ -60,6 +63,7 @@
(let [res (exec-file file ns request)]
res)
(catch Exception e
+ (print-stack-trace e)
(page e [:p [:a {:href (str (:uri request) "?edit=") } "edit"]])))))
(defn clicly-handler [request]
@@ -74,7 +78,7 @@
)
-(defroutes my-app
+(defroutes clicki
(GET "/"
(redirect-to "/index"))
(GET "*"
@@ -113,7 +117,8 @@
(catch Exception e false))
true (if (> c 0) (recur (dec c)))))))
+(decorate clicki (with-session :memory))
(defn -main []
(first-update)
(run-server {:port 8080}
- "/*" (servlet my-app)))
+ "/*" (servlet clicki)))

0 comments on commit f772840

Please sign in to comment.