Skip to content

Commit

Permalink
floating repl added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Sep 16, 2024
1 parent 72ed9e7 commit 8af1e3d
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 40 deletions.
4 changes: 4 additions & 0 deletions demo/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
org.pinkgorilla/webly {:mvn/version "0.7.693"}
; ui modules for demo notebooks:
org.pinkgorilla/ui-highcharts {:mvn/version "0.0.29"}

; run by default in docs-services
nrepl/nrepl {:mvn/version "1.2.0"}
cider/cider-nrepl {:mvn/version "0.49.1"}
}

:aliases
Expand Down
4 changes: 3 additions & 1 deletion demo/resources/ext/demo.edn
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{:name "demo-reval"
:lazy true
:depends-on #{:reval-ui}
:cljs-namespace [demo.page.overlay]
:cljs-ns-bindings {'demo.page.overlay {'overlay-page demo.page.overlay/overlay-page}}

:cljs-routes {"" reval.page.viewer/viewer-page
; "devtools/repl" :repl

"frepl" demo.page.overlay/overlay-page
}

;
Expand Down
9 changes: 9 additions & 0 deletions demo/resources/reval/demo-services.edn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
:stop (webly.app.app/stop-webly this)}


:nrepl {:start (nrepl.server/start-server
:bind "0.0.0.0"
:port 9100
:middleware cider.nrepl.middleware/cider-middleware
:handler cider.nrepl/cider-nrepl-handler)
:stop (.close this)}




;
}}
131 changes: 131 additions & 0 deletions demo/src/demo/frepl.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
(ns demo.frepl
(:require
[clojure.string :as string]
[modular.system]
[reval.document.notebook]
[reval.kernel.protocol :refer [kernel-eval]]
[promesa.core :as p]))

;; first lets get the running reval instance
(def s (modular.system/system :reval))

(def code
(reval.document.notebook/load-src "notebook.study.movies" :clj))

code

(p/await (kernel-eval {:kernel :clj
:ns "notebook.study.movies"
:code code}))


(p/await (kernel-eval {:kernel :clj
:ns "user"
:code code}))


(p/await (kernel-eval {:code "(println 3) (def x 777) (defn f [] 99) (+ 3 4)"
:kernel :clj
:ns "bongotrott"
:id 1}))

(defn add-ns [ns]
(str "(in-ns '" ns ")\r\n"))

(def code-ns (add-ns "notebook.study.movies"))


code-ns
(p/await (kernel-eval {:kernel :clj
:ns "user"
:code code-ns}))




(load-string code)

(def code2
(let [ns "notebook.study.movies"
code-ns (if (and ns (not (string/blank? ns)))
(str "(in-ns '" ns " ) ")
"nil")
code-with-ns (str code-ns " [ " code " (str *ns*) ]")]
code-with-ns))

code2

(load-string code2)


(def code3
(let [ns "notebook.study.movies"
code-ns (if (and ns (not (string/blank? ns)))
(str "(in-ns '" ns " ) ")
"nil")
code-with-ns (str code-ns code )]
code-with-ns))

code3

(load-string code3)

(load-string "(in-ns 'xxx) (def a 1)")


(load-string "(in-ns 'xxx) *ns*")

(load-string "(ns abc)(def x 777) (defn f [] 99) (+ 3 4)")

(load-string "(in-ns 'abc)(def x 777) (defn f [] 99) (+ 3 4)")

(load-string "(in-ns 'ddd)(def x 777) (defn f [] 99) (+ 3 4)")

(load-string "(in-ns 'ddd)(def x 777)")

(load-string "(in-ns 'ddd)(def x 777) (defn y [] 4)")

(load-string "(ns xxx) *ns*")


(load-string "*ns*")

(load-string "(ns yyy) *ns*")



(p/await (kernel-eval {:kernel :clj
:ns "notebook.study.movies"
:code "*ns*"}))

(p/await (kernel-eval {:kernel :clj
:ns "notebook.study.movies"
:code code-with-ns}))


(def code2 "(ns bongo) (def x 34) (+ x 4) *ns*")


(p/await (kernel-eval {:kernel :clj
;:ns "user"
:code code2}))


(p/await (kernel-eval {:kernel :clj
:ns "bongo"
:code "*ns*"}))


(load-string "*ns*")

(load-string "(ns bongo) (def y 36)")

(load-string "(in-ns 'bongo) y")


