Skip to content

Commit adba8f7

Browse files
mfikesdnolen
authored andcommitted
CLJS-2558: Add logo to browser REPL default index.html
1 parent ec0e4c4 commit adba8f7

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:paths ["src/main/clojure" "src/main/cljs"]
1+
{:paths ["src/main/clojure" "src/main/cljs" "resources"]
22
:deps
33
{org.clojure/clojure {:mvn/version "1.9.0"}
44
org.clojure/tools.reader {:mvn/version "1.3.0-alpha3"}

resources/cljs-logo-icon-32.png

3 KB
Loading

resources/cljs-logo.svg

Lines changed: 18 additions & 0 deletions
Loading

src/main/clojure/cljs/repl/browser.clj

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
".jpg" "image/jpeg"
3636
".png" "image/png"
3737
".gif" "image/gif"
38+
".svg" "image/svg+xml"
3839

3940
".js" "text/javascript"
4041
".json" "application/json"
@@ -50,6 +51,7 @@
5051
"image/jpeg" "ISO-8859-1"
5152
"image/png" "ISO-8859-1"
5253
"image/gif" "ISO-8859-1"
54+
"image/svg+xml" "UTF-8"
5355
"text/javascript" "UTF-8"
5456
"text/x-clojure" "UTF-8"
5557
"application/json" "UTF-8"})
@@ -127,10 +129,35 @@
127129
(server/send-and-close conn 200 (slurp local-path) "text/plain"))
128130
;; "/index.html" doesn't exist, provide our own
129131
(= path "/index.html")
130-
(let [{:keys [output-to] :or {output-to "out/main.js"}} copts]
132+
(let [{:keys [output-dir output-to] :or {output-dir "out" output-to "out/main.js"}} copts]
133+
(let [maybe-copy-resource (fn [name] (let [f (io/file output-dir name)]
134+
(when-not (.exists f)
135+
(spit f (slurp (io/resource name))))))]
136+
(maybe-copy-resource "cljs-logo-icon-32.png")
137+
(maybe-copy-resource "cljs-logo.svg"))
131138
(server/send-and-close conn 200
132-
(str "<!DOCTYPE html><head><meta charset=\"UTF-8\"></head><body>"
133-
"<div id=\"app\"></div>"
139+
(str "<!DOCTYPE html><html><head><meta charset=\"UTF-8\">"
140+
"<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"" output-dir "/cljs-logo-icon-32.png\"/></head>"
141+
"<body><div id=\"app\">"
142+
"<p>Welcome to the default <code>index.html</code> provided by the ClojureScript Browser REPL.</p>"
143+
"<p>This page provides the evaluation environment for your Browser REPL and application.</p>"
144+
"<p>You can quickly validate the connection by typing <code>(js/alert&nbsp;\"Hello CLJS!\")</code> into the "
145+
"ClojureScript REPL that launched this page.</p><p>You can easily use your own HTML file to host your application "
146+
"and REPL by providing your own <code>index.html</code> in the directory that you launched this REPL from.</p>"
147+
"<p>Start with this template:</p>"
148+
"<pre>"
149+
"&lt;!DOCTYPE html&gt;\n"
150+
"&lt;html&gt;\n"
151+
" &lt;head&gt;\n"
152+
" &lt;meta charset=\"UTF-8\"&gt;\n"
153+
" &lt;/head&gt;\n"
154+
" &lt;body&gt;\n"
155+
" &lt;script src=\"" output-to "\" type=\"text/javascript\"&gt;&lt;/script&gt;\n"
156+
" &lt;/body&gt;\n"
157+
"&lt;/html&gt;\n"
158+
"</pre>"
159+
"<center><img src=\"" output-dir "/cljs-logo.svg\" style=\"width: 350px; height: 350px;\"/></center>"
160+
"</div></div>"
134161
"<script src=\"" output-to "\"></script>"
135162
"</body></html>")
136163
"text/html"

0 commit comments

Comments
 (0)