This commit is contained in:
jem 2021-03-19 14:26:32 +01:00
parent 122a7ddee7
commit 7a6f31b96a

View file

@ -1,6 +1,7 @@
(ns dda.k8s-mastodon-bot.browser (ns dda.k8s-mastodon-bot.browser
(:require (:require
[clojure.string :as st] [clojure.string :as st]
[clojure.spec.alpha :as s]
[clojure.tools.reader.edn :as edn] [clojure.tools.reader.edn :as edn]
[expound.alpha :as expound] [expound.alpha :as expound]
[dda.k8s-mastodon-bot.core :as core])) [dda.k8s-mastodon-bot.core :as core]))
@ -40,13 +41,13 @@
(.-value) (.-value)
(set! input))) (set! input)))
(defn expound-config (defn validate-config! []
[config] (let [config (config-from-document)]
(st/replace (when-not (s/valid? ::core/config config)
(expound/expound-str ::core/config config {:print-specs? false}) (-> config
#"\n" "<br>")) (edn/read-string)
#(expound/expound-str ::core/config % {:print-specs? false})
(render-validation-result-to-config)))))
(defn render-validation-result-to-config (defn render-validation-result-to-config
[validation-result] [validation-result]
@ -62,14 +63,9 @@
(defn init [] (defn init []
(-> js/document (-> js/document
(.getElementById "generate-button") (.getElementById "generate-button")
(.addEventListener "click" (.addEventListener "click"
#(-> (core/generate (config-from-document) (auth-from-document)) #(-> (core/generate (config-from-document) (auth-from-document))
(set-output!)))) (set-output!))))
(-> (config) (-> (config)
(.addEventListener "blur" (.addEventListener "blur"
#(-> (config-from-document) #(validate-config!))))
(edn/read-string)
(expound-config)
(print-debug)
(render-validation-result-to-config))))
)