diff --git a/README.md b/README.md index 148e971..0183fb3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - clone this repo ``` cd demo - clj -X:nbeval + clj -X:webly:npm-install clj -X:webly:compile clj -X:webly:run @@ -31,10 +31,7 @@ The devtools config we use (in goldly-docs) ``` ``` -(reval.config/set-config! - {:storage-root "demo/rdocument/" - :url-root "/api/rdocument/file/"}) -``` + By default storage root is "/tmp/rdocument/". diff --git a/demo/deps.edn b/demo/deps.edn index be6a020..1d56ebd 100644 --- a/demo/deps.edn +++ b/demo/deps.edn @@ -2,7 +2,7 @@ :deps {org.pinkgorilla/reval {:local/root "../reval" :deps/manifest :deps} org.pinkgorilla/reval-ui {:local/root "../reval-ui" :deps/manifest :deps} - org.pinkgorilla/webly {:mvn/version "0.5.683"} + org.pinkgorilla/webly {:mvn/version "0.7.693"} ; ui modules for demo notebooks: org.pinkgorilla/ui-highcharts {:mvn/version "0.0.29"} } diff --git a/demo/resources/reval/demo-services.edn b/demo/resources/reval/demo-services.edn index 84b6681..dd38677 100644 --- a/demo/resources/reval/demo-services.edn +++ b/demo/resources/reval/demo-services.edn @@ -4,16 +4,25 @@ {:config {:start (modular.config/load-config! (:config #ref [:modular]))} :exts {:start (extension/discover)} + :permission {:start (modular.permission.core/start-permissions + {} ; empty users, as we dont use oauth2 here for identity / user managmenet + )} + + :clj-service {:start (clj-service.core/start-clj-services + (clip/ref :permission) + (clip/ref :exts))} + + :reval {:start (reval.core/start-reval + {:config (:reval (deref (clip/ref :config))) + :clj (clip/ref :clj-service) + :reval-role nil})} + :webly {:start (webly.app.app/start-webly + (clip/ref :exts) (deref (clip/ref :config)) (:profile #ref [:modular])) :stop (webly.app.app/stop-webly this)} - :clj-service {:start (goldly.service/start-clj-services - (clip/ref :exts))} - - :reval {:start (reval.config/set-config! - (:reval (deref (clip/ref :config))))} ; diff --git a/demo/resources/reval/task-services.edn b/demo/resources/reval/task-services.edn index 0ffb958..0bb9b2a 100644 --- a/demo/resources/reval/task-services.edn +++ b/demo/resources/reval/task-services.edn @@ -4,8 +4,10 @@ {:config {:start (modular.config/load-config! (:config #ref [:modular]))} :exts {:start (extension/discover)} - :reval {:start (reval.config/set-config! - (:reval (deref (clip/ref :config))))} + :reval {:start (reval.core/start-reval + {:config (:reval (deref (clip/ref :config))) + :clj nil + :reval-role nil})} ; }} diff --git a/reval-ui/build.clj b/reval-ui/build.clj index f8207b0..3996ba7 100644 --- a/reval-ui/build.clj +++ b/reval-ui/build.clj @@ -5,7 +5,7 @@ )) (def lib 'org.pinkgorilla/reval) -(def version (format "0.6.%s" (b/git-count-revs nil))) +(def version (format "0.7.%s" (b/git-count-revs nil))) (defn jar "build the JAR" [opts] (println "Building the JAR") diff --git a/reval-ui/deps.edn b/reval-ui/deps.edn index 648d6a2..6252215 100644 --- a/reval-ui/deps.edn +++ b/reval-ui/deps.edn @@ -4,11 +4,11 @@ {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.104"} ; reagent - org.pinkgorilla/ui-input {:mvn/version "0.2.45"} ; spaces + org.pinkgorilla/ui-repl {:mvn/version "0.1.105"} ; reagent + org.pinkgorilla/ui-input {:mvn/version "0.2.47"} ; spaces org.pinkgorilla/ui-codemirror {:mvn/version "0.1.48"} - org.pinkgorilla/ui-highlightjs {:mvn/version "0.1.17"} - org.pinkgorilla/clj-service {:mvn/version "0.2.9"}} + org.pinkgorilla/ui-highlightjs {:mvn/version "0.1.19"} + org.pinkgorilla/clj-service {:mvn/version "0.3.18"}} :aliases {; github ci MULTI-DEPS VERSION @@ -16,7 +16,7 @@ slipset/deps-deploy {:mvn/version "0.2.1"} io.github.seancorfield/build-clj {:git/tag "v0.5.4" :git/sha "bc9c0cc"} babashka/fs {:mvn/version "0.0.5"} - org.pinkgorilla/modular {:mvn/version "0.0.40"} ; modular.date + ;org.pinkgorilla/modular {:mvn/version "0.2.56"} ; modular.date } :ns-default build :jvm-opts ["-Dmaven.wagon.rto=90000"]} diff --git a/reval-ui/resources/ext/reval-ui.edn b/reval-ui/resources/ext/reval-ui.edn index fa9f2ec..93e77ab 100644 --- a/reval-ui/resources/ext/reval-ui.edn +++ b/reval-ui/resources/ext/reval-ui.edn @@ -21,20 +21,12 @@ 'reval.notebook-ui.editor {'block-for reval.notebook-ui.editor/block-for}} ; run - :api-routes {"rdocument/" {"ns" reval.document-handler/wrapped-get-ns-list - "files" reval.document-handler/wrapped-get-ns-files - ["file/" :ns "/" :name] reval.document-handler/wrapped-ns-file-handler}} + ;:api-routes {"rdocument/" {"ns" reval.document-handler/wrapped-get-ns-list + ; "files" reval.document-handler/wrapped-get-ns-files + ; ["file/" :ns "/" :name] reval.document-handler/wrapped-ns-file-handler}} :cljs-routes {"reval/" {"viewer" reval.page.viewer/viewer-page "repl" reval.page.repl/repl-page}} - :clj-services {:name "reval" - :permission #{:dev} - :symbols [reval.viz.eval/viz-eval-blocking - reval.document.collection/nb-collections - reval.save/save-code - ; used in repl: - reval.document.notebook/load-src - reval.document.notebook/load-notebook - reval.document.notebook/eval-notebook - reval.document.notebook/save-notebook]}} + ; +} diff --git a/reval-ui/src/reval/helper/url_loader.cljs b/reval-ui/src/reval/helper/url_loader.cljs index abe8963..9aa49e4 100644 --- a/reval-ui/src/reval/helper/url_loader.cljs +++ b/reval-ui/src/reval/helper/url_loader.cljs @@ -1,9 +1,10 @@ (ns reval.helper.url-loader (:require [reagent.core :as r] + [promesa.core :as p] [taoensso.timbre :refer [debug info warnf error]] [pinkie.ui.core :refer [error-boundary]] - [goldly.service.core :as service] + [goldly.service.core :refer [clj]] [pinkgorilla.repl.cljs.http :refer [get-str get-edn]])) (def show-loader-debug-ui false) @@ -12,6 +13,17 @@ ;http://localhost:8000/api/viewer/file/demo.playground.cljplot/1.txt +(defn clj->atom [a fun args] + (let [args (or args []) + rp (apply clj {:timeout 120000} fun args)] + (-> rp + (p/then (fn [res] + (println "clj success: " res) + (swap! a assoc :data res))) + (p/catch (fn [err] + (println "clj error: " err)))) + nil)) + (defn load-url [fmt url a arg-fetch args-fetch] (let [comparator? (or url arg-fetch args-fetch) comparator [url arg-fetch args-fetch]] @@ -23,11 +35,10 @@ :txt (get-str url a [:data]) :edn (get-edn url a [:data]) :clj (if arg-fetch - (service/run-a a [:data] url arg-fetch) + (clj->atom a url arg-fetch) (if args-fetch - (apply service/run-a a [:data] url args-fetch) - (service/run-a a [:data] url)))) - + (clj->atom a url args-fetch) + (clj->atom a url [])))) nil) (swap! a assoc :data nil)))) diff --git a/reval-ui/src/reval/notebook_ui/editor.cljs b/reval-ui/src/reval/notebook_ui/editor.cljs index dd549f2..2574d56 100644 --- a/reval-ui/src/reval/notebook_ui/editor.cljs +++ b/reval-ui/src/reval/notebook_ui/editor.cljs @@ -4,7 +4,7 @@ [ui.codemirror.theme :as theme] [ui.codemirror.api :as api] [ui.codemirror.codemirror :refer [codemirror get-editor]] - [goldly.service.core :as service] + [goldly.service.core :refer [clj]] [reval.notebook-ui.rewrite :refer [block-for]])) (defonce editor-id (r/atom 27)) @@ -20,12 +20,8 @@ (defn save-code [path] (let [code (cm-get-code)] - (service/run-cb {:fun 'reval.save/save-code - :args [{:code code :path path}] - :timeout 1000 - :cb (fn [[_s {:keys [_result]}]] - ;(println "result: " result) - )}))) + (clj {:timeout 1000} + 'reval.save/save-code {:code code :path path}))) (def cm-opts {:lineWrapping false}) diff --git a/reval/deps.edn b/reval/deps.edn index b0a00b2..4ffb4f0 100644 --- a/reval/deps.edn +++ b/reval/deps.edn @@ -4,7 +4,7 @@ org.clojure/data.codec {:mvn/version "0.1.1"} ; image base64 encoding rewrite-clj/rewrite-clj {:mvn/version "1.1.47"} org.pinkgorilla/modular {:mvn/version "0.2.56"} - org.pinkgorilla/timbre {:mvn/version "0.0.6"} + org.pinkgorilla/timbre {:mvn/version "0.0.7"} funcool/promesa {:mvn/version "11.0.674"}} :aliases @@ -34,7 +34,7 @@ :extra-deps {io.github.cognitect-labs/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git" :sha "dd6da11611eeb87f08780a30ac8ea6012d4c05ce"} - org.pinkgorilla/timbre {:mvn/version "0.0.6"}} + org.pinkgorilla/timbre {:mvn/version "0.0.7"}} :exec-fn cognitect.test-runner.api/test :main-opts ["-m" "cognitect.test-runner"]} diff --git a/reval/test/reval/type/image_test.clj b/reval/image_test_BAD.clj similarity index 100% rename from reval/test/reval/type/image_test.clj rename to reval/image_test_BAD.clj diff --git a/reval/src/reval/config.clj b/reval/src/reval/config.clj deleted file mode 100644 index a9d9ba6..0000000 --- a/reval/src/reval/config.clj +++ /dev/null @@ -1,21 +0,0 @@ -(ns reval.config) - -(def default-reval-config - {:rdocument {:storage-root "/tmp/rdocument/" - :url-root "/api/rdocument/file/"} - :collections {:user [:clj "user/notebook/"] - :demo [:clj "demo/notebook/"] - :demo-cljs [:cljs "demo/notebook/"]}}) - -(def config (atom default-reval-config)) - -(defn set-config! [reval-config] - (println "reval config: " reval-config) - (let [reval-config {:rdocument (or (:rdocument reval-config) - (:rdocument default-reval-config)) - :collections (or (:collections reval-config) - (:collections default-reval-config))}] - (reset! config reval-config))) - -(defn get-in-reval-config [path] - (get-in @config path)) diff --git a/reval/src/reval/core.clj b/reval/src/reval/core.clj new file mode 100644 index 0000000..8ddd0ff --- /dev/null +++ b/reval/src/reval/core.clj @@ -0,0 +1,41 @@ +(ns reval.core + (:require + [taoensso.timbre :as timbre :refer [debug info infof error]] + [clj-service.core :refer [expose-functions]] + [reval.default] ; side effects to include all default converters + )) + +(def default-reval-config + {:rdocument {:storage-root "/tmp/rdocument/" + :url-root "/api/rdocument/file/"} + :collections {:user [:clj "user/notebook/"] + :demo [:clj "demo/notebook/"] + :demo-cljs [:cljs "demo/notebook/"]}}) + +(defn sanitize-config [reval-config] + {:rdocument (or (:rdocument reval-config) + (:rdocument default-reval-config)) + :collections (or (:collections reval-config) + (:collections default-reval-config))}) + +(defn start-reval [{:keys [config clj reval-role] :as this}] + (info "starting reval service..") + (let [config (sanitize-config config)] + (when clj + (expose-functions clj + {:name "reval" + :symbols ['reval.viz.eval/viz-eval-blocking + 'reval.save/save-code + 'reval.document.notebook/load-src] + :permission reval-role + :fixed-args []}) + (expose-functions clj + {:name "reval" + :symbols ['reval.document.collection/nb-collections ; this + 'reval.document.notebook/load-notebook ; this + 'reval.document.notebook/eval-notebook ; this + 'reval.document.notebook/save-notebook] ; this + :permission reval-role + :fixed-args [this]})) + {:config config})) + diff --git a/reval/src/reval/document/collection.clj b/reval/src/reval/document/collection.clj index 1b29e7f..b50648f 100644 --- a/reval/src/reval/document/collection.clj +++ b/reval/src/reval/document/collection.clj @@ -4,8 +4,7 @@ [clojure.java.io :as io] [modular.resource.explore :refer [describe-files]] [reval.document.path :refer [split-ext is-format? ext-is-format? filename->ns]] - [reval.document.notebook :refer [eval-notebook]] - [reval.config :refer [get-in-reval-config]])) + [reval.document.notebook :refer [eval-notebook]])) ; this does not work. meta-data cannot be assoced to a string #_(defn name-with-meta [{:keys [name path] :as entry}] @@ -52,18 +51,18 @@ [k [(first v) (get-nss-list (first v) (rest v))]]) spec) (into {}))) -(defn eval-collection [[name [t ns-list]]] +(defn eval-collection [this [name [t ns-list]]] (doall - (map #(eval-notebook (:nbns %)) ns-list))) + (map #(eval-notebook this (:nbns %)) ns-list))) -(defn eval-collections [colls] +(defn eval-collections [this colls] ; {:demo [:clj []] ; :user [:clj ["test.notebook.apple"]]} (doall - (map eval-collection colls))) + (map (partial eval-collection this) colls))) -(defn nb-collections [] - (get-collections (get-in-reval-config [:collections]))) +(defn nb-collections [this] + (get-collections (get-in this [:config :collections]))) (comment @@ -113,10 +112,16 @@ {:test5 [:clj "notebook/test27/"] :study [:clj "notebook/study/"]}) - (nb-collections) + (def this {:config {:rdocument {:storage-root "/tmp/rdocument/" + :url-root "/api/rdocument/file/"} + :collections {:user [:clj "user/notebook/"] + :demo [:clj "demo/notebook/"] + :demo-cljs [:cljs "demo/notebook/"]}}}) - (-> (nb-collections) - eval-collections) + (nb-collections this) + + (->> (nb-collections this) + (eval-collections this)) ; ) diff --git a/reval/src/reval/document/manager.clj b/reval/src/reval/document/manager.clj index 84d4ddf..ce6096e 100644 --- a/reval/src/reval/document/manager.clj +++ b/reval/src/reval/document/manager.clj @@ -4,8 +4,7 @@ [clojure.string :as str] [clojure.java.io :as io] [modular.persist.protocol :as p] - [reval.document.path :refer [ns->dir]] - [reval.config :refer [get-in-reval-config]])) + [reval.document.path :refer [ns->dir]])) ; get-filename and get-link may NOT contain the fmt parameter ; the name contains the extension. The reason is, that we have @@ -18,29 +17,29 @@ ;; URL side -(defn storage-root [] - (get-in-reval-config [:rdocument :storage-root])) +(defn storage-root [this] + (get-in this [:config :rdocument :storage-root])) -(defn url-root [] - (get-in-reval-config [:rdocument :url-root])) +(defn url-root [this] + (get-in this [:config :rdocument :url-root])) -(defn get-link-ns [ns name] - (str (url-root) ns "/" name)) +(defn get-link-ns [this ns name] + (str (url-root this) ns "/" name)) ;; FILE side -(defn get-path-ns [ns] - (str (storage-root) (ns->dir ns) "/")) +(defn get-path-ns [this ns] + (str (storage-root this) (ns->dir ns) "/")) -(defn get-filename-ns [ns name] - (str (get-path-ns ns) name)) +(defn get-filename-ns [this ns name] + (str (get-path-ns this ns) name)) (defn- ensure-directory [path] (when-not (.exists (io/file path)) (.mkdir (java.io.File. path)))) -(defn- ensure-directory-ns [ns] - (let [root (storage-root) +(defn- ensure-directory-ns [this ns] + (let [root (storage-root this) ns-path (ns->dir ns) dirs (str/split ns-path #"/") ensure (fn [r dir] @@ -54,8 +53,8 @@ (doseq [f (reverse (file-seq (clojure.java.io/file fname)))] (clojure.java.io/delete-file f true))) -(defn delete-directory-ns [ns] - (let [ns-path (get-path-ns ns)] +(defn delete-directory-ns [this ns] + (let [ns-path (this get-path-ns ns)] (info "deleting reproduceable ns: " ns "path: " ns-path) (delete-recursively ns-path))) @@ -63,25 +62,27 @@ (let [ext (clojure.core/name format)] (str name "." ext))) -(defn save [data ns name-no-ext format] - (let [filename (-> (get-filename-ns ns name-no-ext) +(defn save [this data ns name-no-ext format] + ;(info "saving.. this: " this) + (let [filename (-> (get-filename-ns this ns name-no-ext) (add-extension format))] - (ensure-directory-ns ns) - (info "saving: " filename) + ;(info "filename: " filename) + (ensure-directory-ns this ns) + ;(info "saving: " filename) (p/save format filename data) data ; usable for threading macros )) -(defn loadr [ns name-no-ext format] - (let [filename (-> (get-filename-ns ns name-no-ext) +(defn loadr [this ns name-no-ext format] + (let [filename (-> (get-filename-ns this ns name-no-ext) (add-extension format))] (when (.exists (io/as-file filename)) (p/loadr format filename)))) ;; explore -(defn get-ns-list [] - (let [nb-root-dir (io/file (storage-root))] +(defn get-ns-list [this] + (let [nb-root-dir (io/file (storage-root this))] (if (and (.exists nb-root-dir) (.isDirectory nb-root-dir)) (->> nb-root-dir @@ -89,8 +90,8 @@ (map #(.getName %))) []))) -(defn get-document-list [ns] - (let [doc-dir (io/file (str (storage-root) (str ns)))] +(defn get-document-list [this ns] + (let [doc-dir (io/file (str (storage-root this) (str ns)))] (if (and (.exists doc-dir) (.isDirectory doc-dir)) (->> doc-dir @@ -100,25 +101,31 @@ (comment - (ensure-directory (storage-root)) + (def this {:config {:rdocument {:storage-root "/tmp/rdocument/" + :url-root "/api/rdocument/file/"} + :collections {:user [:clj "user/notebook/"] + :demo [:clj "demo/notebook/"] + :demo-cljs [:cljs "demo/notebook/"]}}}) - (get-filename-ns "demo.study3" "bongo.txt") + (ensure-directory (storage-root this)) - (get-link-ns "demo.notebook.image" "bongo.txt") + (get-filename-ns this "demo.study3" "bongo.txt") - (ensure-directory-ns "demo.test-notebook.apple") + (get-link-ns this "demo.notebook.image" "bongo.txt") - (save {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :edn) - (save {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott-1" :edn) - (save {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott-2" :edn) - (save {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :bad-format-3) + (ensure-directory-ns this "demo.test-notebook.apple") + + (save this {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :edn) + (save this {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott-1" :edn) + (save this {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott-2" :edn) + (save this {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :bad-format-3) ; should fail, needs ds - (save {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :arrow) + (save this {:a 1 :b "bongotrott" :c [1 2 3]} "demo.3" "bongotrott" :arrow) - (get-ns-list) + (get-ns-list this) - (get-document-list 'demo.3) + (get-document-list this 'demo.3) ;(require '[tablecloth.api :as tc]) ;(save (tc/dataset {:a [1.4 2.5]}) "demo.3" "bongotrott" :nippy) @@ -138,13 +145,13 @@ ; ;(save ns-nb n :arrow) ; )) - (-> (loadr "demo.3" "bongotrott-2" :edn) + (-> (loadr this "demo.3" "bongotrott-2" :edn) :c) - (loadr "demo.studies.asset-allocation-dynamic" "2" :txt) - (loadr "demo.studies.asset-allocation-dynamic" "ds2" :bad-format-5) - (loadr "demo.studies.asset-allocation-dynamic" "ds-777" :nippy) - (loadr "demo.studies.asset-allocation-dynamic" "ds2" :arrow) + (loadr this "demo.studies.asset-allocation-dynamic" "2" :txt) + (loadr this "demo.studies.asset-allocation-dynamic" "ds2" :bad-format-5) + (loadr this "demo.studies.asset-allocation-dynamic" "ds-777" :nippy) + (loadr this "demo.studies.asset-allocation-dynamic" "ds2" :arrow) (delete-recursively "demo/rdocument/demo/notebook/hello") diff --git a/reval/src/reval/document/notebook.clj b/reval/src/reval/document/notebook.clj index 7777cdd..593c9cb 100644 --- a/reval/src/reval/document/notebook.clj +++ b/reval/src/reval/document/notebook.clj @@ -1,6 +1,5 @@ (ns reval.document.notebook (:require - [clojure.string :as str] [clojure.java.io :as io] [taoensso.timbre :refer [debug info warnf]] [modular.helper.id :refer [guuid]] @@ -9,9 +8,7 @@ [reval.document.manager :as rdm] [reval.document.path :refer [ns->dir ns->filename]] [reval.document.src-parser :refer [text->notebook]] - [reval.kernel.clj-eval :refer [clj-eval]] - [reval.default] ; side effects to include all default converters - )) + [reval.kernel.clj-eval :refer [clj-eval]])) ;; create @@ -43,11 +40,11 @@ (into []))}) (defn create-notebook - ([ns] - (create-notebook ns :clj)) - ([ns fmt] + ([this ns] + (create-notebook this ns :clj)) + ([this ns fmt] (when ns - (rdm/delete-directory-ns ns)) + (rdm/delete-directory-ns this ns)) (let [src (if ns (load-src ns fmt) "")] @@ -61,20 +58,20 @@ ;; persistence (defn load-notebook - ([ns] - (load-notebook ns :clj)) - ([ns fmt] + ([this ns] + (load-notebook this ns :clj)) + ([this ns fmt] (let [nb (if ns - (rdm/loadr ns "notebook" :edn) + (rdm/loadr this ns "notebook" :edn) nil)] (-> (if nb nb - (create-notebook ns fmt)) + (create-notebook this ns fmt)) (with-meta {:render-as :p/notebook}))))) -(defn save-notebook [ns nb] +(defn save-notebook [this ns nb] (info "saving notebook: " ns) - (rdm/save nb ns "notebook" :edn)) + (rdm/save this nb ns "notebook" :edn)) ; eval @@ -104,10 +101,10 @@ (map nb-eval-segment segments))) (defn eval-notebook - ([ns] - (eval-notebook ns eval-result->hiccup)) ; default converter - ([ns eval-result-view-fn] - (let [nb (create-notebook ns) + ([this ns] + (eval-notebook this ns eval-result->hiccup)) ; default converter + ([this ns eval-result-view-fn] + (let [nb (create-notebook this ns) eval-results (eval-nb-segments nb ns) content (if eval-result-view-fn (map eval-result-view-fn eval-results) ; use here a better thing. @@ -117,7 +114,7 @@ (assoc-in [:meta :eval-time] (now-str)) (assoc-in [:meta :java] (-> (System/getProperties) (get "java.version"))) (assoc-in [:meta :clojure] (clojure-version)))] - (save-notebook ns nb) + (save-notebook this ns nb) (with-meta nb {:render-as :p/notebook})))) (comment @@ -152,12 +149,14 @@ ;; :out "", ;; :id :87929fe8-4003-4c25-9df4-512391857d07 } - (create-notebook "demo.notebook-test.apple") - (eval-notebook "demo.notebook-test.apple") + (def this {:config {}}) + + (create-notebook this "demo.notebook-test.apple") + (eval-notebook this "demo.notebook-test.apple") - (eval-notebook "demo.notebook.image") + (eval-notebook this "demo.notebook.image") - (load-notebook "user.notebook.banana") + (load-notebook this "user.notebook.banana") ; ) diff --git a/reval/src/reval/kernel/clj_eval.clj b/reval/src/reval/kernel/clj_eval.clj index 6919b5e..e8bcc5d 100644 --- a/reval/src/reval/kernel/clj_eval.clj +++ b/reval/src/reval/kernel/clj_eval.clj @@ -105,9 +105,6 @@ (clj-eval {:code "(println 3) (def x 777) (+ 3 4)" :ns "bongo"}) (clj-eval {:code "x" :ns "bongo" :id 3}) - (clj-eval {:code "(ns bongo (:require [reval.config :as c]))" :ns "bongo"}) - (clj-eval {:code "(ns bongo (:require [reval.config :as c]))" :ns "bongo"}) - (clj-eval {:code "(c/use-project)" :ns "bongo"}) (clj-eval {:code "*ns*" :ns "bongo"}) (-> (kernel-eval {:code "(ns bongo) (println 3) (+ 5 5)" :kernel :clj}) diff --git a/reval/src/reval/task.clj b/reval/src/reval/task.clj index 34ddfaa..e90b939 100644 --- a/reval/src/reval/task.clj +++ b/reval/src/reval/task.clj @@ -1,10 +1,13 @@ (ns reval.task (:require [clojure.java.io :as io] + [modular.system] [reval.document.collection :refer [nb-collections eval-collections]] [reval.default] ; side-effects [clojure.pprint :refer [print-table]])) +(def this (modular.system/system :reval)) + (def nb-welcome {:meta {:ns "welcome"} :content @@ -21,7 +24,7 @@ (defn eval-all-collections [m] (println "evaluating nb collections .. m: " (keys m)) - (let [cols (nb-collections)] + (let [cols (nb-collections this)] (ensure-directory "target") (ensure-directory "target/webly") (ensure-directory "target/webly/public") @@ -29,7 +32,7 @@ (spit "target/webly/public/rdocument/notebooks.edn" cols) (save-welcome) (println "nb-cols: " cols) - (eval-collections cols))) + (eval-collections this cols))) (defn- inline-coll [[cname coll]] (let [x (partition 2 coll) @@ -42,12 +45,12 @@ (defn print-all-collections [m] (println "nb collections .. m: " (keys m)) - (let [cols (nb-collections) + (let [cols (nb-collections this) cols-f (inline-collections cols)] (print-table [:coll :nbns :ext :kernel :path] cols-f))) (comment - (inline-collections (nb-collections)) + (inline-collections (nb-collections this)) (print-all-collections {}) (eval-all-collections {}) diff --git a/reval/src/reval/type/image.clj b/reval/src/reval/type/image.clj index 77435b0..6a60a4a 100644 --- a/reval/src/reval/type/image.clj +++ b/reval/src/reval/type/image.clj @@ -48,16 +48,16 @@ ;; image (to document manager) (defrecord imgrecord [image alt type width height ns] - hiccup-convertable - (to-hiccup [{:keys [^BufferedImage image alt type width height]}] - (let [name-no-ext (guuid-str) - name (str name-no-ext "." type) - src (rdm/get-link-ns ns name)] - (rdm/save image ns name-no-ext :png) - [:img {:src src - :width width - :height height - :alt alt}]))) + ;hiccup-convertable + #_(to-hiccup [{:keys [^BufferedImage image alt type width height]}] + (let [name-no-ext (guuid-str) + name (str name-no-ext "." type) + src (rdm/get-link-ns ns name)] + (rdm/save image ns name-no-ext :png) + [:img {:src src + :width width + :height height + :alt alt}]))) (defn image [^BufferedImage image & {:keys [alt type width height]}] (let [alt (or alt "") diff --git a/reval/test/reval/document/notebook_eval_test.clj b/reval/test/reval/document/notebook_eval_test.clj index 8f48f02..312ef96 100644 --- a/reval/test/reval/document/notebook_eval_test.clj +++ b/reval/test/reval/document/notebook_eval_test.clj @@ -1,15 +1,28 @@ (ns reval.document.notebook-eval-test (:require [clojure.test :refer [deftest is]] + [reval.document.manager :refer [storage-root url-root get-link-ns get-path-ns]] [reval.document.notebook :refer [eval-notebook load-notebook]] [reval.test-init])) -; this test relies on the default storage path -; defined in reval.config. +(def this {:config {:rdocument {:storage-root "/tmp/rdocument/" + :url-root "/api/rdocument/file/"} + :collections {:user [:clj "user/notebook/"] + :demo [:clj "demo/notebook/"] + :demo-cljs [:cljs "demo/notebook/"]}}}) + +(deftest config-test + (let [storage-root-val (storage-root this) + url-root-val (url-root this) + path-ns (get-path-ns this 'demo.apple)] + (is (= storage-root-val "/tmp/rdocument/")) + (is (= url-root-val "/api/rdocument/file/")) + (is (= url-root-val "/api/rdocument/file/")) + (is (= path-ns "/tmp/rdocument/demo/apple/")))) (deftest notebook-eval-test - (eval-notebook "test.notebook.apple") - (let [nb (load-notebook "test.notebook.apple") + (eval-notebook this "test.notebook.apple") + (let [nb (load-notebook this "test.notebook.apple") ;;(loadr :edn "/tmp/rdocument/test/notebook/apple/notebook.edn") segments (:content nb)] (is (= (get-in nb [:meta :ns]) "test.notebook.apple")) @@ -25,8 +38,8 @@ "hello\n")))) (comment - (eval-notebook "test.notebook.apple") - (load-notebook "test.notebook.apple") + (eval-notebook this "test.notebook.apple") + (load-notebook this "test.notebook.apple") ;(loadr :edn "demo/rdocument/demo/notebook_test/apple/notebook.edn") ; diff --git a/reval/test/reval/test_init.clj b/reval/test/reval/test_init.clj index 6048eaf..0266cbc 100644 --- a/reval/test/reval/test_init.clj +++ b/reval/test/reval/test_init.clj @@ -1,8 +1,6 @@ (ns reval.test-init (:require - [taoensso.timbre :refer [debug info warnf error]] [modular.log :refer [timbre-config!]] - [modular.config :as config] [reval.default] ;; side effect: to-hiccup value converter, persister loaded [reval.kernel.clj-eval] ;; side effect: add clj kernel )) @@ -10,12 +8,3 @@ (timbre-config! {:timbre-loglevel [[#{"*"} :info]]}) -(info "setting reval test config..") - -(config/set! - :reval - {:rdocument {:storage-root "/tmp/rdocument/" - :url-root "/api/rdocument/file/"} - :collections {:demo [:clj "demo/notebook/"] - :user [:clj "demo/notebook_test/"]}}) - diff --git a/reval-ui/src/reval/document_handler.clj b/src-junk/document_handler.clj similarity index 100% rename from reval-ui/src/reval/document_handler.clj rename to src-junk/document_handler.clj