Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for with-out-str using *print-fn* [cljs-321]

  • Loading branch information...
commit eab6032e6ba22571e5c4f821707bf5de8075e757 1 parent 3b32345
@ohpauleez ohpauleez authored David Nolen committed
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/clj/cljs/core.clj
View
11 src/clj/cljs/core.clj
@@ -1156,3 +1156,14 @@
(~'f)
~(gen-apply-to-helper))))
(set! ~'*unchecked-if* false)))
+
+(defmacro with-out-str
+ "Evaluates exprs in a context in which *print-fn* is bound to .append
+ on a fresh StringBuffer. Returns the string created by any nested
+ printing calls."
+ [& body]
+ `(let [sb# (goog.string/StringBuffer.)]
+ (binding [cljs.core/*print-fn* (fn [x#] (.append sb# x#))]
+ ~@body)
+ (cljs.core/str sb#)))
+
Please sign in to comment.
Something went wrong with that request. Please try again.