diff --git a/README.md b/README.md index 96d7e08..9a46d3c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Puget [![Build Status](https://travis-ci.org/greglook/puget.svg?branch=master)](https://travis-ci.org/greglook/puget) [![Coverage Status](https://coveralls.io/repos/greglook/puget/badge.png?branch=master)](https://coveralls.io/r/greglook/puget?branch=master) -[![Dependency Status](https://www.versioneye.com/user/projects/53718bfb14c1589a89000144/badge.png)](https://www.versioneye.com/user/projects/53718bfb14c1589a89000144) +[![Dependency Status](https://www.versioneye.com/user/projects/53718bfb14c1589a89000144/badge.png)](https://www.versioneye.com/clojure/mvxcvi:puget/0.5.1) Puget is a Clojure library for printing [EDN](https://github.com/edn-format/edn) values. Under the hood, Puget uses the @@ -74,7 +74,7 @@ To use this version with Leiningen, add the following dependency to your project definition: ```clojure -[mvxcvi/puget "0.5.0"] +[mvxcvi/puget "0.5.1"] ``` From the REPL, you can use the following helper functions for some control of diff --git a/project.clj b/project.clj index f531217..9510c37 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject mvxcvi/puget "0.5.0" +(defproject mvxcvi/puget "0.5.1" :description "Colorizing canonical Clojure printer for EDN values." :url "https://github.com/greglook/puget" :license {:name "Public Domain" diff --git a/src/puget/data.clj b/src/puget/data.clj index 65d9cf4..d7f4e35 100644 --- a/src/puget/data.clj +++ b/src/puget/data.clj @@ -121,18 +121,17 @@ (defmacro extend-tagged-value "Extends the TaggedValue protocol with implementations which return the - given symbol as the tag and use the body to calculate the value. The symbol - 'this' is bound to the data. This macro also defines a print-method which + given symbol as the tag and use the given expression to calculate the value. + The expression should resolve to a function which accepts one argument and + returns the serialized value. This macro also defines a print-method which delegates to edn-str." [t tag expr] - `(do + `(let [value-fn# ~expr] (extend-type ~t TaggedValue - (edn-tag [~'this] ~tag) - (edn-value [~'this] - ~(if (or (symbol? expr) (keyword? expr)) - (list expr 'this) - expr))) + (edn-tag [this#] ~tag) + (edn-value [this#] + (value-fn# this#))) (defprint-method ~t))) @@ -143,7 +142,8 @@ (defmacro extend-tagged-map [c tag] - `(extend-tagged-value ~c ~tag (into {} (seq ~'this)))) + `(extend-tagged-value ~c ~tag + (comp (partial into {}) seq))) @@ -169,7 +169,7 @@ ; #bin - Binary data in the form of byte arrays. (extend-tagged-value (class (byte-array 0)) 'bin - (->> this b64/encode (map char) (apply str))) + #(->> % b64/encode (map char) (apply str))) (defn read-bin