Skip to content

Instantly share code, notes, and snippets.

@alysbrooks
Created October 27, 2021 22:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alysbrooks/dc7820201cc3d2450c8216ac0adaa78d to your computer and use it in GitHub Desktop.
Save alysbrooks/dc7820201cc3d2450c8216ac0adaa78d to your computer and use it in GitHub Desktop.
Very simple hiccup implementation
(fn gen-attributes [attributes]
(clj.reduce (fn [x y] (.. x y))
(icollect [attr val (pairs attributes)]
(string.format " %s=\"%s\"" attr val))))
;
(fn render [form]
(if (clj.string? form) (EscapeHtml form)
(clj.vector? form) (let [tag (. form 1)
attributes (when (clj.map? (. form 2) ) (. form 2))
contents (if (clj.map? (. form 2))
(-> form
clj.rest
clj.rest)
(clj.rest form))
rendered-contents (clj.reduce (fn [x y] (.. x y))
(clj.mapv render contents))]
(string.format "<%s %s>%s</%s>" tag
(if attributes (gen-attributes attributes) "")
rendered-contents
tag))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment