Skip to content

Commit 7a4c533

Browse files
author
awb99
committed
cleanup, build with webly
1 parent 5dbdc1f commit 7a4c533

File tree

13 files changed

+107
-98
lines changed

13 files changed

+107
-98
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,9 @@
7676

7777
# demo
7878

79-
The demo uses the extension manager from goldly to add options to goldly.
80-
8179
```
8280
cd demo
83-
clj -X:demo:npm-install
84-
clj -X:demo:compile
81+
clj -X:npm-install
8582
clj -X:demo
8683
```
8784

demo/deps.edn

+14-22
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,23 @@
33
"target/webly"]
44

55
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
6-
org.pinkgorilla/goldly {:mvn/version "0.4.621"}
6+
org.pinkgorilla/webly {:mvn/version "0.7.702"} ; build tool
77
; goldly extensions:
8-
org.pinkgorilla/ui-tailwind {:mvn/version "0.0.5"} ; tailwind css classes
9-
org.pinkgorilla/ui-repl {:mvn/version "0.0.72"}
10-
org.pinkgorilla/ui-fonts {:mvn/version "0.0.3"} ; font awesome
11-
org.pinkgorilla/options {:local/root "../" :deps/manifest :deps}
12-
}
8+
org.pinkgorilla/ui-tailwind {:mvn/version "0.1.8"} ; tailwind css classes
9+
;org.pinkgorilla/ui-repl {:mvn/version "0.0.72"}
10+
;org.pinkgorilla/ui-fonts {:mvn/version "0.2.5"} ; font awesome
11+
org.pinkgorilla/options {:local/root "../" :deps/manifest :deps}}
1312

14-
:aliases {:demo
15-
{:exec-fn modular.system/start!
16-
:exec-args {:profile "jetty"
17-
:config ["webly/config.edn"
18-
"goldly/config.edn"
19-
"demo-config.edn"]
20-
:services "goldly/services.edn"}}
21-
22-
:npm-install
23-
{:exec-fn goldly.app.build/goldly-build
13+
:aliases {:npm-install
14+
{:exec-fn webly.app.app/webly-build
15+
:config {}
2416
:exec-args {:profile "npm-install"}}
25-
26-
:compile
27-
{:exec-fn goldly.app.build/goldly-build
28-
:exec-args {:profile "compile2"}}
29-
30-
}
17+
:demo
18+
{:exec-fn modular.system/start!
19+
:exec-args {;:profile "jetty"
20+
:profile "watch"
21+
:config {}
22+
:services "demo-services.edn"}}}
3123

3224
;
3325
}

demo/resources/demo-config.edn

-14
This file was deleted.