; (in-ns 'yippie2)
(load-string "(ns yippie7 (:require [clojure.pprint :refer [print-table]]))
(def movies [{:a 1} {:a 2}])
(print-table movies)
*ns*
")
29 changes: 20 additions & 9 deletions demo/src/demo/notebook.clj
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
(ns demo.notebook
(:require
[modular.system]
[reval.document.notebook :refer [eval-notebook load-notebook]]
;[scratchpad.core :refer [show! show-as clear!]]
; [demo.init] ; side effects
))

;; first lets get the running reval instance
(def s (modular.system/system :reval))



;; checkout one notebook..

(-> (eval-notebook "notebook.study.movies")
(eval-notebook s "notebook.study.movies")


(-> (eval-notebook s "notebook.study.movies")
meta)

(-> (eval-notebook "user.notebook.movies")


(-> (eval-notebook s "user.notebook.movies")
:content
count)

(->> (eval-notebook "user.notebook.movies")
(->> (eval-notebook s "user.notebook.movies")
(show-as :p/notebook))

(load-notebook "user.notebook.movies")
(load-notebook s "user.notebook.movies")

(-> (load-notebook "user.bongo.xyr")
(-> (load-notebook s "user.bongo.xyr")
println)

(-> (load-notebook "")
(-> (load-notebook s "")
println)

(-> (load-notebook nil)
(-> (load-notebook s nil)
println)

;; eval an notebook that does not exist:

(->> (eval-notebook "user.notebook.image") ; this does not exist !!
(->> (eval-notebook s "user.notebook.image") ; this does not exist !!
(show-as :p/notebook)) ;; we will get a notebook that contains an error.

;; eval a list of notebooks
Expand All @@ -42,7 +53,7 @@

;; show notebook in scratchpad

(->> (eval-notebook "user.notebook.movies")
(->> (eval-notebook s "user.notebook.movies")
show!)


Expand Down
31 changes: 31 additions & 0 deletions demo/src/demo/page/overlay.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(ns demo.page.overlay
(:require
[reval.frepl :refer [show-floating-repl show-floating-repl-namespace]]))


(defn overlay-page [{:keys [route-params query-params handler] :as route}]
[:div
[:h1 "I am a normal reagent page. But I can add a floating repl."]
[:a {:on-click #(show-floating-repl {:code "(+ 1 2 3)"})}
[:p "show code (floating)"]]
[:a {:on-click #(show-floating-repl {:code "(+ 1 2 3)"
:render-fn 'reval.viz.render-fn/reagent
:data ^{:hiccup true}
[:span {:style {:color "blue"}} "25"]}
)}
[:p "show code (eval result)"]]

[:a {:on-click #(show-floating-repl-namespace {:ns "notebook.study.movies"
:kernel :clj
})}
[:p "show code (namespace)"]]


[:a {:on-click #(show-floating-repl-namespace {:ns "demo.notebook.highcharts"
:kernel :clj})}
[:p "show code (highcharts)"]]



])

10 changes: 10 additions & 0 deletions demo/src/notebook/study/movies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
{:name "Matrix" :year 1999 :studio "Warner Bros" :producer "Joel Silver"}
{:name "Dr. Strange" :year 2016 :studio "Marvel Studios" :producer "Scott Derrickson"}])

*ns*

(print-table movies)


(def more-movies
(conj movies {:name "Harry Potter" :year 2020})
)

(count more-movies)



9 changes: 5 additions & 4 deletions reval-ui/deps.edn
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{:paths ["src"
"resources"]
:deps
{org.pinkgorilla/reval {:local/root "../reval" :deps/manifest :deps}
{nano-id/nano-id {:mvn/version "1.1.0"}
org.pinkgorilla/reval {:local/root "../reval" :deps/manifest :deps}
; deps to ui extensions used in reval
org.pinkgorilla/pinkie {:mvn/version "0.5.232"} ; error boundary
org.pinkgorilla/ui-repl {:mvn/version "0.1.105"} ; reagent
org.pinkgorilla/ui-input {:mvn/version "0.2.47"} ; spaces
org.pinkgorilla/ui-repl {:mvn/version "0.1.107"} ; reagent
org.pinkgorilla/ui-input {:mvn/version "0.2.48"} ; spaces, rnd, overlay
org.pinkgorilla/ui-codemirror {:mvn/version "0.1.48"}
org.pinkgorilla/ui-highlightjs {:mvn/version "0.1.19"}
org.pinkgorilla/clj-service {:mvn/version "0.3.18"}}
org.pinkgorilla/clj-service {:mvn/version "0.3.20"}}

:aliases
{; github ci MULTI-DEPS VERSION
Expand Down
6 changes: 4 additions & 2 deletions reval-ui/resources/ext/reval-ui.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:name "reval-ui"
; build
:lazy true
:depends-on #{:ui-codemirror :ui-repl}
:depends-on #{:ui-codemirror :ui-repl :ui-rnd}
:cljs-namespace [reval.viz.data
reval.viz.render-fn
reval.type.cljs ; side-effects; load protocols for cljs and sci
Expand All @@ -18,7 +18,9 @@
'kernel-eval reval.kernel.protocol/kernel-eval}
'reval.page.viewer {'viewer-page reval.page.viewer/viewer-page}
'reval.page.repl {'repl-page reval.page.repl/repl-page}
'reval.notebook-ui.editor {'block-for reval.notebook-ui.editor/block-for}}
'reval.notebook-ui.editor {'block-for reval.notebook-ui.editor/block-for}
'reval.frepl {'show-floating-repl reval.frepl/show-floating-repl
'show-floating-repl-namespace reval.frepl/show-floating-repl-namespace}}

; run
;:api-routes {"rdocument/" {"ns" reval.document-handler/wrapped-get-ns-list
Expand Down
Loading

0 comments on commit 8af1e3d

Please sign in to comment.