Created
September 18, 2011 19:09
-
-
Save hlship/1225419 to your computer and use it in GitHub Desktop.
More complicated (defrecord) example
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
(defrecord Element [name attributes content] | |
NodeStreaming | |
(stream [node strategy out] | |
(let [element-name (clojure.core/name name) | |
attr-quote (strategy :attribute-quote)] | |
(write out "<" element-name) | |
; Write out normal attributes | |
(doseq [[attr-name attr-value] attributes] | |
(if-not (nil? attr-value) | |
(write out | |
" " (clojure.core/name attr-name) "=" attr-quote (to-attr-string attr-value) attr-quote))) | |
(if (empty? content) | |
((strategy :write-empty-element-close) element-name out) | |
(do | |
(write out ">") | |
(stream-nodes content strategy out) | |
(write out "</" element-name ">")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment