Add hoplon and javelin as a plugin (#73)

* Hoplon and Javelin plugins

* Only Hoplon plugin

* Bump promesa

* Update sci context access/update

* Bump sci
This commit is contained in:
Marcelo Nomoto 2023-11-20 14:39:38 -03:00 committed by GitHub
parent f63d50215d
commit d456009ca1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 89 additions and 24 deletions

View file

@ -3,7 +3,7 @@
{org.clojure/clojure {:mvn/version "1.11.1"}
thheller/shadow-cljs {:mvn/version "2.20.15"}
org.babashka/sci {:git/url "https://github.com/babashka/sci"
:git/sha "8da8f44c41f507e56256b23d0a05c0172d881859"}
:git/sha "3e4689f5163c825ba6fd3085d08b0f95eee00c40"}
#_{:local/root "../babashka/sci"}
reagent/reagent {:mvn/version "1.1.1"}
re-frame/re-frame {:mvn/version "1.3.0"}
@ -11,7 +11,7 @@
cljsjs/react-dom {:mvn/version "18.2.0-1"}
cljsjs/react-dom-server {:mvn/version "18.2.0-1"}
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
funcool/promesa {:mvn/version "10.0.575"}
funcool/promesa {:mvn/version "11.0.678"}
io.github.babashka/sci.nrepl
#_{:local/root "../sci.nrepl"}
{:git/url "https://github.com/babashka/sci.nrepl"
@ -19,7 +19,7 @@
io.github.babashka/sci.configs
#_{:local/root "/Users/borkdude/dev/sci.configs"}
{:git/url "https://github.com/babashka/sci.configs"
:git/sha "33bd51e53700b224b4cb5bda59eb21b62f962745"}}
:git/sha "08bab21643bc0c63a5b99c65193c9d24888270b7"}}
:aliases
{:dev
{:extra-paths ["dev"]

View file

@ -1,6 +1,8 @@
{:deps {io.github.babashka/scittle.build {:local/root "../../build"}
;; datascript plugin
io.github.babashka/scittle.datascript {:local/root "../../plugins/datascript"}
; io.github.babashka/scittle.datascript {:local/root "../../plugins/datascript"}
io.github.babashka/scittle.javelin {:local/root "../../plugins/javelin"}
io.github.babashka/scittle.hoplon {:local/root "../../plugins/hoplon"}
io.github.babashka/http-server
{:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}}
:tasks

View file

@ -1,14 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/css/style.css">
<!-- <link rel="stylesheet" href="/css/style.css"> -->
<script src="/js/scittle.js" type="application/javascript"></script>
<script src="/js/scittle.datascript.js" type="application/javascript"></script>
<script src="/js/scittle.javelin.js" type="application/javascript"></script>
<script src="/js/scittle.hoplon.js" type="application/javascript"></script>
<script type="application/x-scittle">
(require '[datascript.core :as d])
(prn (ns-publics 'datascript.core))
(require '[hoplon.core :as h])
(require '[javelin.core :as j])
(j/defc title "From Hoplon")
(h/body
(h/h1 (h/text "~{title}")))
</script>
</head>
<body>
<h1>Hello Hoplon!</h1>
</body>
</html>

3
plugins/hoplon/deps.edn Normal file
View file

@ -0,0 +1,3 @@
{:deps
{hoplon/hoplon {:mvn/version "7.5.0"}
io.github.babashka/sci.configs {:git/sha "08bab21643bc0c63a5b99c65193c9d24888270b7"}}}

View file

@ -0,0 +1,9 @@
(ns scittle.hoplon
{:no-doc true}
(:require [sci.configs.hoplon.hoplon :refer [config]]
[scittle.core :as scittle]))
(defn init []
(scittle/register-plugin!
::hoplon
config))

View file

@ -0,0 +1,9 @@
(ns scittle.javelin
{:no-doc true}
(:require [sci.configs.hoplon.javelin :refer [config]]
[scittle.core :as scittle]))
(defn init []
(scittle/register-plugin!
::javelin
config))

View file

@ -0,0 +1,13 @@
[{:name scittle/hoplon
:namespaces [javelin.core
hoplon.core
hoplon.dom]
:js "./scittle.hoplon.js"
:shadow-config
{:modules
{:scittle.hoplon {:init-fn scittle.hoplon/init
:depends-on #{:scittle :scittle.javelin}
:entries [hoplon.core hoplon.dom]}
:scittle.javelin {:init-fn scittle.javelin/init
:depends-on #{:scittle}
:entries [javelin.core]}}}}]

3
plugins/javelin/deps.edn Normal file
View file

@ -0,0 +1,3 @@
{:deps
{hoplon/javelin {:mvn/version "3.9.3"}
io.github.babashka/sci.configs {:git/sha "08bab21643bc0c63a5b99c65193c9d24888270b7"}}}

View file

@ -0,0 +1,9 @@
(ns scittle.javelin
{:no-doc true}
(:require [sci.configs.hoplon.javelin :refer [config]]
[scittle.core :as scittle]))
(defn init []
(scittle/register-plugin!
::javelin
config))

View file

@ -0,0 +1,8 @@
[{:name scittle/javelin
:namespaces [javelin.core]
:js "./scittle.javelin.js"
:shadow-config
{:modules
{:scittle.javelin {:init-fn scittle.javelin/init
:depends-on #{:scittle}
:entries [javelin.core]}}}}]

View file

@ -4,6 +4,7 @@
[goog.object :as gobject]
[goog.string]
[sci.core :as sci]
[sci.ctx-store :as store]
[sci.impl.unrestrict]
[scittle.impl.common :refer [cljns]]
[scittle.impl.error :as error]
@ -45,12 +46,12 @@
'sci.core {'stacktrace sci/stacktrace
'format-stacktrace sci/format-stacktrace}})
(def !sci-ctx
(atom (sci/init {:namespaces namespaces
:classes {'js js/globalThis
:allow :all
'Math js/Math}
:ns-aliases {'clojure.pprint 'cljs.pprint}})))
(store/reset-ctx!
(sci/init {:namespaces namespaces
:classes {'js js/globalThis
:allow :all
'Math js/Math}
:ns-aliases {'clojure.pprint 'cljs.pprint}}))
(def !last-ns (volatile! @sci/ns))
@ -58,21 +59,21 @@
(sci/binding [sci/ns @!last-ns]
(let [rdr (sci/reader s)]
(loop [res nil]
(let [form (sci/parse-next @!sci-ctx rdr)]
(let [form (sci/parse-next (store/get-ctx) rdr)]
(if (= :sci.core/eof form)
(do
(vreset! !last-ns @sci/ns)
res)
(recur (sci/eval-form @!sci-ctx form))))))))
(recur (sci/eval-form (store/get-ctx) form))))))))
(defn ^:export eval-string [s]
(try (-eval-string s)
(catch :default e
(error/error-handler e (:src @!sci-ctx))
(error/error-handler e (:src (store/get-ctx)))
(throw e))))
(defn register-plugin! [_plug-in-name sci-opts]
(swap! !sci-ctx sci/merge-opts sci-opts))
(store/swap-ctx! sci/merge-opts sci-opts))
(defn- eval-script-tags* [script-tags]
(when-let [tag (first script-tags)]
@ -84,7 +85,7 @@
(let [response (gobject/get this "response")]
(gobject/set tag "scittle_id" src)
;; save source for error messages
(swap! !sci-ctx assoc-in [:src src] response)
(store/swap-ctx! assoc-in [:src src] response)
(sci/binding [sci/file src]
(eval-string response)))
(eval-script-tags* (rest script-tags)))))]
@ -92,7 +93,7 @@
(if-let [text (not-empty (str/trim (gobject/get tag "textContent")))]
(let [scittle-id (str (gensym "scittle-tag-"))]
(gobject/set tag "scittle_id" scittle-id)
(swap! !sci-ctx assoc-in [:src scittle-id] text)
(store/swap-ctx! assoc-in [:src scittle-id] text)
(sci/binding [sci/file scittle-id]
(eval-string text))
(eval-script-tags* (rest script-tags)))

View file

@ -1,9 +1,10 @@
(ns scittle.nrepl
(:require
[clojure.edn :as edn]
[sci.ctx-store :as store]
[sci.nrepl.completions :refer [completions]]
[sci.nrepl.info :refer [info]]
[scittle.core :refer [!last-ns eval-string !sci-ctx]]))
[scittle.core :refer [!last-ns eval-string]]))
(defn nrepl-websocket []
(.-ws_nrepl js/window))
@ -29,7 +30,7 @@
:status ["error" "done"]})))))
(defn handle-nrepl-info [msg]
(let [info (info (assoc msg :ctx @!sci-ctx))]
(let [info (info (assoc msg :ctx (store/get-ctx)))]
(nrepl-reply msg info)))
(declare ops)
@ -61,13 +62,13 @@
:eldoc handle-nrepl-info
:lookup handle-nrepl-info
:describe handle-describe
:complete (fn [msg] (let [completions (completions (assoc msg :ctx @!sci-ctx))]
:complete (fn [msg] (let [completions (completions (assoc msg :ctx (store/get-ctx)))]
(nrepl-reply msg completions)))})
(defn handle-nrepl-message [msg]
(if-let [handler (ops (:op msg))]
(handler msg)
(nrepl-reply (merge msg {:status ["error" "done"] :err "unkown-op"}) (assoc msg :ctx @!sci-ctx))))
(nrepl-reply (merge msg {:status ["error" "done"] :err "unkown-op"}) (assoc msg :ctx (store/get-ctx)))))
(defn ws-url [host port path]
(str "ws://" host ":" port "/" path))