Skip to content

Commit

Permalink
Merge pull request #131 from scicloj/cleanup-item-ns
Browse files Browse the repository at this point in the history
Clean up `scicloj.clay.v2.item`
  • Loading branch information
daslu authored Jul 24, 2024
2 parents 5c89fcb + 947f287 commit 995baba
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/scicloj/clay/v2/item.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
(ns scicloj.clay.v2.item
(:require [clojure.pprint :as pp]
[clojure.string :as string]
[charred.api :as charred]
[scicloj.clay.v2.files :as files]
[scicloj.clay.v2.util.image :as util.image]
[scicloj.kind-portal.v1.api :as kind-portal]
[scicloj.clay.v2.util.meta :as meta]
[hiccup.page]
[hiccup.core :as hiccup]
[clojure.string :as str]
[scicloj.kindly.v4.api :as kindly]))
[clojure.string :as str]))

(def *id (atom 0))

Expand All @@ -23,14 +20,13 @@

(defn escape [string]
(-> string
(string/escape
(str/escape
{\< "&lt;"
\> "&gt;"
\& "&amp;"
\" "&quot;"
\' "&apos;"})))


(defn clojure-code-item [{:keys [tag hiccup-element md-class]}]
(fn [string-or-strings]
(let [strings (->> string-or-strings
Expand All @@ -53,7 +49,7 @@
```
:::
" (name md-class) s)))
(string/join "\n"))})))
(str/join "\n"))})))

(def source-clojure
(clojure-code-item {:tag :source-clojure
Expand All @@ -65,8 +61,6 @@
:hiccup-element :code.sourceCode.language-clojure.printed-clojure
:md-class :printedClojure}))



(defn just-println [value]
(-> value
println
Expand All @@ -84,7 +78,7 @@
(defn md [text]
{:md (->> text
in-vector
(string/join "\n"))})
(str/join "\n"))})

(defn katex-hiccup [string]
[:div
Expand All @@ -98,7 +92,7 @@
{:md (->> text
in-vector
(map (partial format "$$%s$$"))
(string/join "\n"))
(str/join "\n"))
:hiccup (->> text
in-vector
(map katex-hiccup)
Expand All @@ -119,7 +113,6 @@
{:md string
:hiccup [:p string]})


(def next-id
(let [*counter (atom 0)]
#(str "id" (swap! *counter inc))))
Expand Down Expand Up @@ -165,7 +158,6 @@
};"))]]
:deps [:cytoscape]})


(defn echarts [{:as context
:keys [value]}]
{:hiccup [:div
Expand All @@ -181,7 +173,6 @@
};"))]]
:deps [:echarts]})


(defn plotly [{:as context
{:keys [data layout config]
:or {layout {}
Expand All @@ -197,7 +188,6 @@
(charred/write-json-str config))]]
:deps [:plotly]})


(defn portal [value]
{:hiccup [:div
[:script
Expand Down Expand Up @@ -226,11 +216,10 @@
[:a {:href url} path]
path)]]])]})


(defn html [html]
{:html (->> html
in-vector
(string/join "\n"))})
(str/join "\n"))})

(defn image [{:keys [value
full-target-path
Expand All @@ -245,17 +234,16 @@
image
".png")]
(when-not
(util.image/write! image "png" png-path)
(util.image/write! image "png" png-path)
(throw (ex-message "Failed to save image as PNG.")))
{:hiccup [:img {:src (-> png-path
(string/replace
(str/replace
(re-pattern (str "^"
base-target-path
"/"))
""))}]
:item-class "clay-image"}))


(defn vega-embed [{:keys [value
full-target-path
base-target-path]
Expand All @@ -270,7 +258,7 @@
".csv")]
(spit csv-path values)
{:url (-> csv-path
(string/replace
(str/replace
(re-pattern (str "^"
base-target-path
"/"))
Expand All @@ -284,7 +272,6 @@
(->> (format "vegaEmbed(document.currentScript.parentElement, %s);")))]]
:deps [:vega]}))


(defn video [{:keys [youtube-id
iframe-width
iframe-height
Expand All @@ -309,7 +296,7 @@
(defn observable [code]
{:md (->> code
in-vector
(string/join "\n")
(str/join "\n")
(format "
```{ojs}
//| echo: false
Expand Down

0 comments on commit 995baba

Please sign in to comment.