Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a :print-fallback key to *options* to fall back on pr-str #18

Merged
merged 3 commits into from
Feb 27, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update these per the keyword selection below. For simple pr-str behavior, I think the keyword could be :print to indicate it's using the normal print-method implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had assumed we'd literally pass the print function, e.g. your *options* would include something like:

:print-fallback pr-str

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though a curated keyword selection might indeed be better from a usability perspective.


`: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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, nice catch.

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*)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just a boolean switch here, I think it'd be better to make :print-fallback a keyword, with the default being the existing unknown document behavior. This could then be a case statement instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot. I'll update my PR.

[: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