Skip to content

Commit c7c6f24

Browse files
committed
introduce minimal deps-based project example
1 parent 700d9e5 commit c7c6f24

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

examples/deps/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
public/js
3+
.cpcache

examples/deps/cljsc_opts.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:preloads [devtools.preload]
2+
:output-dir "public/js"
3+
:asset-path "js"}

examples/deps/demo.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
clj --main cljs.main --compile-opts cljsc_opts.edn --compile app.core
6+
7+
python -m http.server 3300 --directory public

examples/deps/deps.edn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:paths ["src"]
2+
:deps {org.clojure/clojure {:mvn/version "RELEASE"}
3+
org.clojure/clojurescript {:mvn/version "RELEASE"}
4+
binaryage/devtools {:mvn/version "RELEASE"}}}

examples/deps/public/favicon.ico

1.74 KB
Binary file not shown.

examples/deps/public/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="icon" type="image/x-icon" href="favicon.ico">
7+
<title>devtools-example</title>
8+
<script src="js/main.js" type="text/javascript"></script>
9+
</head>
10+
<body>
11+
<pre>
12+
1. Please open Chrome DevTools (CMD+OPT+I / CTRL+SHIFT+I)
13+
2. Enable custom formatters in DevTools -> Settings -> Console -> Enable custom formatters
14+
3. Refresh the page and see output in the DevTools Console
15+
</pre>
16+
<script>app.core.main()</script>
17+
</body>
18+
</html>

examples/deps/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This is bare bone clojurescript project using [deps.edn](https://clojure.org/guides/deps_and_cli) and [cljs.main](https://clojurescript.org/reference/repl-and-main)
2+
roughly modelled after [https://clojurescript.org/guides/quick-start](https://clojurescript.org/guides/quick-start).
3+
4+
To test this project:
5+
6+
1. `./demo.sh`
7+
2. open Chrome with [http://localhost:3300](http://localhost:3300)
8+
3. follow on-page instructions

examples/deps/src/app/core.cljs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(ns app.core
2+
(:require [clojure.string :as string]
3+
[devtools.formatters.markup :refer [<standard-body>]]
4+
[devtools.formatters.templating :refer [render-markup]]
5+
[devtools.protocols :refer [IFormat]]))
6+
7+
(defn hello [name]
8+
(str "hello, " name "!"))
9+
10+
(def showcase-value {:number 0
11+
:string "string"
12+
:keyword :keyword
13+
:symbol 'symbol
14+
:vector [0 1 2 3 4 5 6]
15+
:set '#{a b c}
16+
:map '{k1 v1 k2 v2}})
17+
18+
(defprotocol MyProtocol
19+
(-method1 [this])
20+
(-method2
21+
[this param1]
22+
[this param1 param2]))
23+
24+
(deftype MyType [f1 f2]
25+
MyProtocol
26+
(-method1 [this])
27+
(-method2 [this param1])
28+
(-method2 [this param1 param2]))
29+
30+
; custom formatter defined in user code
31+
(deftype Person [name address]
32+
IFormat
33+
(-header [_] (render-markup [["span" "color:white;background-color:#999;padding:0px 4px;"] (str "Person: " name)]))
34+
(-has-body [_] (some? address))
35+
(-body [_] (render-markup (<standard-body> (string/split-lines address)))))
36+
37+
(defn demo-devtools! []
38+
(js/console.log nil 42 0.1 :keyword 'symbol "string" #"regexp" [1 2 3] {:k1 1 :k2 2} #{1 2 3}) ; simple values
39+
(js/console.log [nil 42 0.1 :keyword 'symbol "string" #"regexp" [1 2 3] {:k1 1 :k2 2} #{1 2 3}]) ; vector of simple values
40+
(js/console.log (range 100) (range 101) (range 220) (interleave (repeat :even) (repeat :odd))) ; lists, including infinite ones
41+
(js/console.log {:k1 'v1 :k2 'v2 :k3 'v3 :k4 'v4 :k5 'v5 :k6 'v6 :k7 'v7 :k8 'v8 :k9 'v9}) ; maps
42+
(js/console.log #{1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}) ; sets
43+
(js/console.log hello filter js/document.getElementById) ; functions cljs / native
44+
(js/console.log (fn []) (fn [p__gen p123]) #(str %) (js* "function(x) { console.log(x); }")) ; lambda functions
45+
(js/console.log [#js {:key "val"} #js [1 2 3] (js-obj "k1" "v1" "k2" :v2) js/window]) ; js interop
46+
(js/console.log [1 2 3 [10 20 30 [100 200 300 [1000 2000 3000 :*]]]]) ; nested vectors
47+
(js/console.log (with-meta ["has meta data"] {:some "meta-data"})) ; values with metadata
48+
(js/console.log (Person. "John Doe" "Office 33\n27 Colmore Row\nBirmingham\nEngland") (Person. "Mr Homeless" nil)) ; custom formatting
49+
(js/console.log (atom showcase-value)) ; atoms
50+
(js/console.log (MyType. 1 2)))
51+
52+
(defn ^:export main []
53+
(demo-devtools!))

0 commit comments

Comments
 (0)