-
-
Save kindlychung/97bf9b74daf0230ea4f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns-unmap *ns* 'fill) | |
(defn- fill-dispatch [node value] | |
(if-let [type (and (= :input (:tag node)) | |
(-> node :attrs :type))] | |
[(keyword (str "input." type)) (class value)] | |
[(:tag node) (class value)])) | |
(def fill-hierarchy | |
(-> (make-hierarchy) | |
(derive :input.radio ::checkable) | |
(derive :input.checkbox ::checkable))) | |
(defmulti fill | |
#'fill-dispatch | |
:default nil | |
:hierarchy #'fill-hierarchy) | |
(defmethod fill nil | |
[node value] | |
(if (= :input (:tag node)) | |
(do | |
(alter-var-root #'fill-hierarchy | |
derive | |
(first (fill-dispatch node value)) | |
:input) | |
(fill node value)) | |
(assoc node :content [(str value)]))) | |
(defmethod fill | |
[:input Object] [node value] | |
(assoc-in node [:attrs :value] (str value))) | |
(defmethod fill [::checkable clojure.lang.IPersistentSet] | |
[node value] | |
(if (contains? value (-> node :attrs :value)) | |
(assoc-in node [:attrs :checked] "checked") | |
(update-in node [:attrs] dissoc :checked))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment