Skip to content

Commit

Permalink
cleanup and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Oct 5, 2023
1 parent ae1ee6e commit 29ae5da
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 75 deletions.
59 changes: 59 additions & 0 deletions src/scicloj/clay/v2/actions.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(ns scicloj.clay.v2.actions
(:require [scicloj.clay.v2.doc :as doc]
[scicloj.clay.v2.server :as server]
[scicloj.clay.v2.path :as path]))

(defn show-doc!
([path]
(show-doc! path nil))
([path {:keys [title toc? custom-message]
:as options}]
(server/show-message!
(or custom-message
[:div
[:p "showing document for "
[:code (path/path->filename path)]]
[:div.loader]]))
(let [doc (doc/gen-doc path options)]
(-> doc
(server/show-widgets!
{:title title
:toc? toc?})))
:ok))

(defn show-doc-and-write-html!
[path options]
(-> options
(assoc :custom-message [:div
[:p "showing document for "
[:code (path/path->filename path)]]
[:p "and then writing as html file"]
[:div.loader]]
:path path)
(->> (show-doc! path)))
(server/write-html!))

(defn gen-doc-and-write-quarto!
[path {:keys [title]
:as options}]
(server/show-message!
[:div
[:p "generating Quarto document for "
[:code (path/path->filename path)]]
[:div.loader]])
(-> options
(assoc
:title (or title path)
:path path)
(->> (doc/gen-doc path))
server/write-quarto!))

(defn gen-doc-and-write-light-quarto!
[path {:keys [title]
:as options}]
(-> options
(assoc
:title (or title path)
:path path)
(->> (doc/gen-doc path))
server/write-light-quarto!))
30 changes: 13 additions & 17 deletions src/scicloj/clay/v2/api.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns scicloj.clay.v2.api
(:require [scicloj.clay.v2.pipeline :as pipeline]
[scicloj.kindly.v4.api :as kindly]
[scicloj.clay.v2.doc :as scittle.doc]
[scicloj.clay.v2.server :as scittle.server]
[scicloj.clay.v2.actions :as actions]
[scicloj.clay.v2.server :as server]
[scicloj.clay.v2.portal :as portal]
[clojure.string :as string]
[clojure.test]))
Expand Down Expand Up @@ -37,58 +37,54 @@
([path options]
(avoid-recursion
(start!)
(scittle.doc/show-doc! path options))
(actions/show-doc! path options))
[:ok]))

(defn write-html!
[path]
(scittle.server/write-html! path))

(defn show-namespace-and-write-html!
[path options]
(avoid-recursion
(->> {:format :html}
(merge options)
(scittle.doc/show-doc-and-write-html! path))))
(actions/show-doc-and-write-html! path))))

(defn generate-and-show-namespace-quarto!
[path options]
(avoid-recursion
(->> {:format :quarto}
(merge options)
(scittle.doc/gen-doc-and-write-quarto! path))))
(actions/gen-doc-and-write-quarto! path))))

(defn generate-namespace-light-quarto!
[path options]
(avoid-recursion
(->> {:format :quarto}
(merge options)
(scittle.doc/gen-doc-and-write-light-quarto! path))))
(actions/gen-doc-and-write-light-quarto! path))))

(defn browse!
[]
(scittle.server/browse!))
(server/browse!))

(defn port
[]
(scittle.server/port))
(server/port))

(defn url
[]
(scittle.server/url))
(server/url))

(defn swap-options! [f & args]
(apply scittle.server/swap-options!
(apply server/swap-options!
f args))

(defn reset-options!
([]
(reset-options! scittle.server/default-options))
(reset-options! server/default-options))
([options]
(scittle.server/swap-options! (constantly options))))
(server/swap-options! (constantly options))))

(defn options []
(scittle.server/options))
(server/options))

(defn handle-form! [form]
(avoid-recursion
Expand Down
58 changes: 0 additions & 58 deletions src/scicloj/clay/v2/doc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,61 +149,3 @@
[separator
il])))))
doall)))




(defn show-doc!
([path]
(show-doc! path nil))
([path {:keys [title toc? custom-message]
:as options}]
(server/show-message!
(or custom-message
[:div
[:p "showing document for "
[:code (path/path->filename path)]]
[:div.loader]]))
(let [doc (gen-doc path options)]
(-> doc
(server/show-widgets!
{:title title
:toc? toc?})))
:ok))

(defn show-doc-and-write-html!
[path options]
(-> options
(assoc :custom-message [:div
[:p "showing document for "
[:code (path/path->filename path)]]
[:p "and then writing as html file"]
[:div.loader]]
:path path)
(->> (show-doc! path)))
(server/write-html!))

(defn gen-doc-and-write-quarto!
[path {:keys [title]
:as options}]
(server/show-message!
[:div
[:p "generating Quarto document for "
[:code (path/path->filename path)]]
[:div.loader]])
(-> options
(assoc
:title (or title path)
:path path)
(->> (gen-doc path))
server/write-quarto!))

(defn gen-doc-and-write-light-quarto!
[path {:keys [title]
:as options}]
(-> options
(assoc
:title (or title path)
:path path)
(->> (gen-doc path))
server/write-light-quarto!))

0 comments on commit 29ae5da

Please sign in to comment.