Skip to content

Commit 4900aae

Browse files
committed
Migrate to new visibility settings
1 parent b847826 commit 4900aae

File tree

10 files changed

+50
-46
lines changed

10 files changed

+50
-46
lines changed

index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
```clojure
2-
^{:nextjournal.clerk/visibility #{:hide :hide-ns}}
32
(ns index
3+
{:nextjournal.clerk/visibility {:code :hide}}
44
(:require [clojure.string :as str]
55
[nextjournal.clerk :as clerk]))
66
```

notebooks/controls.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;; # Controls! 🎛
2-
^{:nextjournal.clerk/visibility #{:hide-ns}}
2+
^{:nextjournal.clerk/visibility {:code :hide}}
33
(ns ^:nextjournal.clerk/no-cache controls
44
(:require [clojure.string :as str]
55
[nextjournal.clerk :as clerk]))

notebooks/data_science.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;; # A small data science example 🔢
2-
^{:nextjournal.clerk/visibility #{:hide-ns}}
2+
^{:nextjournal.clerk/visibility {:code :hide}}
33
(ns data-science
44
(:require [clojure.string :as str]
55
[clojure.set :refer [join rename-keys project]]

notebooks/dictionary.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
;; # 📔️ Regex Dictionary
2-
^{:nextjournal.clerk/visibility #{:hide-ns :hide}}
2+
^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
33
(ns dictionary
44
(:require [clojure.string :as str]
55
[clojure.java.io :as io]
66
[wordnet.core :as wordnet]
77
[nextjournal.clerk :as clerk]
88
[controls :refer [text-input]]))
99

10-
^{:nextjournal.clerk/viewer :hide-result}
1110
(def dict
1211
(try
1312
(wordnet/make-dictionary "datasets/dict")
1413
(catch Exception e
1514
(throw (ex-info "You must download the WordNet database from https://wordnet.princeton.edu/download/current-version and expand it into the datasets/dict directory to run this demo." {})))))
1615

17-
^{:nextjournal.clerk/viewer :hide-result}
1816
(def words
1917
(->> (if (.exists (io/file "/usr/share/dict/words"))
2018
"/usr/share/dict/words"
@@ -23,6 +21,8 @@
2321
str/split-lines
2422
(filter #(seq (dict %)))))
2523

24+
{::clerk/visibility {:result :show}}
25+
2626
(clerk/html [:div [:span {:class "font-bold"} "Type three or more letters of a regex!"]])
2727
^{:nextjournal.clerk/viewer text-input}
2828
(defonce text-state (atom ""))

notebooks/git.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
;; # 🕰️ GIT timeline for this project
2-
^{:nextjournal.clerk/visibility #{:hide-ns :hide}}
32
(ns timeline
3+
{:nextjournal.clerk/visibility {:code :hide :result :hide}}
44
(:require [nextjournal.clerk :as clerk]
55
[clj-jgit.porcelain :as cg]
66
[clj-jgit.querying :as cgq]
77
[clojure.set :as set]
88
[nextjournal.clerk.viewer :as v]))
99

10-
^{:nextjournal.clerk/viewer :hide-result}
1110
(def clerk-repo
1211
(cg/load-repo ".git"))
1312

14-
^{:nextjournal.clerk/viewer :hide-result}
1513
(def commits
1614
(->> (cg/git-log clerk-repo)
1715
(map (comp (partial cgq/commit-info clerk-repo) :id))
1816
reverse
1917
(into [])))
2018

19+
{:nextjournal.clerk/visibility {:result :show}}
20+
2121
(clerk/with-viewer
2222
{:transform-fn (comp v/mark-presented
2323
(v/update-val (partial map

notebooks/introduction.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;; # Hello, Clerk 👋
2-
^{:nextjournal.clerk/visibility #{:hide-ns}}
2+
^{:nextjournal.clerk/visibility {:code :hide}}
33
(ns introduction
44
(:require [nextjournal.clerk :as clerk]
55
[meta-csv.core :as csv])

notebooks/logo.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
;; # 🎨 Making a Clerk Logo
2-
^{:nextjournal.clerk/visibility #{:hide-ns}}
2+
^{:nextjournal.clerk/visibility {:code :fold}}
33
(ns logo
44
(:require [nextjournal.clerk :as clerk]
55
[clojure2d.core :as c2d]
66
[fastmath.complex :as complex]
77
[fastmath.vector :as v]))
88

9-
^{:nextjournal.clerk/visibility #{:hide}}
10-
(clerk/hide-result ; we need this because we don't want to open any windows
11-
(System/setProperty "java.awt.headless" "true"))
9+
^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
10+
(System/setProperty "java.awt.headless" "true")
1211

1312
;; The new Clerk header image is made from a fifth order [Hilbert
1413
;; Curve](https://en.wikipedia.org/wiki/Hilbert_curve), so we will

notebooks/osc_spirograph.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; driven controller running on your phone to interact with vector graphic animations in a Clerk notebook. OSC is generally employed in live multimedia
44
;; devices and sound synthesizers, but as [remarked a while ago by Joe Armstrong](https://joearms.github.io/published/2016-01-28-A-Badass-Way-To-Connect-Programs-Together.html)
55
;; its properties make it an interesting choice for exchanging data across machines in a broader range of applications._
6-
^{:nextjournal.clerk/visibility :hide-ns}
6+
^{:nextjournal.clerk/visibility {:code :fold}}
77
(ns osc-spirograph
88
(:require [nextjournal.clerk :as clerk]
99
[clojure.java.io :as io]
@@ -16,7 +16,7 @@
1616
(javax.imageio ImageIO)
1717
(java.util List ArrayList)))
1818

19-
^{::clerk/visibility :fold :nextjournal.clerk/viewer :hide-result}
19+
^{::clerk/visibility {:code :hide :result :hide}}
2020
(def client-model-sync
2121
;; This viewer is used to sync models between clojure values and those on the client side
2222
{:transform-fn (comp v/mark-presented (v/update-val (comp deref deref ::clerk/var-from-def)))
@@ -43,7 +43,7 @@
4343
;; $$\zeta(t) = \sum_{k=1}^3 \mathsf{amplitude}_k\,\large{e}^{2\pi\,\mathsf{frequency}_k \,i\, t}$$
4444
;;
4545

46-
^{::clerk/visibility :fold ::clerk/viewer :hide-result}
46+
^{::clerk/visibility {:code :fold :result :hide}}
4747
(def spirograph-viewer
4848
{:render-fn '(fn [_]
4949
(v/html
@@ -124,12 +124,12 @@
124124
(swap! model #(-> % (assoc :drawing drawing) build-phasors build-curve)))))]
125125
[:div {:ref refn :style {:width "100%" :height "800px"}}]))]))})
126126

127-
^{::clerk/width :full ::clerk/visibility :hide ::clerk/viewer spirograph-viewer}
127+
^{::clerk/width :full ::clerk/visibility {:code :hide} ::clerk/viewer spirograph-viewer}
128128
(Object.)
129129

130130
;; We'll be interacting with the spirograph by means of [TouchOSC](https://hexler.net/touchosc) an application for building OSC (or MIDI) driven interfaces runnable on smartphones and the like.
131131
;; Our controller is looking like this:
132-
^{::clerk/visibility :hide}
132+
^{::clerk/visibility {:code :hide}}
133133
(ImageIO/read (io/resource "spirograph.png"))
134134
;; the linear faders on the left will control the phasors amplitudes while the radial ones change their frequencies. This
135135
;; specific layout is saved in [this file](https://github.com/zampino/osc-spirograph/blob/main/spirograph.tosc).
@@ -192,7 +192,7 @@
192192
;; to which I refer the reader to further explore the implications of Fourier analysis with digital signal processing.
193193
;; My article should definitely expand to also contain some sound, probably using overtone. Suggestions anyone? [@lo_zampino](https://twitter.com/lo_zampino)
194194

195-
^{::clerk/visibility :hide ::clerk/viewer :hide-result}
195+
^{::clerk/visibility {:code :hide :result :hide}}
196196
(comment
197197
(clerk/serve! {:port 7777})
198198
(clerk/clear-cache!)

notebooks/slideshow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Simply require `clerk-slideshow`…
1818
…and add it to Clerk’s existing viewers:
1919

2020
```clojure
21-
^{::clerk/viewer clerk/hide-result}
21+
^{::clerk/visibility {:result :hide}}
2222
(clerk/add-viewers! [slideshow/viewer])
2323
```
2424

@@ -61,4 +61,4 @@ Now some demos 👉
6161

6262
## And that’s it for now! 👋
6363

64-
More demos will follow soon!
64+
More demos will follow soon!

notebooks/zipper_with_scars.clj

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
;; # Clojure Zippers with Scars à la Huet
22
;; _Building scars into clojure zipper library to go up and back down at the previous location._
3-
^{:nextjournal.clerk/visibility :hide-ns}
4-
(ns ^:nextjournal.clerk/no-cache zipper-with-scars
3+
(ns zipper-with-scars
4+
{:nextjournal.clerk/visibility {:code :fold}
5+
:nextjournal.clerk/no-cache true}
56
(:require [clojure.zip :as zip]
67
[arrowic.core :as a]
78
[nextjournal.clerk :as clerk]
@@ -21,7 +22,7 @@
2122
;; the [original zipper paper](http://gallium.inria.fr/~huet/PUBLIC/zip.pdf) has a memo-version of the up and down functions. Let's use Clerk viewers to illustrate how they work.
2223
;;
2324
;; Admittedly, the story with scars is just an excuse to test some animated zipper viewers in Clerk. To that end some machinery follows, unfold at your own peril.
24-
^{::clerk/visibility :fold ::clerk/viewer :hide-result}
25+
^{::clerk/visibility {:result :hide}}
2526
(do
2627
(defn loc-seq [zloc]
2728
;; this sorts nodes so that children seqs are displayed in the correct order by arrowic
@@ -55,12 +56,12 @@
5556
(defn ->svg [{:as g :keys [vertices edges]}]
5657
(a/as-svg
5758
(a/with-graph (a/create-graph)
58-
(let [vmap (zipmap vertices (map (partial insert-vtx g) vertices))]
59-
(doseq [[v1 v2] edges]
60-
(a/insert-edge! (vmap v1) (vmap v2)
61-
:end-arrow false :rounded true
62-
:stroke-width "3"
63-
:stroke-color "#7c3aed"))))))
59+
(let [vmap (zipmap vertices (map (partial insert-vtx g) vertices))]
60+
(doseq [[v1 v2] edges]
61+
(a/insert-edge! (vmap v1) (vmap v2)
62+
:end-arrow false :rounded true
63+
:stroke-width "3"
64+
:stroke-color "#7c3aed"))))))
6465

6566
(def zipper?
6667
(every-pred vector? (comp #{2} count) (comp map? first)
@@ -76,17 +77,17 @@
7677
:render-fn '(fn [frames]
7778
(v/html
7879
(reagent/with-let
79-
[!reel? (reagent/atom false) !idx (reagent/atom 0) !tmr (reagent/atom nil)
80-
stepfn #(swap! !idx inc)]
81-
(cond
82-
(and @!reel? (not @!tmr))
83-
(reset! !tmr (js/setInterval stepfn 500))
84-
(and (not @!reel?) @!tmr)
85-
(do (js/clearInterval @!tmr) (reset! !tmr nil) (reset! !idx 0)))
86-
[:div.flex.items-left
87-
[:div.flex.mr-5 {:style {:font-size "1.5rem"}}
88-
[:div.cursor-pointer {:on-click #(swap! !reel? not)} ({true "" false "▶️"} @!reel?)]]
89-
(v/inspect (frames (as-> (count frames) c (if @!reel? (mod @!idx c) (dec c)))))])))})
80+
[!reel? (reagent/atom false) !idx (reagent/atom 0) !tmr (reagent/atom nil)
81+
stepfn #(swap! !idx inc)]
82+
(cond
83+
(and @!reel? (not @!tmr))
84+
(reset! !tmr (js/setInterval stepfn 500))
85+
(and (not @!reel?) @!tmr)
86+
(do (js/clearInterval @!tmr) (reset! !tmr nil) (reset! !idx 0)))
87+
[:div.flex.items-left
88+
[:div.flex.mr-5 {:style {:font-size "1.5rem"}}
89+
[:div.cursor-pointer {:on-click #(swap! !reel? not)} ({true "" false "▶️"} @!reel?)]]
90+
(v/inspect (frames (as-> (count frames) c (if @!reel? (mod @!idx c) (dec c)))))])))})
9091

9192
(defn reset-reel [zloc] (vary-meta zloc assoc :frames [] :cut? false))
9293
(defn add-frame [zloc] (vary-meta zloc update :frames (fnil conj []) zloc))
@@ -95,10 +96,14 @@
9596
(list* '-> subj `reset-reel `add-frame
9697
(concat (interpose `add-frame ops) [`add-frame `cut])))
9798
(clerk/add-viewers! [zip-reel-viewer zip-location-viewer]))
98-
^{::clerk/viewer :hide-result}
99+
100+
{::clerk/visibility {:code :show :result :hide}}
101+
99102
(def ->zip (partial zip/zipper map? :content #(assoc %1 :content %2)))
100-
^{::clerk/viewer :hide-result}
103+
101104
(defn ->node [name] {:name name})
105+
106+
{::clerk/visibility {:result :show}}
102107
;; In code cells below, you may read `zmov->` as clojure's own threading macro:
103108
;; the resulting values are the same while metadata is being varied to contain intermediate "frames".
104109
(def tree
@@ -141,7 +146,7 @@
141146
Seqable
142147
(seq [_] (concat left (cons node right))))
143148
;; and we're plugging it in the original up and down function definitions:
144-
^{::clerk/visibility :hide ::clerk/viewer :hide-result}
149+
^{::clerk/visibility {:code :hide :result :hide}}
145150
(.addMethod ^clojure.lang.MultiFn print-method Scar (get-method print-method clojure.lang.ISeq))
146151

147152
(defn zip-up-memo [[node path :as loc]]
@@ -205,7 +210,7 @@
205210
zip/remove
206211
zip/remove)
207212

208-
^{::clerk/viewer :hide-result ::clerk/visibility :hide}
213+
^{::clerk/visibility {:result :hide}}
209214
(comment
210215
(clerk/clear-cache!)
211216
(macroexpand '(zmov-> tree zip/up zip/down))

0 commit comments

Comments
 (0)