Skip to content

Commit

Permalink
Merge pull request #19 from scicloj/options
Browse files Browse the repository at this point in the history
add options dynamic var
  • Loading branch information
daslu authored Sep 6, 2024
2 parents 1ddd459 + fcd765c commit b1a3a37
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 83 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## [4-beta7] - TBD
- added `*options*` as an alternative to passing options per form

## [4-beta6] - 2024-08-08
- fixed docstring for `:kind/image` (fixing #16)

Expand Down
29 changes: 16 additions & 13 deletions dev/scicloj/kindly/gen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@
(str (name k) ": " (escape v))))
"\"" \newline
" ([] " kind-kw ")" \newline
(if (:hide-code attrs)
(str
" ([value] (hide-code (attach-kind-to-value value " kind-kw "))) ")
(str
" ([value] (attach-kind-to-value value " kind-kw ")) "))
(str \newline
" ([value options] (" (symbol "scicloj.kindly.v4.kind" (name kind)) " (vary-meta value assoc :kindly/options options)))")
")" \newline)))

" ([value] (scicloj.kindly.v4.kind/" kind " value nil))" \newline
" ([value options] (kindly/attach-meta-to-value value {:kindly/kind " kind-kw " :kindly/options options})))"
\newline)))

(defn kind-fns [all-kinds]
(str/join (str \newline \newline)
Expand All @@ -50,7 +44,7 @@
(defn kind-ns [all-kinds]
(str "(ns scicloj.kindly.v4.kind
\"Kinds for visualization\"
(:require [scicloj.kindly.v4.api :refer [attach-kind-to-value hide-code]])
(:require [scicloj.kindly.v4.api :as kindly])
(:refer-clojure :exclude " (excludes all-kinds) "))
" (kind-fns all-kinds) \newline))
Expand All @@ -73,6 +67,16 @@
(str "(ns scicloj.kindly.v4.api
\"See the kind namespace\")
(def ^:dynamic *options*
\"Visualization tools take options in the following priority:
1. options on the metadata of a form or value
3. kind specific options found in the `:kinds` map of this dynamic var
2. options found in this dynamic var
See the kindly documentation for valid options.\"
nil)
(defn attach-meta-to-value
[value m]
(if (instance? clojure.lang.IObj value)
Expand All @@ -88,9 +92,8 @@
([value]
(hide-code value true))
([value bool]
(if (instance? clojure.lang.IObj value)
(vary-meta value assoc :kindly/hide-code true)
(hide-code [value]))))
;; Will change when Clay is updated
(attach-meta-to-value value {:kindly/hide-code bool})))
(defn consider
\"Add metadata to a given value.
Expand Down
15 changes: 12 additions & 3 deletions src/scicloj/kindly/v4/api.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
(ns scicloj.kindly.v4.api
"See the kind namespace")

(def ^:dynamic *options*
"Visualization tools take options in the following priority:
1. options on the metadata of a form or value
3. kind specific options found in the `:kinds` map of this dynamic var
2. options found in this dynamic var
See the kindly documentation for valid options."
nil)

(defn attach-meta-to-value
[value m]
(if (instance? clojure.lang.IObj value)
Expand All @@ -16,9 +26,8 @@
([value]
(hide-code value true))
([value bool]
(if (instance? clojure.lang.IObj value)
(vary-meta value assoc :kindly/hide-code true)
(hide-code [value]))))
;; Will change when Clay is updated
(attach-meta-to-value value {:kindly/hide-code bool})))

(defn consider
"Add metadata to a given value.
Expand Down
Loading

0 comments on commit b1a3a37

Please sign in to comment.