Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/scicloj/clay/v2/api.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(ns scicloj.clay.v2.api
(:require
[clojure.string :as string]
[clojure.test]
[scicloj.clay.v2.config :as config]
[scicloj.clay.v2.files :as files]
[scicloj.clay.v2.live-reload :as live-reload]
[scicloj.clay.v2.server :as server]
[scicloj.clay.v2.make :as make]
[scicloj.kindly.v4.api :as kindly]
[scicloj.kindly.v4.kind :as kind]))

(defn stop! []
Expand Down
15 changes: 15 additions & 0 deletions src/scicloj/clay/v2/files.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
(:require [clojure.java.io :as io]
[babashka.fs :as fs]))

;; will be bound when the notebook is being evaluated
(def ^:dynamic *context* nil)

(def *target-path->files (atom {}))

(defn init-target! [target-path]
Expand Down Expand Up @@ -43,3 +46,15 @@
(get value))]
(io/make-parents new-file)
[new-file (relative-url target-path new-file)])))))

(defn notebook-relative-file!
"When evaluated by Clay as a notebook,
returns a pair of [file relative-path] such that one can write to file,
and include it in a document using the relative path.
When evaluated outside of Clay, returns nil.
`custom-name` will be used as a filename prefix.
`value` is used for de-duplication, only one file is returned per value.
`ext` is the file extension."
[custom-name value ext]
(when *context*
(next-file! *context* custom-name value ext)))
4 changes: 3 additions & 1 deletion src/scicloj/clay/v2/notebook.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns scicloj.clay.v2.notebook
(:require [clojure.string :as str]
[clojure.pprint :as pp]
[scicloj.clay.v2.files :as files]
[scicloj.clay.v2.util.path :as path]
[scicloj.clay.v2.item :as item]
[scicloj.clay.v2.prepare :as prepare]
Expand Down Expand Up @@ -430,7 +431,8 @@
(binding [*ns* *ns*
*warn-on-reflection* *warn-on-reflection*
*unchecked-math* *unchecked-math*
pp/*print-right-margin* pprint-margin]
pp/*print-right-margin* pprint-margin
files/*context* spec]
(-> (relevant-notes spec)
(complete-notes spec)
(with-out-err-captured))))
Expand Down