Skip to content

Use interesting generated data for your devcards. Review them with a range of data. Also works for pure functions (via edn renderer).

License

Notifications You must be signed in to change notification settings

olivergeorge/devcards-vs-clojure-spec

Repository files navigation

devcards-vs-clojure-spec

Tools to automatically generate useful devcards from view specs.

  • If you spec your views then we can generate data. Yay.
  • The generated data isn't interesting. Boo!
  • This library provides "interesting generators", think lorem-ipsum. Yay!
  • Devcards would only show one example, Boo!
  • This library includes a wrapper to make the devcard generators interactive. Yay!
  • Specifying a devcard for every function is haaard! Boo!
  • This library (will) include a helper to generate devcards for all spec fns in a namespace. Yay!
  • [insert next pain point]... [boo]
  • [contribute new feature]... [yay]

Status

First code pushed. Very little input or testing. Treat as alpha.

Prior art / related links

Usage

(ns example.my-table
  (:require-macros
    [devcards.core :refer [defcard]])
  (:require
    [cljs.spec :as s]
    [devcards-vs-clojure-spec.core :as core]
    [devcards-vs-clojure-spec.generators :as gen]
    [sablono.core :as sab]))

(defn my-table
  ([rows]
   (my-table (distinct (mapcat keys rows)) rows))
  ([ks rows]
   [:table.table
    [:thead [:tr (for [k ks]
                   [:th (name k)])]]
    [:tbody (for [row rows]
              [:tr (for [k ks]
                     [:td (get row k "-")])])]]))

(s/def ::col-key keyword?)
(s/def ::cell-val string?)

(s/fdef my-table
  :args (s/cat :keys (s/? (s/coll-of ::col-key))
               :rows (s/coll-of (s/map-of ::col-key ::cell-val))))

(core/add-override ::col-key #(s/gen #{:A :B :C}))
(core/add-override ::cell-val (gen/build-lorem-ipsum-generator 0 16))

(defcard my-table-with-controls
  (core/controls (core/sampler #'my-table)))

About

Use interesting generated data for your devcards. Review them with a range of data. Also works for pure functions (via edn renderer).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published