Skip to content

Instantly share code, notes, and snippets.

@danielcompton
Forked from mbertheau/non_idiomatic.cljs
Created September 24, 2015 09:45
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 danielcompton/9d0bdb562ebbca0fbcb2 to your computer and use it in GitHub Desktop.
Save danielcompton/9d0bdb562ebbca0fbcb2 to your computer and use it in GitHub Desktop.
(defn checkbox [short-name takes-place? word k]
^{:key (str k "takes-place")}
[:div.col.s2
[:input.filled-in {:type "checkbox"
:id (str "weekdays-" short-name)
:checked takes-place?}]
[:label.black-text {:for (str "weekdays-" short-name)
:style {:height "auto"
:line-height "normal"}}
word (when-not takes-place? (str " nicht" (when (= k :sun) ".")))]])
(defn takes-place [short-name times k]
^{:key (str key "times")}
[:div.col.s8
"um "
(when times
(apply concat
(for [[index time] (map-indexed vector times)]
(list
^{:key (str index "f")}
[:div {:id (str "weekdays-" short-name "-" index)
:value time
:style {:width "3rem" :height "auto" :text-align "center" :margin "0"}}]
^{:key (str index "t")}
[:span ", "]))
(list (list " und "))))
^{:key (count times)}
[:div {:id (count times)
:style {:width "3rem" :height "auto" :text-align "center" :margin "0"}}]
(if (= k :sun) "." ",")])
(defn not-takes-place [k]
^{:key (str k "not")} [:div.col.s8 " "])
(defn weekdays []
(let [weekdays-ratom {:mon {:takes-place? true :times ["9:00" "10:30"]}
:tue {:takes-place? false}
:wed {:takes-place? false}
:thu {:takes-place? false}
:fri {:takes-place? false}
:sat {:takes-place? false}
:sun {:takes-place? false}}
names {:mon {:intro "und zwar jeden" :word "Montag"}
:tue {:intro "und jeden" :word "Dienstag"}
:wed {:intro "und jeden" :word "Mittwoch"}
:thu {:intro "und jeden" :word "Donnerstag"}
:fri {:intro "und jeden" :word "Freitag"}
:sat {:intro "und jeden" :word "Samstag"}
:sun {:intro "sowie jeden" :word "Sonntag"}}]
[:div.row
(doall
(apply
concat
(for [[k {:keys [intro word]}] names
:let [short-name (name k)
{:keys [takes-place? times]} (get weekdays-ratom k)]]
[^{:key (str k "intro")}
[:div.col.s2.right-align intro]
(checkbox short-name takes-place? word k)
(if takes-place?
(takes-place short-name times k)
(not-takes-place k))])))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment