This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-08
Channels
- # adventofcode (49)
- # babashka (21)
- # babashka-sci-dev (12)
- # beginners (250)
- # calva (23)
- # cider (6)
- # clj-kondo (11)
- # cljsrn (8)
- # clojure (129)
- # clojure-europe (50)
- # clojure-france (8)
- # clojure-italy (6)
- # clojure-nl (14)
- # clojure-romania (7)
- # clojure-spec (21)
- # clojure-uk (3)
- # clojurescript (17)
- # conjure (1)
- # core-async (40)
- # core-logic (24)
- # core-typed (7)
- # datavis (2)
- # datomic (2)
- # emacs (29)
- # fulcro (10)
- # graalvm (6)
- # graphql (24)
- # gratitude (6)
- # jobs (1)
- # lsp (9)
- # malli (6)
- # missionary (1)
- # nextjournal (46)
- # off-topic (2)
- # other-languages (3)
- # pathom (5)
- # portal (2)
- # re-frame (37)
- # remote-jobs (1)
- # shadow-cljs (15)
- # spacemacs (9)
- # testing (6)
- # tools-deps (13)
- # vim (32)
- # xtdb (16)
we’d like to cut a Clerk release, would appreciate it if folks could take io.github.nextjournal/clerk {:git/sha "aa6ed09880316d15b0d3c76ae50505d1978e4008"}
for a spin and let me know if there’s anything we missed. Preliminary changelog is at https://github.com/nextjournal/clerk/blob/main/CHANGELOG.md#unreleased
@carsten.behring @daslu I believe both of you asked for being able to let Clerk serve arbitrary things. In the latest main
a viewer can provide a fetch-fn
to enable this by returning a map with :nextjournal/content-type
and :nextjournal/value
keys, see https://github.com/nextjournal/clerk/blob/main/notebooks/viewers/image.clj for an example. This will also inline the blob for the static builds. Curious to hear if that serves your needs.
Thanks. Looking at the example seems to say, that it satisfies the "general need", of being able to load / generate byte arrays in image format and show them on the web. This would allow Clerk , for example, to render plots where the plotting library can only generate "desktop" graphics, typically PNGs.
I was a bit wondering, if there is a limitation that I need to set a global viewer for any type of "bytes" (= same viewer for all byte arrays).
Is there documentation which function a pred? can be ?
so what exactly gets passed to the function specified in :pred?
The "evaluation result" ?
I just looked at teh code, and relaized how
clerk/set-viewers!
clerk/with-viewer
clerk/with-viewers
So I have ultimate control on the "active viewers"
That's fine.
So pred?: true
would works as well, if i am inside a
with-viewer
block.
That was my doubt.I will try it a bit.
it is supposed to work with with-viewers
?
This fails:
(clerk/with-viewers [{:pred bytes?
:fetch-fn (fn [_ bytes] {:nextjournal/content-type "image/png"}
:nextjournal/value bytes)
:render-fn (fn [blob] (v/html [:img {:src (v/url-for blob)}]))}]
(.. (HttpClient/newHttpClient)
(send (.build (HttpRequest/newBuilder (URI. "")))
(HttpResponse$BodyHandlers/ofByteArray)) body))
without pred?
with-viewers
works
The issue went away. The image supports is working, thanks @U5H74UNSF
@carsten.behring good to hear. Btw you should also be able to register the predicate on the file and use a :transform-fn
to convert it to bytes
;; # 🏞 Customizing Fetch
;; Showing how to use a custom `fetch-fn` with a `content-type` to let Clerk serve arbitrary things, in this case a PNG image.
(ns ^:nextjournal.clerk/no-cache image
(:require [ :as io]
[nextjournal.clerk :as clerk])
(:import (java.nio.file Files)))
;; We set a custom viewer for `java.io.File` that includes a `:fetch-fn`, returning a wrapped value with a `:nextjournal/content-type` key set.
(clerk/set-viewers! [{:pred #(instance? File %)
:fetch-fn (fn [_ file] {:nextjournal/content-type "image/png"
:nextjournal/value (Files/readAllBytes (.toPath file))})
:render-fn (fn [blob] (v/html [:img {:src (v/url-for blob)}]))}])
(io/file "/Users/mk/Downloads/James_Clerk_Maxwell.png")
this is just for pngs but could check the extension or sniff the content type to extend this
Maybe something for the docu: Avoid a namespace like:
(ns wordclouds
(:require [nextjournal.clerk :as clerk]))
(clerk/show! "notebooks/wordclouds.clj")
fixed https://github.com/nextjournal/clerk/commit/0544915014cbb448acf51d111a069a9b0bec44ac
endless loop ... while evaluating last line
I was looking at the visibility control in the new version of Clerk. Nice !
This allows now precise control what to hide and what to show.
Nevertheless I found myself quite a lot of times using clerk/hide-result
It is maybe possible to use the hide-result
as metadata and have an option to hide results for the whole ns and switch it on for a few forms only ?
A good use case for this is "documentation of Clojure libraries", where maybe a lot of code / results is hidden.
I see 4 use cases:
1. I know I do a data science notebook for me, so I want to see all code and all results
2. I know I want to do docu, so I want to show some (most code, most results)
3. I do a data science notebook , and a static rendering I want to hide all code (for my manager) (= override the visibility settings)
4. I want to do a specially nice output. So I need to be sure to be able to disable all ugly output/code
The fact that Clerk renders as well "one lines" on def / nil
makes this control more important
So the same as for "hide and "fold"
To get this result:
I need to use "hide-result" a lot
This is maybe not for the typical data science notebook use case, I agree.
I changed a bit the code and it seemed to work very nice.
I made a PR to replace the hide-result
fn with meta data :hide-result :show-result
https://github.com/nextjournal/clerk/pull/24
An other idea for a feature: Allow "copy" from a code cell with one keypress. And eventually as well for whole rendered namespace.
No the code,
just a simple button, which copies the code from a code cell, without need to "mark" by mouse