demo/resources/demo-services.edn

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{:modular (modular.system/modular-env)
2+
;:secrets #include "secrets.edn" ;; externalised and usually "mounted" as a docker/kubernetes secret
3+
:components
4+
{:config {:start (modular.config/load-config! (:config #ref [:modular]))}
5+
6+
:exts {:start (extension/discover)}
7+
8+
:webly {:start (webly.app.app/start-webly
9+
(clip/ref :exts)
10+
(deref (clip/ref :config))
11+
(:profile #ref [:modular]))
12+
:stop (webly.app.app/stop-webly this)}}}

demo/resources/ext/demo.edn

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
{:name "demo"
2-
:cljs-routes {"" demo.page.options/page-options
3-
"controls" demo.page.controls/page-controls
4-
"trateg" demo.page.trateg/page-trateg}
5-
:sci-cljs-ns [demo.page.options
6-
demo.page.controls
7-
demo.page.trateg]
8-
9-
10-
}
1+
{:name "demo-app"
2+
:lazy true
3+
:depends-on #{;:options
4+
}
5+
:cljs-namespace [demo.page.core
6+
demo.page.controls
7+
demo.page.quanta]
8+
:cljs-ns-bindings {'demo.page.core {'page demo.page.core/page}
9+
'demo.page.controls {'page demo.page.controls/page}
10+
'demo.page.quanta {'page demo.page.quanta/page}}
11+
:cljs-routes {"" demo.page.core/page
12+
"controls" demo.page.controls/page
13+
"quanta" demo.page.quanta/page}}

demo/src/demo/page/controls.cljs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(def state-pet (r/atom :cat))
1313
(def state-bool (r/atom true))
1414

15-
(defn page-controls [_]
15+
(defn page [_]
1616
[:div
1717
[:a {:href "/"}
1818
[:p "goto options"]]
@@ -21,10 +21,12 @@
2121
[:div " pet: " (pr-str @state-pet)
2222
" bool: " (pr-str @state-bool)]
2323

24+
[h1 "editor bool"]
2425
[edit/bool {:set-fn #(reset! state-bool %)
2526
:options {:class "bg-red-300 p-2"}}
2627
@state-bool]
2728

29+
[h1 "editor select"]
2830
[edit/select
2931
{:set-fn #(reset! state-pet %)
3032
:options {:class "placeholder-gray-400 text-gray-700 relative bg-white rounded text-sm border border-gray-400 outline-none focus:outline-none focus:shadow-outline"

demo/src/demo/page/options.cljs demo/src/demo/page/core.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns demo.page.options
1+
(ns demo.page.core
22
(:require
33
[reagent.core :as r]
44
[options.core :refer [options-ui]]))
@@ -78,11 +78,11 @@
7878
[:br]
7979
[:h1 {:class "pt-5 pb-5 text-xl text-bold text-blue-700"} s]])
8080

81-
(defn page-options [_]
81+
(defn page [_]
8282
[:div
8383

8484
[:a {:href "/controls"} [:p "goto controls"]]
85-
[:a {:href "/trateg"} [:p "goto trateg"]]
85+
[:a {:href "/quanta"} [:p "goto quanta"]]
8686

8787
[h1 "state"]
8888
[:div (pr-str @state)]
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
(ns demo.page.trateg
1+
(ns demo.page.quanta
22
(:require
33
[reagent.core :as r]
4-
[options.core :refer [options-ui]]))
4+
[options.core :refer [options-ui2]]))
55

6-
(def state (r/atom {}))
6+
(def state (r/atom {[0 :asset] "USD/JPY",
7+
[2 :trailing-n] 120,
8+
[2 :atr-n] 10,
9+
[2 :percentile] 70,
10+
[2 :step] 1.0E-4,
11+
[4 :max-open-close-over-low-high] 0.3}))
712

8-
(def config
9-
{:state state
10-
:options [{:type :select
13+
(def options [{:type :select
1114
:path [0 :asset],
1215
:name "asset",
1316
:spec
@@ -17,22 +20,15 @@
1720
{:type :select :path [2 :atr-n], :name "dATR#", :spec [5 10 20 30]}
1821
{:type :select :path [2 :percentile], :name "dPercentile", :spec [10 20 30 40 50 60 70 80 90]}
1922
{:type :select :path [2 :step], :name "dStep", :spec [0.001 1.0E-4 4.0E-5]}
20-
{:type :select :path [4 :max-open-close-over-low-high], :name "doji-co/lh max", :spec [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]}],
21-
:current
22-
{[0 :asset] "USD/JPY",
23-
[2 :trailing-n] 120,
24-
[2 :atr-n] 10,
25-
[2 :percentile] 70,
26-
[2 :step] 1.0E-4,
27-
[4 :max-open-close-over-low-high] 0.3}})
23+
{:type :select :path [4 :max-open-close-over-low-high], :name "doji-co/lh max", :spec [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]}])
2824

2925
(defn h1 [s]
3026
[:<>
3127
[:hr]
3228
[:br]
3329
[:h1 {:class "pt-5 pb-5 text-xl text-bold text-blue-700"} s]])
3430

35-
(defn page-trateg [_]
31+
(defn page [_]
3632
[:div
3733
[:a {:href "/controls"}
3834
[:p "goto controls"]]
@@ -41,7 +37,20 @@
4137
[:div (pr-str @state)]
4238

4339
[h1 "unstyled"]
44-
[options-ui {:class "bg-blue-300 options-debug"
45-
:style {:width "50vw"
40+
[options-ui2 {:class "bg-blue-300 options-debug"
41+
:style {:width "50vw"
4642
;:height "40vh"
47-
}} config]])
43+
}
44+
:edit options
45+
:state state
46+
} ]
47+
48+
[h1 "labels-left"]
49+
[options-ui2 {:class "bg-blue-300 options-label-left"
50+
:style {:width "50vw"
51+
;:height "40vh"
52+
}
53+
:edit options
54+
:state state}]
55+
56+
])

resources/ext/options.edn

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:cljs-namespace [options.core
55
options.edit]
66
:cljs-ns-bindings {'options.core {'options-ui options.core/options-ui
7+
'options-ui2 options.core/options-ui2
78
'register-editor options.core/register-editor}
89
'options.edit {'bool options.edit/bool
910
'button options.edit/button

src/options/core.cljs

+23-19
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,37 @@
2020
(defn register-editor [t f]
2121
(swap! editors assoc t f))
2222

23-
(defn get-editor [t]
23+
(defn get-editor [t]
2424
(or (get @editors t) editor-view))
2525

26-
27-
(defn get-value [state path]
28-
(when path
29-
(get @state path)))
30-
31-
(defn set-value [state path v]
32-
(when path
33-
(println "set-value path: " path " value: " v)
34-
(swap! state assoc path v)))
35-
36-
(defn create-edit-element [state {:keys [path name type] :as options}]
26+
(defn create-edit-element [{:keys [set-fn get-fn]} {:keys [path name type] :as options}]
3727
(let [editor (get-editor type)]
3828
[:<>
3929
[:span name] ; <label for= "pet-select" >Choose a pet:</label>
40-
[editor {:state state
41-
:set-fn #(set-value state path %)
30+
[editor {:set-fn (partial set-fn path)
4231
:options options}
43-
(get-value state path)]]))
32+
(get-fn path)]]))
33+
34+
(defn options-ui2 [{:keys [class style
35+
edit
36+
state
37+
set-fn
38+
get-fn]
39+
:or {set-fn (fn [path v]
40+
;(println "setting " path " to: " v)
41+
(swap! state assoc path v))
42+
get-fn (fn [path]
43+
(get @state path))}}]
44+
(into [:div {:style style
45+
:class class}]
46+
(map #(create-edit-element {:set-fn set-fn
47+
:get-fn get-fn} %) edit)))
4448

4549
(defn options-ui [{:keys [class style]} ; styling
4650
{:keys [current state options]
4751
:or {state (r/atom current)} :as config}] ; data
4852
(reset! state current)
49-
(fn [_styling {:keys [state options] :as config}]
50-
(into [:div {:style style
51-
:class class}]
52-
(map #(create-edit-element state %) options))))
53+
[options-ui2 {:class class
54+
:style style
55+
:state state
56+
:edit options}])

src/options/editor/bool.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
:checked current-val
88
:on-change (fn [e]
99
(let [v (-> e .-target .-checked)]
10-
(println "setting checkbox to: " v)
10+
;(println "setting checkbox to: " v)
1111
(set-fn v)))}]))

src/options/editor/select.cljs

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,25 @@
3333
[:option {:value id} name]))
3434

3535
(defn get-id [spec id]
36-
(println "get-id: " id " in spec: " spec)
36+
;(println "get-id: " id " in spec: " spec)
3737
(-> (filter #(= id (:id %)) spec)
3838
first))
3939

4040
(defn editor-select [{:keys [set-fn options]} current-val]
4141
(let [{:keys [class spec]
4242
:or {class ""
4343
spec []}} options
44-
mapped? (map? (first spec))
45-
spec (if mapped?
44+
spec? (map? (first spec))
45+
spec (if spec?
4646
(spec->spec spec)
47-
(vals->spec spec))]
47+
(vals->spec spec))
48+
current-val (if spec?
49+
current-val
50+
(str current-val))]
4851
(into [:select {:class class
4952
:on-change (fn [e]
5053
(let [id-str (-> e .-target .-value)
51-
entry (get-id spec id-str)
54+
entry (get-id spec id-str)
5255
v (:val entry)]
5356
;(println "entry: " entry)
5457
;(println "setting select to id: " id-str "val: " v)

src/options/editor/string.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
:placeholder name
99
:on-change (fn [e]
1010
(let [v (-> e .-target .-value)]
11-
(println "setting checkbox to: " v)
11+
;(println "setting string to: " v)
1212
(set-fn v)))}]))

0 commit comments

Comments
 (0)