Improved docs, adding Codox dep

This commit is contained in:
James Reeves 2012-02-12 15:27:07 +00:00
parent 34e2639edb
commit aa6fcdf91b
3 changed files with 16 additions and 5 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ pom.xml
/classes/ /classes/
.lein-failures .lein-failures
.lein-deps-sum .lein-deps-sum
doc

View file

@ -3,4 +3,5 @@
:dependencies [[org.clojure/clojure "1.2.1"] :dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/core.incubator "0.1.0"] [org.clojure/core.incubator "0.1.0"]
[ring "1.0.1"]] [ring "1.0.1"]]
:dev-dependencies [[clj-http "0.3.1"]]) :dev-dependencies [[clj-http "0.3.1"]
[codox "0.4.0"]])

View file

@ -16,14 +16,14 @@
(try-port port run-server) (try-port port run-server)
(throw ex)))))) (throw ex))))))
(defn- server-port (defn server-port
"Get the port the server is listening on." "Get the port the server is listening on."
[server] [server]
(-> (.getConnectors server) (-> (.getConnectors server)
(first) (first)
(.getPort))) (.getPort)))
(defn- server-host (defn server-host
"Get the host the server is bound to." "Get the host the server is bound to."
[server] [server]
(-> (.getConnectors server) (-> (.getConnectors server)
@ -35,7 +35,7 @@
(browse-url (browse-url
(str "http://" (server-host server) ":" (server-port server)))) (str "http://" (server-host server) ":" (server-port server))))
(defmacro ^:private in-thread (defmacro ^{:private true} in-thread
"Execute the body in a new thread and return the Thread object." "Execute the body in a new thread and return the Thread object."
[& body] [& body]
`(doto (Thread. (fn [] ~@body)) `(doto (Thread. (fn [] ~@body))
@ -54,7 +54,16 @@
(middleware options))) (middleware options)))
(defn serve (defn serve
"Start a web server to run a handler." "Start a web server to run a handler. Takes the following options:
:port - the port to run the server on
:join? - if true, wait for the server to stop
:init - a function to run before the server starts
:destroy - a function to run after the server stops
:open-browser? - if true, open a web browser after the server starts
:middleware - a list of middleware functions to apply to the handler
If join? is false, a Server object is returned."
{:arglists '([handler] [handler options])}
[handler & [{:keys [init destroy join?] :as options}]] [handler & [{:keys [init destroy join?] :as options}]]
(let [options (assoc options :join? false) (let [options (assoc options :join? false)
destroy (if destroy (memoize destroy)) destroy (if destroy (memoize destroy))