/
notespace_demo.clj
164 lines (108 loc) · 3.97 KB
/
notespace_demo.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
(ns practicalli.notespace-demo
(:require [notespace.api :as notespace]
[notespace.kinds :as kind]))
;; Notespace
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Listen for changes in the namespace and update notespace automatically
;; Hidden kinds should not show in the notespace page
^kind/hidden
(comment
;; Manually start an empty notespace - autostarted when using Clojure CLI
;; re-evaluate to start
(notespace/init-with-browser)
(notespace/init)
;; Notespace listens to file changes
(notespace/listen)
)
;; Notespace examples
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Full details at:
;; https://scicloj.github.io/notespace/doc/notespace/v3-experiment1-test/index.html
;; Simple Content
["## Notes are the pieces of a notespace
A note is a top level form in the Clojure namespace"]
["Notespace renders each top level form and shows both the code of that form and the evaluation result"]
["There are many kinds of notes available, including static **markdown** content like these *introductory paragraphs*. Code evaluation and results can be added as their own note or evaluated as part of hiccup style code. Visualizations such as graphs and plots can be rendered using the [Vega graphics language](https://vega.github.io/vega/docs/specification/)"]
;; simple values
;; Plain HTML content - no code rendering
;; use keywords for html tags, scoped to the vector
^kind/hiccup-nocode
[:h2 "Simple values"]
;; A value evaluates to itself, not very useful
[34388]
^kind/hiccup-nocode
[:h2 "Evaluating expressions"]
["Top level forms will render showing code and a pretty printed result to make nested results easier to read for humans"]
(+ 1 2 3 4 5 6)
;; Top level forms can be explicitly tagged as naive
^kind/naive
(->> (partial rand-int 6)
(partial repeatedly 6)
(repeatedly 6))
^kind/hiccup-nocode
[:h2 "Defining and calling functions"]
;; Define a function and call it to see the results
(defn pie-me
""
[number]
(* number 3.14))
(pie-me 12)
^kind/hiccup-nocode
[:h2 "Generative code"]
;; Render Clojure code writen in the hiccup style
^kind/hiccup
[:div
(->> (range 1 4)
(map (fn [i] [:h1 i]))
(into [:div]))]
(defn weather-forcast-mock
"Generate mock weati"
[temperature-min temperature-max]
(zipmap [:monday :tuesday :wednesday :thursday :friday :saturday :sunday]
(repeatedly #(rand-nth (range temperature-min temperature-max)))))
(weather-forcast-mock 20 30)
^kind/hidden
;; Send evaluation result to the connected data inspector, portal.
(tap>
(weather-forcast-mock 20 30))
^kind/hiccup-nocode
[:h2 "Hidden evaluation"]
;; Show the code but not the result
^kind/void
[:h1 "Hide my evaluation result. Am I even evaluated?"]
^kind/hiccup-nocode
[:p "Weather forcast"]
;; Visualizations
^kind/hidden
(comment
;; Notespace helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These function must be kept in a comment block
;; or they will disrupt the evaluation of the notespace
(notespace/init)
(notespace/init-with-browser)
;; Update the notespace with current namespace
(notespace/eval-this-notespace)
;; Update the notespace with current line
(notespace/eval-and-realize-note-at-line 26)
;; Generate static web page from current namespace
(notespace/render-static-html "index.html")
;; Listen for changes in the namespace and update notespace automatically
(notespace/listen)
(notespace/check)
;; Portal helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Require portal library when using Leiningen
(require '[portal.api :as inspect])
;; Open Portal window with solarized-dark theme
(inspect/open {:portal.colors/theme :portal.colors/solarized-light})
;; Clear the Portal window
(inspect/clear)
;; Close the Portal window
(inspect/close)
;; Inspect values with Portal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(tap>
(zipmap [:monday :tuesday :wednesday :thursday :friday :saturday :sunday]
(range 10 20)))
) ;; End of rich comment block