Skip to content

Commit

Permalink
Add a :print-fallback key to *options* to fall back on pr-str
Browse files Browse the repository at this point in the history
This commit adds a `:print-fallback` key (default false) to the
puget.printer/*options* map. Setting the value to true will cause Puget
to fall back on an object's `pr-str` value rather than printing its
class information.
  • Loading branch information
David Jarvis committed Feb 27, 2015
1 parent 7e523ae commit a1da466
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/puget/printer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
The text placed between a map key and a collection value. The keyword :line
will cause line breaks if the whole map does not fit on a single line.
`:print-fallback`
If true, falls back to to using pr-str rather than puget's default
unknown-document representation
`:print-meta`
If true, metadata will be printed before values. If nil, defaults to the
value of *print-meta*.
Expand All @@ -55,6 +59,7 @@
:strict false
:map-delimiter ","
:map-coll-separator " "
:print-fallback false
:print-meta nil
:print-color false
:color-markup :ansi
Expand Down Expand Up @@ -121,7 +126,7 @@


(defn- illegal-when-strict!
"Throws an exception if strict mode is enabled. The error indincates that the
"Throws an exception if strict mode is enabled. The error indicates that the
given value has no EDN representation."
[value]
(when (:strict *options*)
Expand Down Expand Up @@ -202,14 +207,17 @@
(unknown-document value (.getName (class value)) repr))
([value tag repr]
(illegal-when-strict! value)
[:span
(color-doc :class-delimiter "#<")
(color-doc :class-name tag)
(color-doc :class-delimiter "@")
(system-id value)
" "
repr
(color-doc :class-delimiter ">")]))
(if (:print-fallback *options*)
[:span
(pr-str value)]
[:span
(color-doc :class-delimiter "#<")
(color-doc :class-name tag)
(color-doc :class-delimiter "@")
(system-id value)
" "
repr
(color-doc :class-delimiter ">")])))



Expand Down

0 comments on commit a1da466

Please sign in to comment.