Skip to content

Commit

Permalink
Tweak sample doc and add it to snapshot build
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed Jan 20, 2022
1 parent e436442 commit 1359a4f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions notebooks/viewers_meta.clj → notebooks/viewer_api_meta.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; # Viewers Meta
;; # Metadata-Based Viewer API
^{:nextjournal.clerk/visibility :hide-ns}
(ns ^:nextjournal.clerk/no-cache viewers-meta
(:require [nextjournal.clerk :as clerk]))
Expand All @@ -8,15 +8,15 @@
(def tabular-data
(clerk/table {:col-1 ["a" "b" "c"] :col-2 ["a" "b" "c"]}))

;; This isn't always what you want as it performs a tranformation of your data.
;; This isn't always what you want as it performs a transformation of your data.
(keys tabular-data)

;; If this isn't what you want because you depend on it downstream, you can alternatively use metadata to convey the viewer.

;; You can alternatively use metadata on the form to convey the viewer.
^{::clerk/viewer clerk/table}
(def tabular-data-untouched
{:col-1 ["a" "b" "c"] :col-2 ["a" "b" "c"]})

;; And see that it remains untouched. This comes with the added benefit that changing a viewer does not require a recomputation.
(keys tabular-data-untouched)

;; This also works on literals, not just on vars. Though you will less care about transformation in that case – as you'll not be holding a reference to it. As you see in the following example, you can also use keywords instead of functions. This is useful when you don't want to require Clerk.
Expand Down
1 change: 1 addition & 0 deletions src/nextjournal/clerk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"rule_30"
"visibility"
"viewer_api"
"viewer_api_meta"
"viewers/html"
"viewers/image"
"viewers/markdown"
Expand Down
2 changes: 1 addition & 1 deletion src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
(:nextjournal/value x)
x))


#_(value (with-viewer :code '(+ 1 2 3)))
#_(value 123)

Expand All @@ -75,6 +74,7 @@
(when (map? x)
(:nextjournal/viewer x)))


#_(viewer (with-viewer :code '(+ 1 2 3)))
#_(viewer "123")

Expand Down

0 comments on commit 1359a4f

Please sign in to comment.