Last active
January 5, 2025 23:49
-
-
Save respatialized/ae664301c01a8c6698a4dfb40540c3ab to your computer and use it in GitHub Desktop.
kindly-render tap browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:deps {org.scicloj/kindly-render | |
#_{:mvn/version "0.1.1-alpha"} | |
{:git/url "https://github.com/scicloj/kindly-render" | |
:sha "d77dee338c7d72d157e20b5a45a5513441f5d5e5"} | |
com.github.igrishaev/ring-jdk-adapter {:mvn/version "0.1.1"} | |
;; use newer version to avoid JDK22+ errors | |
io.github.nextjournal/markdown {:mvn/version "0.6.157"} | |
org.clojure/data.json {:mvn/version "2.5.1"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns respatialized.tappy | |
"Tap browser" | |
(:require [ring.adapter.jdk :as jdk] | |
[scicloj.kindly-render.notes.to-html-page :as to-html] | |
[clojure.java.browse :refer [browse-url]])) | |
(def display-value (atom nil)) | |
(defn guide | |
"Use kindly-render to display the value and convey it to the atom used by the server" | |
[value] | |
(let [rendered-html (to-html/render-note {:value value})] | |
(reset! display-value (:html rendered-html)))) | |
(defn show | |
[request] | |
{:status 200 | |
:headers {"Content-Type" "text/html; charset=utf-8"} | |
:body @display-value}) | |
(def preferences {:host "127.0.0.1" :port 9099 :root-path "/tappy"}) | |
(defn display! | |
[options] | |
(let [config (merge preferences options)] | |
(add-tap guide) | |
(let [srv (jdk/server show config)] | |
(browse-url | |
(str "http://" (:host config) ":" (:port config) (:root-path config))) | |
srv))) | |
(def server (display! {})) | |
(defn conclude! [srv] (remove-tap guide) (jdk/stop srv)) | |
(comment | |
(conclude! server) | |
@display-value | |
(tap> [1 2 3 4 5 6]) | |
(tap> ^:kind/hiccup [:div [:strong "test text"]]) | |
(tap> ["something"]) | |
(tap> "something") | |
(to-html/render-note {:value "something"}) | |
(to-html/render-note {:value 1}) | |
(to-html/render-note {:value [1 2 3 4 5 6]})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment