morning @tsulej, taking a look at your issue right now
Hi there! Thanks! I found something more regarding custom types (playing with that now). Will post details in the thread.
I'll start with the following, which works properly.
(deftype MyType [a b])
(MyType. 1 2)
;; => #object[sometest.MyType 0x57c6a598 "sometest.MyType@57c6a598"]Then, l add toString:
(deftype MyType [a b]
Object
(toString [_] (str "#MyType " [a b])))
(MyType. 1 2)
;; => #object[sometest.MyType 0x1987e9b3 "#MyType [1 2]"]
Now it's rendered with nippy error (also ignoring toString:
Now I add two more interfaces:
(deftype MyType [a b]
Object
(toString [_] (str "#MyType " [a b]))
clojure.lang.Sequential
clojure.lang.Seqable
(seq [_] (seq [a b])))
(MyType. 1 2)
;; => #object[sometest.MyType 0x6fd2252 "#MyType [1 2]"]Now, generating html causes the exception:
1. Unhandled java.lang.AbstractMethodError
Receiver class sometest.MyType does not define or inherit an
implementation of the resolved method 'abstract clojure.lang.ISeq
seq()' of interface clojure.lang.Seqable.
RT.java: 543 clojure.lang.RT/seqFrom
RT.java: 537 clojure.lang.RT/seq
core.clj: 139 clojure.core/seq
core.clj: 7392 clojure.core/bounded-count
core.clj: 7386 clojure.core/bounded-count
viewer.cljc: 320 nextjournal.clerk.viewer$bounded_count_opts$fn__18923/invoke
viewer.cljc: 320 nextjournal.clerk.viewer$bounded_count_opts/invokeStatic
viewer.cljc: 317 nextjournal.clerk.viewer$bounded_count_opts/invoke
viewer.cljc: 418 nextjournal.clerk.viewer$describe/invokeStatic
viewer.cljc: 366 nextjournal.clerk.viewer$describe/invoke
viewer.cljc: 372 nextjournal.clerk.viewer$describe/invokeStatic
viewer.cljc: 366 nextjournal.clerk.viewer$describe/invoke
view.clj: 110 nextjournal.clerk.view/->result
view.clj: 109 nextjournal.clerk.view/->result
view.clj: 164 nextjournal.clerk.view/describe-block
view.clj: 151 nextjournal.clerk.view/describe-block
core.clj: 2635 clojure.core/partial/fn
core.clj: 2746 clojure.core/map/fn/fn
PersistentVector.java: 343 clojure.lang.PersistentVector/reduce
core.clj: 6885 clojure.core/transduce
core.clj: 6901 clojure.core/into
core.clj: 6889 clojure.core/into
view.clj: 171 nextjournal.clerk.view/doc->viewer/fn
core.clj: 6185 clojure.core/update
core.clj: 6177 clojure.core/update
view.clj: 171 nextjournal.clerk.view/doc->viewer
view.clj: 167 nextjournal.clerk.view/doc->viewer
clerk.clj: 274 nextjournal.clerk/file->viewer
clerk.clj: 271 nextjournal.clerk/file->viewer
clerk.clj: 273 nextjournal.clerk/file->viewer
clerk.clj: 271 nextjournal.clerk/file->viewer
core.clj: 2598 clojure.core/juxt/fn
core.clj: 2746 clojure.core/map/fn/fn
PersistentVector.java: 343 clojure.lang.PersistentVector/reduce
core.clj: 6885 clojure.core/transduce
core.clj: 6901 clojure.core/into
core.clj: 6889 clojure.core/into
clerk.clj: 380 nextjournal.clerk/build-static-app!
clerk.clj: 366 nextjournal.clerk/build-static-app!
REPL: 15 sometest/eval25870I belive it's something with state / caching
When I copied above code to the different namespace I've got the same error. When I changed MyType to MyType2 the result is almost ok (ignoring toString though):
adding another interface causes an error again (for example clojure.lang.Counted (count [_] 2)
pushed a fix for the first issue https://github.com/nextjournal/clerk/commit/a30123a231a4b13e7caed66e12b4d29bdd92d772 now looking at the second one…
I can generate a static app fine
can you try to add the ^:nextjournal.clerk/no-cache tag to see if that fixes it?
ok, yeah, I can reproduce
no-cache seems to work
I think the issue is that we’re not yet handling deftype wrt caching
can you make an issue with your code?
yes, sure!
thank you!
thank you!
@mkvlr how to locally install Clerk snapshot from the source code (I use lein in current project I wanted to test for #64)?
oh, not sure how this works with lein and git deps these days…
I tried to run clj -X:build but have no access to cas repo
(in-ns 'nextjournal.clerk.viewer)
(defn- var-from-def? [x]
(and (map? x) (get x :nextjournal.clerk/var-from-def)))maybe easiest to try this in the repl
Ok, tried that and no changes (looks like this functions is not called)
genuary.2022.day26> (in-ns 'nextjournal.clerk.viewer)
#namespace[nextjournal.clerk.viewer]
nextjournal.clerk.viewer> (defn- var-from-def? [x] (println "aaa")
(and (map? x) (get x :nextjournal.clerk/var-from-def)))
#'nextjournal.clerk.viewer/var-from-def?
nextjournal.clerk.viewer> (clerk/build-static-app! {:out-path "docs" :paths ["src/genuary/2022/day26.clj"]})
#error {
:cause class clojure.lang.Keyword cannot be cast to class java.lang.Character (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Character is in module java.base of loader 'bootstrap')
:via
[{:type java.lang.ClassCastException
:message class clojure.lang.Keyword cannot be cast to class java.lang.Character (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Character is in module java.base of loader 'bootstrap')
:at [clojure.lang.RT uncheckedIntCast RT.java 1476]}]
:tracenextjournal.clerk.viewer> (var-from-def? 123)
aaa
falseah right, it is being called but there’s more you need to reload
not as easy as I thought from the repl
but I tried the fix and am pretty confident it’s working…
ok, I'll switch to deps then
it works, I use it in other projects
so yes, I need to switch to that, thanks
it's working! thanks a lot 😄
great! Thanks for the report
we were actually talking about this piece of code and we wondering if it’s safe to call get yesterday 😼
A couple of minor observations when using build-static-app! (version 0.5.346)...
• Using :bundle? false nicely generates the individual .html files but with incorrect hyperlinks between them. Is there a sort of root URL parameter that I ought to have set? (Using :bundle? true generated correct intra-page hyperlinks.) Or perhaps the :bundle? false setting isn’t quite public yet.
• It opens my web browser at http://localhost:7778/build but nothing is being served from there.
Thanks.
you can pass a :path-prefix param (with a trailing, not leading slash), e.g. build/
and for the links to work, you need a http server
(for the :bundle? false option that is)
or how do you think the links are wrong?
Thanks @mkvlr…
:path-prefix "public/build/" is what I needed to get my hyperlinks to work (when using :bundle? false). Although (very minor) build-static-app! still tries to open my web browser at
when is what works.
I don’t think you want public in your links or do you actually want to serve it from your.domain/public/build?
…as you say, I don’t want public in my URLs but, I was struggling to get to the right value for a :path-prefix. This is what now works for me in my deps.edn:
:aliases {:web-pages
;; To use this alias...
;; (1) run a webserver, e.g.
;; python3 -m http.server 7778 --directory public
;; (2) and run this alias, e.g.
;; clj -X:web-pages
;; (3) once Clerk has finished generating the HTML files
;; it will open a web browser at the 'index' URL for those HTML files:
;;
{:extra-paths ["datasets"]
:exec-fn nextjournal.clerk/build-static-app!
:exec-args {:bundle? false
:path-prefix "build/"
:paths ["index.md"
"notebooks/scotgov_datasets.clj"
"notebooks/wikidata_label_first_querying_for_scotgov_agencies.clj"]}}}
Thanks for the pointers 😃yeah, in this case I expect only a map, this is a data structure internal to Clerk so I don’t think being defensive hurts here
as we’ve seen it can cause problems in real-world code 😼
I noticed that enums in tables get rendered as objects: I this wanted behaviour ?
I think this is just the normal Clojure printing, so yes.