Skip to content

Commit

Permalink
Factor out render-str function.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed Oct 12, 2015
1 parent ce82416 commit f7e3f92
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/puget/printer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
(map->PugetPrinter)))


(defn render-to-out
(defn render-out
"Prints a value using the given printer."
[printer value]
(binding [*print-meta* false]
Expand All @@ -445,24 +445,29 @@
{:width (:width printer)})))


(defn render-str
"Renders a value to a string using the given printer."
[printer value]
(-> (render-out printer value)
(with-out-str)
(str/trim-newline)))


(defn pprint
"Pretty-prints a value to *out*. Options may be passed to override the
default *options* map."
([value]
(pprint value nil))
([value opts]
(render-to-out (->printer opts) value)))
(render-out (->printer opts) value)))


(defn pprint-str
"Pretty-print a value to a string."
([value]
(pprint-str value nil))
([value opts]
(-> value
(pprint opts)
with-out-str
str/trim-newline)))
(render-str (->printer opts) value)))


(defn cprint
Expand Down

0 comments on commit f7e3f92

Please sign in to comment.