moved hickory framework to commons
This commit is contained in:
parent
ed90703b13
commit
2ac6afb3bb
2 changed files with 61 additions and 3 deletions
|
@ -6,7 +6,8 @@
|
||||||
"src/test/resources"]
|
"src/test/resources"]
|
||||||
:dependencies [[aero "1.1.6"]
|
:dependencies [[aero "1.1.6"]
|
||||||
[orchestra "2021.01.01-1"]
|
[orchestra "2021.01.01-1"]
|
||||||
[expound "0.8.9"]]
|
[expound "0.8.9"]
|
||||||
|
[hickory "0.7.1"]]
|
||||||
:builds {:test {:target :node-test
|
:builds {:test {:target :node-test
|
||||||
:output-to "target/node-tests.js"
|
:output-to "target/node-tests.js"
|
||||||
:autorun true
|
:autorun true
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
[clojure.string :as st]
|
[clojure.string :as st]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[expound.alpha :as expound]
|
[expound.alpha :as expound]
|
||||||
[orchestra.core :refer-macros [defn-spec]]))
|
[orchestra.core :refer-macros [defn-spec]]
|
||||||
|
[hickory.render :as hr]))
|
||||||
|
|
||||||
(defn-spec print-debug string?
|
(defn-spec print-debug string?
|
||||||
[sth string?]
|
[sth string?]
|
||||||
|
@ -65,3 +66,59 @@
|
||||||
(-> (get-element-by-id "form")
|
(-> (get-element-by-id "form")
|
||||||
(.-classList)
|
(.-classList)
|
||||||
(.add "was-validated")))
|
(.add "was-validated")))
|
||||||
|
|
||||||
|
(defn replace-element-content
|
||||||
|
[name
|
||||||
|
content]
|
||||||
|
(-> (get-element-by-id name)
|
||||||
|
(.-innerHTML)
|
||||||
|
(set! (hr/hickory-to-html content))))
|
||||||
|
|
||||||
|
(defn generate-feedback-tag
|
||||||
|
[id]
|
||||||
|
{:type :element :attrs {:class "invalid-feedback"} :tag :div :content [{:type :element :attrs {:id (str id "-validation")} :tag :pre :content nil}]})
|
||||||
|
|
||||||
|
(defn generate-label
|
||||||
|
[id-for
|
||||||
|
label]
|
||||||
|
{:type :element :attrs {:for id-for :class "form-label"} :tag :label :content [label]})
|
||||||
|
|
||||||
|
(defn generate-input-field
|
||||||
|
[id
|
||||||
|
label
|
||||||
|
default-value]
|
||||||
|
(str (generate-label id label)
|
||||||
|
{:type :element :attrs {:class "form-control" :type "text" :name id :value default-value} :tag :input :content nil}
|
||||||
|
(generate-feedback-tag id)))
|
||||||
|
|
||||||
|
(defn generate-text-area
|
||||||
|
[id
|
||||||
|
label
|
||||||
|
default-value
|
||||||
|
rows]
|
||||||
|
(str (generate-label id label)
|
||||||
|
{:type :element :attrs {:name id :id id :class "form-control" :rows rows} :tag :textarea :content [default-value]}
|
||||||
|
(generate-feedback-tag id)))
|
||||||
|
|
||||||
|
(defn generate-button
|
||||||
|
[id
|
||||||
|
label]
|
||||||
|
{:type :element
|
||||||
|
:attrs {:type "button", :id id, :class "btn btn-primary"}
|
||||||
|
:tag :button
|
||||||
|
:content [label]})
|
||||||
|
|
||||||
|
(defn generate-br
|
||||||
|
[]
|
||||||
|
{:type :element, :attrs nil, :tag :br, :content nil})
|
||||||
|
|
||||||
|
(defn generate-output
|
||||||
|
[id
|
||||||
|
label
|
||||||
|
rows]
|
||||||
|
{:type :element, :attrs {:id id}, :tag :div, :content [{:type :element, :attrs {:for "output", :class "form-label"}, :tag :label, :content [label]}
|
||||||
|
{:type :element, :attrs {:name "output", :id "output", :class "form-control", :rows rows}, :tag :textarea, :content []}]})
|
||||||
|
|
||||||
|
(defn generate-needs-validation
|
||||||
|
[]
|
||||||
|
{:type :element, :attrs {:class "needs-validation", :id "form"}, :tag :form, :content []})
|
Loading…
Reference in a new issue