Skip to content

Commit

Permalink
cst.server: serve-* take head and body options
Browse files Browse the repository at this point in the history
  • Loading branch information
jedahu committed Apr 24, 2012
1 parent 69930c8 commit abcebce
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cst/src/cst/server.clj
Expand Up @@ -8,17 +8,19 @@
[java.io File]))

(defn test-body
[{:keys [output-dir output-to]}]
[{:keys [output-dir output-to]} {:keys [head body]}]
(let [base (str output-dir "/goog/base.js")
multiple? (.exists (File. base))]
(str "<html><head><meta charset='UTF-8'/></head><body>"
(str "<html><head><meta charset='UTF-8'/>" head
(when multiple? (str "<script src='/" base "'></script>"))
"</head><body>" body
"<script src='/" output-to "'></script>"
(when multiple? "<script>goog.require('cst.build.test.ns');</script>")
"</body></html>")))

(defn- serve-cljs-
[{:keys [cst] :as proj-opts} & {:keys [test-uri handler body] :or {test-uri "/"}}]
[{:keys [cst] :as proj-opts} &
{:keys [test-uri handler html-fn] :or {test-uri "/"} :as opts}]
(vprintln 1 " running jetty")
(vprintln 1 (str " test url: http://localhost:" (:http cst) test-uri))
(run-jetty
Expand All @@ -28,7 +30,7 @@
(= test-uri (:uri req))
{:status 200
:headers {"Content-Type" "text/html"}
:body (or body (test-body (:build cst)))}
:body ((or html-fn test-body) (:build cst) opts)}

(.exists (File. (str "." (:uri req))))
{:status 200
Expand All @@ -47,22 +49,24 @@
(defn serve-cljs*
[project & opts]
(binding [*verbosity* (or (-> project :cst :verbosity) 0)]
(apply serve-cljs- project opts)))
(apply serve-cljs- project opts)))

(def serve-cljs (memoize serve-cljs*))

(defn repl-body
[repl-dir]
(str "<html><head><meta charset='UTF-8'/></head>"
"<body><script src='/" repl-dir "/goog/base.js'></script>"
"<script src='/" repl-dir "/main.js'></script>"
"<script>goog.require('cst.repl.browser.ns');</script></body></html>"))
[{:keys [repl-dir]} {:keys [head body]}]
(str "<html><head><meta charset='UTF-8'/>" head
"<script src='/" repl-dir "/goog/base.js'></script>"
"<script src='/" repl-dir "/main.js'></script></head><body>"
body
"<script>goog.require('cst.repl.browser.ns');</script>"
"</body></html>"))

(defn serve-brepl*
[proj-opts & opts]
(apply serve-cljs*
proj-opts
:body (repl-body (:repl-dir (:cst proj-opts)))
:body (repl-body (:cst proj-opts))
opts))

(def serve-brepl (memoize serve-brepl*))

0 comments on commit abcebce

Please sign in to comment.