From fc24c547b62c91691d2ac431e8f9e84ab1e46a17 Mon Sep 17 00:00:00 2001 From: Daniel Skarda Date: Fri, 30 May 2014 11:37:23 +0200 Subject: [PATCH 1/3] New repl-env options: inject-html and inject-scripts --- src/clj/cemerick/austin.clj | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/clj/cemerick/austin.clj b/src/clj/cemerick/austin.clj index c32e0db..9cef544 100644 --- a/src/clj/cemerick/austin.clj +++ b/src/clj/cemerick/austin.clj @@ -147,6 +147,12 @@ function." (format ";console.error('Austin ClojureScript REPL session %s does not exist. Maybe you have a stale ClojureScript REPL environment in `cemerick.austin.repls/browser-repl-env`?');" session-id))) +(defn- repl-client-code [session-id] + (-> (get @sessions session-id) :client-code)) + +(defn- include-js [url] + (format "" url)) + (defn- send-repl-client-page [^HttpExchange ex session-id] (let [url (format "http://%s/%s/repl" @@ -160,6 +166,7 @@ function." "" + (repl-client-code session-id) "")))) (defn- send-repl-index @@ -175,6 +182,7 @@ function." "" + (repl-client-code session-id) "")))) (defn- send-static @@ -375,6 +383,8 @@ function." preloaded-libs: List of namespaces that should not be sent from the REPL server to the browser. This may be required if the browser is already loading code and reloading it would cause a problem. + inject-html: Additional HTML code to be included in REPL page (default \"\") + inject-scripts List of additional javascript files to be loaded from repl page. optimizations: The level of optimization to use when compiling the client end of the REPL. Defaults to :simple. host: The host URL on which austin will run the clojurescript repl. @@ -392,6 +402,8 @@ function." :serve-static true :static-dir ["." "out/"] :preloaded-libs [] + :inject-html "" + :inject-scripts [] :src "src/" :host "localhost" :source-map true @@ -414,7 +426,9 @@ function." :loaded-libs preloaded-libs :client-js (future (create-client-js-file opts - (io/file (:working-dir opts) "client.js"))))) + (io/file (:working-dir opts) "client.js"))) + :client-code (str (apply str (map include-js (:inject-scripts opts))) + (:inject-html opts)))) (println (str "Browser-REPL ready @ " (:entry-url opts))) opts))) From 0e3dd045bb1b379ea758fe0c7781b43a076a8a67 Mon Sep 17 00:00:00 2001 From: Daniel Skarda Date: Fri, 30 May 2014 12:21:19 +0200 Subject: [PATCH 2/3] Fix: do not include injects in client page --- src/clj/cemerick/austin.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clj/cemerick/austin.clj b/src/clj/cemerick/austin.clj index 9cef544..717b5ad 100644 --- a/src/clj/cemerick/austin.clj +++ b/src/clj/cemerick/austin.clj @@ -166,8 +166,7 @@ function." "" - (repl-client-code session-id) - "")))) + "")))) (defn- send-repl-index [ex session-id] From b26c9f857915a4b74722e4a297348835a3bd48a5 Mon Sep 17 00:00:00 2001 From: Daniel Skarda Date: Tue, 10 Jun 2014 17:16:13 +0200 Subject: [PATCH 3/3] Extend send-static to serve resources --- src/clj/cemerick/austin.clj | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/clj/cemerick/austin.clj b/src/clj/cemerick/austin.clj index 717b5ad..be851cd 100644 --- a/src/clj/cemerick/austin.clj +++ b/src/clj/cemerick/austin.clj @@ -184,6 +184,18 @@ function." (repl-client-code session-id) "")))) +(defn- file-or-resource + [path] + (cond + (.exists (io/file path)) + path + + (re-find #"^\./" path) + (io/resource (subs path 2)) + + :else + (io/resource path))) + (defn- send-static [ex session-id path] (let [opts (get @sessions session-id) @@ -192,8 +204,9 @@ function." (not= "/favicon.ico" path)) (let [path (if (= "/" path) "/index.html" path)] (if-let [local-path (seq (for [x (if (string? st-dir) [st-dir] st-dir) - :when (.exists (io/file (str x path)))] - (str x path)))] + :let [found (file-or-resource (str x path))] + :when found] + found))] (send-response ex 200 (slurp (first local-path)) :content-type (condp #(.endsWith %2 %1) path ".html" "text/html"