Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created August 2, 2014 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/57a96a7761745d024fe7 to your computer and use it in GitHub Desktop.
Save alandipert/57a96a7761745d024fe7 to your computer and use it in GitHub Desktop.
Hatfield-McCoy selector wizard
(page "index.html")
(def people (cell {"Hatfield"
#{{:first "William" :gender :male}
{:first "Victoria" :gender :female}
{:first "Henry" :gender :male}
{:first "Elliott" :gender :male}
{:first "Elizabeth" :gender :female}}
"McCoy"
#{{:first "Randolph" :gender :male}
{:first "Mary" :gender :female}
{:first "Frank" :gender :male}
{:first "Roseanna" :gender :female}
{:first "Josephine" :gender :female}}}))
(def families (cell= (sort (keys people))))
(html
(head
(link :rel "stylesheet" :type "text/css" :href "css/main.css"))
(body
(h1 "Hatfield-McCoy Selector Wizard v1.0")
(let [family (cell nil)
gender (cell nil)
person (cell nil)]
(div
(div
(h3 "Select a Family")
(select :change #(reset! family (if (= @% "none") nil @%))
(option :value "none")
(loop-tpl :bindings [f families]
(option :value f f))))
(div :toggle family
(h3 "Select a Gender")
(select :change #(reset! gender (if (= @% "none") nil (keyword @%)))
(option :value "none")
(option :value "female" "female")
(option :value "male" "male")))
(div :toggle (cell= (and family gender))
(h3 (text "Select a ~{gender} ~{family}"))
(select :change #(reset! person {:first @% :last @family :gender @gender})
(loop-tpl :bindings [p (cell= (->> family
(get people)
(filter #(= gender (:gender %)))))]
(cell-let [first (:first p)] (option :value first first)))))
(div :toggle person
(p (text "You selected ~{(pr-str person)}!")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment