-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: src/compojure/route.clj test/compojure/test/route.clj
- Loading branch information
Showing
7 changed files
with
65 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
lib | ||
classes | ||
compojure.jar | ||
*.jar | ||
pom.xml | ||
_site |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
(defproject compojure "0.4.1" | ||
(defproject compojure "0.5.0-beta3" | ||
:description "A concise web framework for Clojure" | ||
:url "http://github/weavejester/compojure" | ||
:dependencies [[org.clojure/clojure "1.1.0"] | ||
[org.clojure/clojure-contrib "1.1.0"] | ||
[clout "0.2.0"] | ||
[ring/ring-core "0.2.5"]] | ||
:dev-dependencies [[lein-clojars "0.5.0"] | ||
:dependencies [[org.clojure/clojure "1.2.0"] | ||
[org.clojure/clojure-contrib "1.2.0"] | ||
[clout "0.3.0"] | ||
[ring/ring-core "0.3.0"]] | ||
:dev-dependencies [[lein-clojars "0.6.0"] | ||
[swank-clojure "1.2.1"] | ||
[ring/ring-jetty-adapter "0.2.5"]]) | ||
[ring/ring-jetty-adapter "0.3.0"]]) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
(ns compojure.response | ||
"Methods for generating Ring response maps" | ||
(:use [ring.util.response :only (response header)]) | ||
(:import java.util.Map | ||
[java.io File InputStream] | ||
[clojure.lang IDeref IFn ISeq])) | ||
|
||
(defmulti render | ||
"Given the request map and an arbitrary value x, turn x into a valid HTTP | ||
response map. Dispatches on the type of x." | ||
(fn [_ x] (type x))) | ||
|
||
(defmethod render nil [_ _] nil) | ||
|
||
(defmethod render String [_ html] | ||
{:status 200 | ||
:headers {"Content-Type" "text/html"} | ||
:body html}) | ||
|
||
(defmethod render Map [_ m] | ||
(merge {:status 200, :headers {}, :body ""} m)) | ||
|
||
(defmethod render IFn [request handler] | ||
(render request (handler request))) | ||
|
||
(defmethod render IDeref [request ref-like] | ||
(render request (deref ref-like))) | ||
|
||
(defmethod render File [_ file] | ||
{:status 200, :headers {}, :body file}) | ||
|
||
(defmethod render ISeq [_ coll] | ||
{:status 200, :headers {}, :body coll}) | ||
|
||
(defmethod render InputStream [_ stream] | ||
{:status 200, :headers {}, :body stream}) | ||
|
||
(prefer-method render Map IFn) | ||
(defprotocol Renderable | ||
(render [this request] | ||
"Render the object into a form suitable for the given request map.")) | ||
|
||
(extend-type nil | ||
Renderable | ||
(render [_ _] nil)) | ||
|
||
(extend-type String | ||
Renderable | ||
(render [this _] | ||
(-> (response this) | ||
(header "Content-Type" "text/html")))) | ||
|
||
(extend-type Map | ||
Renderable | ||
(render [this _] | ||
(merge (response "") this))) | ||
|
||
(extend-type IFn | ||
Renderable | ||
(render [this request] | ||
(render (this request) request))) | ||
|
||
(extend-type IDeref | ||
Renderable | ||
(render [this request] | ||
(render (deref this) request))) | ||
|
||
(extend-type File | ||
Renderable | ||
(render [this _] (response this))) | ||
|
||
(extend-type ISeq | ||
Renderable | ||
(render [this _] (response this))) | ||
|
||
(extend-type InputStream | ||
Renderable | ||
(render [this _] (response this))) |
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
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
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