Created
October 27, 2021 22:35
-
-
Save alysbrooks/dc7820201cc3d2450c8216ac0adaa78d to your computer and use it in GitHub Desktop.
Very simple hiccup implementation
This file contains hidden or 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
(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