Skip to content

Commit

Permalink
Allow transform fns to hack on visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Nov 20, 2023
1 parent 60afdf9 commit b681d57
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@
(not= [0] path))
(str "-" (str/join "-" path))))))

(defn update-visibility [{:as x :nextjournal/keys [visibility]}]
(cond-> x
(= :hide (:result visibility))
(-> (assoc-in [:nextjournal/viewer :render-fn :form] '(fn [_ _] [:<>])))))

(defn transform-result [{:as wrapped-value :keys [path]}]
(let [{:as cell :keys [form id settings] ::keys [result doc]} (:nextjournal/value wrapped-value)
Expand All @@ -522,7 +526,8 @@
(select-keys (keys viewer-opts-normalization))
(set/rename-keys viewer-opts-normalization))
{:as to-present :nextjournal/keys [auto-expand-results?]} (merge (dissoc (->opts wrapped-value) :!budget :nextjournal/budget)
(dissoc cell :result)
(dissoc cell :result :settings)
(set/rename-keys (:settings cell) viewer-opts-normalization)
opts-from-block
(ensure-wrapped-with-viewers (or viewers (get-viewers (get-*ns*))) value))
presented-result (-> (present to-present)
Expand All @@ -537,7 +542,8 @@
#_(prn :presented-result viewer-eval? presented-result)
(-> wrapped-value
mark-presented
(merge {:nextjournal/value (cond-> {:nextjournal/presented presented-result :nextjournal/blob-id blob-id}
(merge {:nextjournal/value (cond-> {:nextjournal/presented (update-visibility presented-result)
:nextjournal/blob-id blob-id}
viewer-eval-result?
(assoc ::viewer-eval-form (-> presented-result :nextjournal/value :form))

Expand Down Expand Up @@ -632,8 +638,10 @@
{:nextjournal/render-opts (assoc (select-keys cell [:loc])
:id (processed-block-id (str id "-code")))}
(dissoc cell :result)))
(or result? eval?)
true #_ (or result? eval?)
(conj (cond-> (ensure-wrapped (-> cell (assoc ::doc doc) (set/rename-keys {:result ::result})))

;; TODO: viewer-eval case
(and eval? (not result?))
(assoc :nextjournal/viewer (assoc result-viewer :render-fn '(fn [_] [:<>])))))))))

Expand Down Expand Up @@ -915,7 +923,9 @@
{:name `mathjax-viewer :render-fn 'nextjournal.clerk.render/render-mathjax :transform-fn mark-presented})

(defn ->opts [wrapped-value]
;; TODO: use viewer-opts-normalization keys
(select-keys wrapped-value [:nextjournal/budget :nextjournal/css-class :nextjournal/width :nextjournal/render-opts
:nextjournal/visibility
:nextjournal/render-evaluator
:!budget :store!-wrapped-value :present-elision-fn :path :offset]))

Expand Down Expand Up @@ -1402,7 +1412,7 @@
(recur wrapped-value')
(-> wrapped-value'
(assoc :nextjournal/viewer viewer)
(merge (->opts wrapped-value))))))
(->> (merge (->opts wrapped-value)))))))

(defn apply-viewers [x]
(apply-viewers* (ensure-wrapped-with-viewers x)))
Expand Down

0 comments on commit b681d57

Please sign in to comment.