-
Notifications
You must be signed in to change notification settings - Fork 2
Utilities
The dictim.json
names provides two public functions to-json
and from-json
for converting dictim to json and back.
Under the covers, the Cheshire library is used.
The dictim.validate
namespace provides the functions valid?
and all-valid?
for validating dictim. The first for a single element, the second for a collection of multiple elements.
user> (in-ns 'dictim.validate)
#namespace[dictim.validate]
dictim.validate> (def elem
[:mike
"Old friends"
[:comment "a diagram of friends"]
[:t1
"T Boggs expanded"
[:tris "TAB"]
[:mads "Madeline"]
[:tris "--" :maddie "wedding bells?"]]])
#'dictim.validate/elem
dictim.validate> (valid? elem)
true
A meaningful error will be thrown if a particular element fails validation.
The dictim.format
namespace exposes one public function, fmt
which will clean up and re-format a d2 string.
user=> (use 'dictim.format)
nil
user=> (println d2-messy)
family1: The Jones' {
style: { fill: red;
}; personA: Henrick
personB: Michael
personA -- personB: brothers;}
nil
user=> (println (fmt d2-messy))
family1: The Jones' {
style: {
fill: red
}
personA: Henrick
personB: Michael
personA -- personB: brothers
}
nil
fmt
can take one keyword argument :tab
to set the number of spaces used for an indentation step. The default is 2.
The fmt
fuunction is invoked by default on d2 compiled from dicitm.
The dictim.template
namespace exposes some additional useful functions asides from its core functions add-styles
and remove-styles
(which are covered on the Template wiki page.
Similar to clojure.walk
the functions walk-dictim
, prewalk-dictim
and postwalk-dictim
allow you to traverse any dictim diagram spec.
Multimethods are accessing parts of a dictim element are used in the test functionality of add-styles
but could be useful elsewhere.
These are key
, keys
, label
, children
, element-type
and are available in the dictim.tests
namespace.