Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cst.server: serve-* take head and body options

  • Loading branch information...
commit abcebce97035bcb75dc40bc2699e4fd20460b463 1 parent 69930c8
@jedahu authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 cst/src/cst/server.clj
View
26 cst/src/cst/server.clj
@@ -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
@@ -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
@@ -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*))
Please sign in to comment.
Something went wrong with that request. Please try again.