Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Generate doc-examples string at compile time (#34)

  • Loading branch information...
khardenstine authored and moea committed Jan 19, 2018
1 parent 1155c7c commit 26fe43eb9de6d7cc7ad8a466953fa0ffe09889ca
Showing with 11 additions and 10 deletions.
  1. +11 −10 src/kvlt/util.cljc
@@ -56,16 +56,17 @@
(defn pprint-str [x]
(str/trimr (with-out-str (pprint/pprint x))))

(defn examples->str [examples]
(str "\n\n```clojure\n"
(str/join
"\n\n"
(for [[before after] examples]
(cond-> (pprint-str before)
after (str "\n =>\n" (pprint-str after)))))
"\n```"))

(defn doc-examples! [vvar examples]
(alter-meta!
vvar update :doc str
"\n\n```clojure\n"
(str/join
"\n\n"
(for [[before after] examples]
(cond-> (pprint-str before)
after (str "\n =>\n" (pprint-str after)))))
"\n```"))
(alter-meta! vvar update :doc str (examples->str examples)))

#? (:clj
(defmacro fn-when [[binding] & body]
@@ -75,4 +76,4 @@

#? (:clj
(defmacro with-doc-examples! [vvar & examples]
`(doc-examples! #'~vvar (quote ~examples))))
`(alter-meta! #'~vvar update :doc str ~(examples->str examples))))

0 comments on commit 26fe43e

Please sign in to comment.
You can’t perform that action at this time.