From beebf6036949f0de810c22d12f7957d124ce02a9 Mon Sep 17 00:00:00 2001 From: Bobby Towers Date: Sun, 16 Apr 2023 15:29:48 -0700 Subject: [PATCH] remove everything except codemirror stuff --- bb.edn | 71 -------- deps.edn | 26 --- doc/dev.md | 109 ----------- doc/links.md | 7 - doc/nrepl/README.md | 61 ------- doc/nrepl/bb.edn | 17 -- doc/nrepl/index.html | 13 -- doc/nrepl/playground.cljs | 15 -- .../public/codemirror.html => index.html | 2 +- resources/public/base.html | 42 ----- resources/public/bookmarklet.html | 46 ----- resources/public/cljs/bookmarklet.cljs | 140 -------------- resources/public/cljs/nrepl_playground.cljs | 15 -- resources/public/cljs/script.cljs | 2 - resources/public/cljs/tictactoe.cljs | 85 --------- resources/public/css/style.css | 22 --- resources/public/disable_auto_eval.html | 26 --- resources/public/html/cljs-ajax.html | 23 --- resources/public/html/export.html | 16 -- resources/public/html/local.html | 15 -- resources/public/html/reagent.html | 25 --- resources/public/index.html | 171 ------------------ resources/public/nrepl.html | 14 -- resources/public/tictactoe.html | 44 ----- resources/public/wordle.html | 39 ---- script/release.clj | 75 -------- script/release.old | 15 -- shadow-cljs.edn | 32 ---- .../public/cljs => src}/codemirror.cljs | 0 src/scittle/cljs_ajax.cljs | 13 -- src/scittle/core.cljs | 107 ----------- src/scittle/impl/common.cljs | 4 - src/scittle/impl/error.cljs | 92 ---------- src/scittle/nrepl.cljs | 86 --------- src/scittle/pprint.cljs | 8 - src/scittle/promesa.cljs | 8 - src/scittle/re_frame.cljs | 8 - src/scittle/reagent.cljs | 19 -- .../public/test => test}/codemirror.html | 0 39 files changed, 1 insertion(+), 1512 deletions(-) delete mode 100644 bb.edn delete mode 100644 deps.edn delete mode 100644 doc/dev.md delete mode 100644 doc/links.md delete mode 100644 doc/nrepl/README.md delete mode 100644 doc/nrepl/bb.edn delete mode 100644 doc/nrepl/index.html delete mode 100644 doc/nrepl/playground.cljs rename resources/public/codemirror.html => index.html (97%) delete mode 100644 resources/public/base.html delete mode 100644 resources/public/bookmarklet.html delete mode 100644 resources/public/cljs/bookmarklet.cljs delete mode 100644 resources/public/cljs/nrepl_playground.cljs delete mode 100644 resources/public/cljs/script.cljs delete mode 100644 resources/public/cljs/tictactoe.cljs delete mode 100644 resources/public/css/style.css delete mode 100644 resources/public/disable_auto_eval.html delete mode 100644 resources/public/html/cljs-ajax.html delete mode 100644 resources/public/html/export.html delete mode 100644 resources/public/html/local.html delete mode 100644 resources/public/html/reagent.html delete mode 100644 resources/public/index.html delete mode 100644 resources/public/nrepl.html delete mode 100644 resources/public/tictactoe.html delete mode 100644 resources/public/wordle.html delete mode 100755 script/release.clj delete mode 100644 script/release.old delete mode 100644 shadow-cljs.edn rename {resources/public/cljs => src}/codemirror.cljs (100%) delete mode 100644 src/scittle/cljs_ajax.cljs delete mode 100644 src/scittle/core.cljs delete mode 100644 src/scittle/impl/common.cljs delete mode 100644 src/scittle/impl/error.cljs delete mode 100644 src/scittle/nrepl.cljs delete mode 100644 src/scittle/pprint.cljs delete mode 100644 src/scittle/promesa.cljs delete mode 100644 src/scittle/re_frame.cljs delete mode 100644 src/scittle/reagent.cljs rename {resources/public/test => test}/codemirror.html (100%) diff --git a/bb.edn b/bb.edn deleted file mode 100644 index 802138b..0000000 --- a/bb.edn +++ /dev/null @@ -1,71 +0,0 @@ -{:deps {io.github.babashka/sci.nrepl - #_{:local/root "../sci.nrepl"} - {:git/sha "2f8a9ed2d39a1b09d2b4d34d95494b56468f4a23"} - io.github.babashka/http-server - {:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}} - - :tasks - {:requires ([babashka.fs :as fs] - [cheshire.core :as json] - [babashka.process :as p :refer [process]]) - - clean {:doc "Start from clean slate." - :task (do (run! fs/delete (fs/list-dir (fs/file "resources" "public" "js") "**.*")) - (fs/delete-tree ".cpcache") - (fs/delete-tree ".shadow-cljs"))} - - shadow:watch {:doc "Development build. Starts webserver and watches for changes." - :task (clojure {:extra-env {"SCI_ELIDE_VARS" "true"}} - "-M:dev -m shadow.cljs.devtools.cli watch main")} - - http-server {:doc "Starts http server for serving static files" - :requires ([babashka.http-server :as http]) - :task (do (http/serve {:port 1341 :dir "resources/public"}) - (println "Serving static assets at http://localhost:1341"))} - - browser-nrepl {:doc "Start browser nREPL" - :requires ([sci.nrepl.browser-server :as bp]) - :task (bp/start! {})} - - -dev {:depends [shadow:watch browser-nrepl http-server]} - - dev {:doc "Development build. Starts webserver and watches for changes." - :task (do (run '-dev {:parallel true}) - (deref (promise)))} - - prod {:doc "Builds production artifacts." - :task (clojure {:extra-env {"SCI_ELIDE_VARS" "true"}} - "-M:dev -m shadow.cljs.devtools.cli release main")} - - dist {:doc "Prepare dist folder for npm package" - :depends [prod] - :task (do - (fs/delete-tree "dist") - (fs/create-dirs "dist") - (run! (fn [f] (fs/copy f "dist")) - (fs/glob "resources/public/js" "*.js")))} - - bump-version {:doc "Bumps package.json and pushes new git tag" - :task (do (shell "npm version patch") - (shell "git push --atomic origin main" - (str "v" (:version (json/parse-string (slurp "package.json") true)))))} - - npm-publish {:doc "Updates NPM ibrary" - :task (do (run 'dist) - (run 'bump-version) - (shell "npm publish"))} - - replace-version {:doc "Ported from bash one-liners. Expects two versions. - TODO: port to Clojure. - TODO: skip changelog.md - " - :task - (let [[prev next] *command-line-args*] - (-> (process ["bash" "-c" - (format "rg %s --files-with-matches | xargs sed -i '' 's/%s/%s/g'" - prev prev next)] - {:inherit true}) - p/check))} - - gh-pages {:doc "Updates Github pages with new release build." - :task (shell "script/release.clj")}}} diff --git a/deps.edn b/deps.edn deleted file mode 100644 index 58efc55..0000000 --- a/deps.edn +++ /dev/null @@ -1,26 +0,0 @@ -{:paths ["src" "resources"] - - :deps - {org.clojure/clojure {:mvn/version "1.11.1"} - org.babashka/sci {:git/url "https://github.com/babashka/sci" - :git/sha "a85c488ee45700bcbe67bc01ab1c27407fff7887"} - #_{:local/root "../babashka/sci"} - reagent/reagent {:mvn/version "1.1.1"} - re-frame/re-frame {:mvn/version "1.3.0"} - cljsjs/react {:mvn/version "18.2.0-1"} - 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"} - io.github.babashka/sci.nrepl - #_{:local/root "../sci.nrepl"} - {:git/url "https://github.com/babashka/sci.nrepl" - :git/sha "2f8a9ed2d39a1b09d2b4d34d95494b56468f4a23"} - io.github.babashka/sci.configs - #_{:local/root "/Users/borkdude/dev/sci.configs"} - {:git/url "https://github.com/babashka/sci.configs" - :git/sha "bf8d209e4aeabb92cb1be04e3d8f789583d5f449"}} - :aliases - {:dev - {:extra-paths ["dev"] - :extra-deps {thheller/shadow-cljs {:mvn/version "2.20.15"}}}}} diff --git a/doc/dev.md b/doc/dev.md deleted file mode 100644 index 09d3346..0000000 --- a/doc/dev.md +++ /dev/null @@ -1,109 +0,0 @@ -# Dev - -## Workflow - -### Start with an issue before writing code - -Before writing any code, please create an issue first that describes the problem -you are trying to solve with alternatives that you have considered. A little bit -of prior communication can save a lot of time on coding. Keep the problem as -small as possible. If there are two problems, make two issues. We discuss the -issue and if we reach an agreement on the approach, it's time to move on to a -PR. - -### Follow up with a pull request - -Post a corresponding PR with the smallest change possible to address the -issue. Then we discuss the PR, make changes as needed and if we reach an -agreement, the PR will be merged. - - - - - - -### Force-push - -Please do not use `git push --force` on your PR branch for the following -reasons: - -- It makes it more difficult for others to contribute to your branch if needed. -- It makes it harder to review incremental commits. -- Links (in e.g. e-mails and notifications) go stale and you're confronted with: - this code isn't here anymore, when clicking on them. -- CircleCI doesn't play well with it: it might try to fetch a commit which - doesn't exist anymore. -- Your PR will be squashed anyway. - -## Developing - -Run `bb dev` to start shadow-cljs compilation in watch mode. - - - - - -## Release - -Static files including compiled JS are hosted on Github. This is set up like -described -[here](https://medium.com/linagora-engineering/deploying-your-js-app-to-github-pages-the-easy-way-or-not-1ef8c48424b7): - -All the commands below assume that you already have a git project initialized and that you are in its root folder. - -``` -# Create an orphan branch named gh-pages -git checkout --orphan gh-pages -# Remove all files from staging -git rm -rf . -# Create an empty commit so that you will be able to push on the branch next -git commit --allow-empty -m "Init empty branch" -# Push the branch -git push origin gh-pages -``` - -Now that the branch is created and pushed to origin, let’s configure the worktree correctly: - -``` -# Come back to master -git checkout main -# Add gh-pages to .gitignore -echo "gh-pages/" >> .gitignore -git worktree add gh-pages gh-pages -``` - -After cloning this repo to a new dir: - -``` -git fetch origin gh-pages -git worktree prune -git worktree add gh-pages gh-pages -``` - -To deploy to Github Pages: - -``` -script/release.clj -``` - -To create a new NPM release: - -- Prepare version `package.json`, except patch (if anything should change here) -- Run `bb npm-publish`: this will compile, bump patch version, create tag and and push to npm and Github -- `bb replace-version 0.4.11 0.5.14` -- Create Github release with updated links from `doc/links.md` -- `bb gh-pages` - -To upgrade examples: - -``` -rg '0.0.1' --files-with-matches | xargs sed -i '' 's/0.0.5.14.1.0/g' -bb release -cd gh-pages -git checkout -b v0.5.14 -git push --set-upstream origin v0.5.14 -git checkout gh-pages -cd .. -``` - -Then make a new release on Github with the `v0.5.14` tag. diff --git a/doc/links.md b/doc/links.md deleted file mode 100644 index 33575c4..0000000 --- a/doc/links.md +++ /dev/null @@ -1,7 +0,0 @@ -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.cljs-ajax.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.reagent.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.re-frame.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.promesa.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.pprint.js -https://cdn.jsdelivr.net/npm/scittle@0.5.14/dist/scittle.nrepl.js diff --git a/doc/nrepl/README.md b/doc/nrepl/README.md deleted file mode 100644 index 9ff7f08..0000000 --- a/doc/nrepl/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# nREPL - -To connect to a Scittle nREPL server from your editor, follow these steps. The -setup described here, can be found in this directory. - -In babashka or Clojure JVM, use the -[sci.nrepl](https://github.com/babashka/sci.nrepl) dependency and run: - -``` clojure -(require '[sci.nrepl.browser-server :as nrepl]) -(nrepl/start! {:nrepl-port 1339 :websocket-port 1340}) -``` - -This will run an nREPL server on port 1339 and a websocket server on port 1340. -Your editor's nREPL client will connect to port 1339 and your browser, running -scittle, will connect to port 1340. The nREPL server forwards messages to the -browser via the websocket connection. - -In your scittle website, you will need to include the following, in addition to -the normal routine: - -``` html - - -``` - -Also include the CLJS file that you want to evaluate with nREPL: - -``` html - -``` - -Then visit `playground.cljs` in your editor and connect to the nREPL server, -and start evaluating! - -See the `index.html` file for an example. - -When you run `bb dev` in this directory, and then open `http://localhost:1341` -you should be able evaluate expressions in `playground.cljs`. See a demo -[here](https://twitter.com/borkdude/status/1526285565343281159). - -Note that the nREPL server connection stays alive even after the browser window -refreshes. - -### CIDER - -Currently when connecting from CIDER, you need to use this snippet: - -``` elisp -(cider-register-cljs-repl-type 'sci-js "(+ 1 2 3)") - -(defun mm/cider-connected-hook () - (when (eq 'sci-js cider-cljs-repl-type) - (setq-local cider-show-error-buffer nil) - (cider-set-repl-type 'cljs))) - -(add-hook 'cider-connected-hook #'mm/cider-connected-hook) -``` - -Then choose `cider-connect-cljs`, select port `1339`, followed by the `sci-js` -REPL type. diff --git a/doc/nrepl/bb.edn b/doc/nrepl/bb.edn deleted file mode 100644 index e4cf885..0000000 --- a/doc/nrepl/bb.edn +++ /dev/null @@ -1,17 +0,0 @@ -{:deps {io.github.babashka/sci.nrepl - {:git/sha "2f8a9ed2d39a1b09d2b4d34d95494b56468f4a23"} - io.github.babashka/http-server - {:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}} - :tasks {http-server {:doc "Starts http server for serving static files" - :requires ([babashka.http-server :as http]) - :task (do (http/serve {:port 1341 :dir "."}) - (println "Serving static assets at http://localhost:1341"))} - - browser-nrepl {:doc "Start browser nREPL" - :requires ([sci.nrepl.browser-server :as bp]) - :task (bp/start! {})} - - -dev {:depends [http-server browser-nrepl]} - - dev {:task (do (run '-dev {:parallel true}) - (deref (promise)))}}} diff --git a/doc/nrepl/index.html b/doc/nrepl/index.html deleted file mode 100644 index 2c16bd2..0000000 --- a/doc/nrepl/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - -

Scittle

-

What is this?

- - diff --git a/doc/nrepl/playground.cljs b/doc/nrepl/playground.cljs deleted file mode 100644 index cd18550..0000000 --- a/doc/nrepl/playground.cljs +++ /dev/null @@ -1,15 +0,0 @@ -(ns playground) - -(+ 1 2 3) - -(-> - (js/document.getElementsByTagName "body") - first - (.append - (doto (js/document.createElement "p") - (.append - (js/document.createTextNode "there"))))) - -(defn foo []) - -(js/alert "Isn't this cool? :)") diff --git a/resources/public/codemirror.html b/index.html similarity index 97% rename from resources/public/codemirror.html rename to index.html index 12c9f99..1d87832 100644 --- a/resources/public/codemirror.html +++ b/index.html @@ -41,7 +41,7 @@ scittle.core.eval_script_tags(); - +
diff --git a/resources/public/base.html b/resources/public/base.html deleted file mode 100644 index a9aac58..0000000 --- a/resources/public/base.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - -

Scittle

- -
-      
-<head>
-  <script src="https://babashka.github.io/scittle/js/scittle.js" type="application/javascript"></script>
-
-  <script type="application/x-scittle">
-    (defn my-alert []
-      (js/alert "You clicked!"))
-
-    ;; export function to use from JavaScript:
-    (set! (.-my_alert js/window) my-alert)
-  </script>
-
-</head>
-
-<body>
-  <button onclick="my_alert()">
-    Click me!
-  </button>
-</body>
- - - - - diff --git a/resources/public/bookmarklet.html b/resources/public/bookmarklet.html deleted file mode 100644 index 15dce60..0000000 --- a/resources/public/bookmarklet.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - -

Scittle Bookmarklet creator

-

What is Scittle?

-

Read the main page for more details.

-

The bookmarklet editor

-
-

The following source was loaded and interpreted - from cljs/bookmarklet.cljs using the - script tag: -


-<script type="application/x-scittle" src="cljs/bookmarklet.cljs"></script>
-
-
-

-
- - - - - - diff --git a/resources/public/cljs/bookmarklet.cljs b/resources/public/cljs/bookmarklet.cljs deleted file mode 100644 index 69d2169..0000000 --- a/resources/public/cljs/bookmarklet.cljs +++ /dev/null @@ -1,140 +0,0 @@ -(ns bookmarklet - (:require [reagent.core :as r] - [reagent.dom :as rdom])) - -(defn append-tag [tag {:keys [body onload onerror] :as attributes}] - (str "var s=document.createElement('" (name tag) "');" - (clojure.string/join ";" (map (fn [[k v]] (str "s.setAttribute('" (name k) "','" (name v) "')")) (dissoc attributes :body :onload :onerror))) - (when body - (str ";s.innerText=" body)) - (when onload - (str ";s.onload=" onload)) - (when onerror - (str ";s.onerror=" onerror)) - ";document.body.appendChild(s);")) - -(defn pr-code [code-str] - (pr-str (str "#_CODE_" code-str "#_CODE_"))) - -(defn read-code [code-str] - (when-let [raw-code (second (re-find #"#_CODE_(.+)#_CODE_" code-str))] - ;; Use read-string to undo escaping of characters by pr-str (e.g. newlines) - (read-string (str "\"" raw-code "\"")))) - -(defn load-gist [gist callback] - (let [set-content (fn [progress-event] - (callback (.. progress-event -srcElement -responseText))) - oreq (js/XMLHttpRequest.)] - (.addEventListener oreq "load" set-content) - (.open oreq "GET" (str "https://gist.githubusercontent.com/" gist "/raw")) - (.send oreq))) - - -(defn bookmarklet-href [code-str] - (str "javascript:(function(){" - "var runCode = function() { - try { - scittle.core.eval_string(" (pr-code code-str) ") - } catch (error) { - console.log('Error in code', error); - alert('Error running code, see console') - } - };" - "if(typeof scittle === 'undefined'){" - (append-tag :script {:src "https://babashka.github.io/scittle/js/scittle.js" - :onerror "function(){alert('Error loading ' + this.src)}" - :onload "runCode"}) - "} else { - runCode() }" - "})();")) - -(defn query-params [] - (let [query-str (.substring js/window.location.search 1)] - (into {} - (map (fn [pair] - (let [[k v] (.split pair "=" 2)] - [(keyword (js/decodeURIComponent k)) - (js/decodeURIComponent v)]))) - (.split query-str "&")))) - - -(def *initial-name (r/atom nil)) -(def *initial-code (r/atom nil)) - -;; Initialize code -(let [{:keys [gist code name]} (query-params)] - (cond gist - (do - (reset! *initial-name "---") - (reset! *initial-code ";; loading from gist") - (load-gist gist (fn [content] - (let [[code meta-str] (reverse (clojure.string/split content #";;---+\n")) - {bookmark-name :name} (when meta-str - (read-string meta-str))] - (when bookmark-name - (reset! *initial-name bookmark-name)) - (reset! *initial-code code))))) - code - (do - (reset! *initial-name (or name "My first bookmarklet")) - (reset! *initial-code code)) - :else - (do - (reset! *initial-name "My first bookmarklet") - (reset! *initial-code (str "; This is the code of your bookmarklet\n" - (pr-str '(js/alert "Hello"))))))) - -(defn bookmark-name-field [initial-name *bookmark-name] - (let [*name (r/atom initial-name)] - [(fn [] - [:input {:type "text" - :placeholder "The name of the Bookmarklet" - :value @*name - :on-change (fn [e] - (let [v (.. e -target -value)] - (reset! *name v) - (reset! *bookmark-name - (if (clojure.string/blank? v) - (str "Bookmarklet " (rand-int 1000)) - v))))}])])) - -(defn editor [*code] - [:textarea - {:rows 10 :cols 80 - :value @*code - :on-drop (fn [e] - (let [bookmarklet (js/decodeURIComponent (.. e -dataTransfer (getData "text"))) - cljs-snippet (read-code bookmarklet) - new-code (if cljs-snippet - (str "; Extracted snippet\n" cljs-snippet) - (str "; Failed to extract snippet\n" bookmarklet))] - (js/console.log "Dropped" bookmarklet) - (set! (.. e -target -value) new-code) - (reset! *code new-code) - (.preventDefault e))) - :on-change (fn [e] (reset! *code (.. e -target -value)))}]) - - - -(defn workspace [] - (let [value @*initial-code - *code (r/atom value) - bookmark-name @*initial-name - *bookmark-name (r/atom bookmark-name)] - [:div - [bookmark-name-field bookmark-name *bookmark-name] - [:br] - [editor *code] - [:br] - [:br] - "Click the following link or drag it to the bookmarks bar: " - [(fn [] - [(fn [] [:a {:href (bookmarklet-href @*code)} @*bookmark-name])]) - *code] - [:br] - [(fn [] - [:a {:href (str "?name=" (js/encodeURIComponent @*bookmark-name) - "&code=" (js/encodeURIComponent @*code) - "%20")} "Copy this link to share ⤴️"])]])) - -(rdom/render [workspace] (.getElementById js/document "app")) diff --git a/resources/public/cljs/nrepl_playground.cljs b/resources/public/cljs/nrepl_playground.cljs deleted file mode 100644 index 2c71307..0000000 --- a/resources/public/cljs/nrepl_playground.cljs +++ /dev/null @@ -1,15 +0,0 @@ -(ns nrepl-playground) - -(+ 1 2 3) - -(-> - (js/document.getElementsByTagName "body") - first - (.append - (doto (js/document.createElement "p") - (.append - (js/document.createTextNode "there"))))) - -(defn foo []) - -(js/alert "Isn't this cool? :)") diff --git a/resources/public/cljs/script.cljs b/resources/public/cljs/script.cljs deleted file mode 100644 index 27b8b45..0000000 --- a/resources/public/cljs/script.cljs +++ /dev/null @@ -1,2 +0,0 @@ -(defn my-alert2 [] - (js/alert "My alert 2!")) diff --git a/resources/public/cljs/tictactoe.cljs b/resources/public/cljs/tictactoe.cljs deleted file mode 100644 index d348658..0000000 --- a/resources/public/cljs/tictactoe.cljs +++ /dev/null @@ -1,85 +0,0 @@ -(ns tictactoe - "Ported from https://github.com/borkdude/tictactoe-cljs" - (:require [reagent.core :as r] - [reagent.dom :as rdom])) - -(def empty-board [[\- \- \-] - [\- \- \-] - [\- \- \-]]) - -(def state (r/atom {:board empty-board :player \X})) - -(defn get-board-cell - ([board row col] - (get-in board [row col]))) - -(defn get-player [app-state] - (-> app-state :game-state :player)) - -(defn other-player [player] - (if (= player \X) \O \X)) - -(defn winner-in-rows? [board player] - (boolean (some (fn [row] (every? (fn [c] (= c player)) row)) board))) - -(defn transposed-board [board] - (vec (apply map vector board))) - -(defn winner-in-cols? [board player] - (winner-in-rows? (transposed-board board) player)) - -(defn winner-in-diagonals? [board player] - (let [diag-coords [[[0 0] [1 1] [2 2]] - [[0 2] [1 1] [2 0]]]] - (boolean (some (fn [coords] - (every? (fn [coord] - (= player (apply get-board-cell board coord))) - coords)) - diag-coords)))) - -(defn winner? - "checks if there is a winner. when called with no args, checks for player X and player O. -returns the character for the winning player, nil if there is no winner" - ([board] - (boolean (or (winner? board \X) - (winner? board \O)))) - ([board player] - (when (or (winner-in-rows? board player) - (winner-in-cols? board player) - (winner-in-diagonals? board player)) - player))) - -(defn full-board? - [board] - (let [all-cells (apply concat board)] - (not-any? #(= % \-) all-cells))) - -(defn new-state [old-state row col] - (if (and (= (get-board-cell (:board old-state) row col) \-) - (not (winner? (:board old-state)))) - {:board (assoc-in (:board old-state) [row col] (:player old-state)) - :player (other-player (:player old-state))} - old-state)) - -(defn tictactoe [] - [:div - (if (winner? (:board @state)) - (str "The winner is " (other-player (:player @state))) - (if (full-board? (:board @state)) - "It's a draw" - (str "Your turn, player " (:player @state)))) - (let [board (-> @state :board)] - [:table - [:tbody - (map-indexed - (fn [i row] - ^{:key i} - [:tr - (map-indexed (fn [j elt] - ^{:key j} - [:td {:on-click (fn [] - (swap! state new-state i j))}elt]) - row)]) - board)]])]) - -(rdom/render [tictactoe] (.getElementById js/document "app")) diff --git a/resources/public/css/style.css b/resources/public/css/style.css deleted file mode 100644 index 55ef6c5..0000000 --- a/resources/public/css/style.css +++ /dev/null @@ -1,22 +0,0 @@ -div#app -{ - color:#666; - font-family: Arial; -} - -div#app td -{ - width:50px; - height:50px; - border:1px solid #dedede; - background:#fff; - margin:1px; - color:#666; - text-align: center; - line-height: 50px; -} - -div#app td:hover -{ - cursor:pointer; -} diff --git a/resources/public/disable_auto_eval.html b/resources/public/disable_auto_eval.html deleted file mode 100644 index 34ed838..0000000 --- a/resources/public/disable_auto_eval.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - -

Scittle

-

On this page, auto-eval is disabled.

-

-

- - diff --git a/resources/public/html/cljs-ajax.html b/resources/public/html/cljs-ajax.html deleted file mode 100644 index d98a513..0000000 --- a/resources/public/html/cljs-ajax.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - diff --git a/resources/public/html/export.html b/resources/public/html/export.html deleted file mode 100644 index 05c5bb3..0000000 --- a/resources/public/html/export.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - diff --git a/resources/public/html/local.html b/resources/public/html/local.html deleted file mode 100644 index 603a5bc..0000000 --- a/resources/public/html/local.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - -
- - diff --git a/resources/public/html/reagent.html b/resources/public/html/reagent.html deleted file mode 100644 index bede495..0000000 --- a/resources/public/html/reagent.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - -
- - diff --git a/resources/public/index.html b/resources/public/index.html deleted file mode 100644 index 6e08a9a..0000000 --- a/resources/public/index.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -
-
- -

Scittle

-

What is this?

-

This project exposes the Small Clojure Interpreter in the - browser in such a way that you can use it with the script tag.

- - -

Usage

- - To embed scittle in your website, it is recommended to use the links - published to - the releases - page. - - Include scittle.js and write a script tag - where type is set - to application/x-scittle. - -
- - - -

Source from file

- - When you have a file on your server, say cljs/script.cljs, you can load it using the src attribute: - -

-        <script src="cljs/script.cljs" type="application/x-scittle"></script>
-    
- - - - -

Reagent plugin

- - To enable reagent, - in addition to scittle.js, you need to include React - and scittle.reagent.js: - -
- -
- - - -

Re-frame plugin

- - To enable re-frame, - in addition to the files needed for reagent, you need to include scittle.re-frame.js. - Also see the codemirror playground. - - -

Cljs-ajax plugin

- - To enable cljs-ajax, - in addition to scittle.js, you need to include scittle.cljs-ajax.js: - -
- - - - -

cljs.pprint plugin

To - enable cljs.pprint, in - addition to scittle.js, you need to - include scittle.pprint.js. - - -

REPL

- - To connect to a REPL with Scittle, - see README.md - - -

Examples

- - - - diff --git a/resources/public/nrepl.html b/resources/public/nrepl.html deleted file mode 100644 index f7e903d..0000000 --- a/resources/public/nrepl.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - -

Scittle

-

What is this?

- - diff --git a/resources/public/tictactoe.html b/resources/public/tictactoe.html deleted file mode 100644 index 5b62e74..0000000 --- a/resources/public/tictactoe.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - -

Scittle tic-tac-toe

-

What is Scittle?

-

Read the main page for more details.

-

The game

-
-

The following source was loaded and interpreted - from cljs/tictactoe.cljs using the - script tag: -


-<script type="application/x-scittle" src="cljs/tictactoe.cljs"></script>
-
-
-

-
- - - diff --git a/resources/public/wordle.html b/resources/public/wordle.html deleted file mode 100644 index 935570c..0000000 --- a/resources/public/wordle.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - Wordle! - - - - - - - - -

Wordle by @oxalorg. - Play the game by typing letters and then hit return. The source code is loaded from here. -

-
- - diff --git a/script/release.clj b/script/release.clj deleted file mode 100755 index 5293fa9..0000000 --- a/script/release.clj +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bb - -(require '[babashka.fs :as fs] - '[babashka.tasks :refer [shell]]) - -(fs/copy "resources/public/index.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/base.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/tictactoe.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/bookmarklet.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/wordle.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/disable_auto_eval.html" "gh-pages" - {:replace-existing true}) - -(fs/copy "resources/public/codemirror.html" "gh-pages" - {:replace-existing true}) - -(def html-source-dir (fs/file "resources" "public" "html")) -(def html-target-dir (fs/file "gh-pages" "html")) -(fs/create-dirs html-target-dir) -(doseq [html ["export.html" "reagent.html" "cljs-ajax.html"]] - (fs/copy (fs/file html-source-dir html) html-target-dir - {:replace-existing true})) - -(def style-source-dir (fs/file "resources" "public" "css")) -(def style-target-dir (fs/file "gh-pages" "css")) -(fs/create-dirs style-target-dir) -(fs/copy "resources/public/css/style.css" style-target-dir - {:replace-existing true}) - -(def js-source-dir (fs/file "resources" "public" "js")) -(def js-target-dir (fs/file "gh-pages" "js")) -(fs/create-dirs js-target-dir) - -(println "Compiling CLJS") -(shell "bb prod") - -(fs/copy "resources/public/js/report.html" "gh-pages" - {:replace-existing true}) - -(def index-file (fs/file "gh-pages" "index.html")) - -(def cljs-source-dir (fs/file "resources" "public" "cljs")) -(def cljs-target-dir (fs/file "gh-pages" "cljs")) -(fs/create-dirs cljs-target-dir) - -(run! (fn [f] - (println "Copying" (str f)) - (fs/copy f - cljs-target-dir - {:replace-existing true})) - (fs/glob cljs-source-dir "*.cljs")) - -(run! (fn [f] - (println "Copying" (str f)) - (fs/copy f - js-target-dir - {:replace-existing true})) - (fs/glob js-source-dir "scittle*.js")) - -(def with-gh-pages (partial shell {:dir "gh-pages"})) -(with-gh-pages "git add .") -(with-gh-pages "git commit -m 'update build'") -(with-gh-pages "git push origin gh-pages") - -nil diff --git a/script/release.old b/script/release.old deleted file mode 100644 index bcc1cff..0000000 --- a/script/release.old +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -clojure -M:dev -m shadow.cljs.devtools.cli release main -cp resources/public/index.html gh-pages -sed -i 's/main.js/sci_script_tag.js/' gh-pages/index.html - -mkdir -p gh-pages/js -cp resources/public/js/main.js gh-pages/js/sci_script_tag.js - -cd gh-pages -git add . -git commit -m "update build" -git push origin gh-pages diff --git a/shadow-cljs.edn b/shadow-cljs.edn deleted file mode 100644 index 47e5deb..0000000 --- a/shadow-cljs.edn +++ /dev/null @@ -1,32 +0,0 @@ -{:deps - {:aliases [:dev]} - - :dev-http - {8000 "classpath:public"} - - :builds - {:main - {:target :browser - :js-options - {:resolve {"react" {:target :global - :global "React"} - "react-dom" {:target :global - :global "ReactDOM"}}} - :modules - {:scittle {:entries [scittle.core]} - :scittle.nrepl {:entries [scittle.nrepl] - :depends-on #{:scittle}} - :scittle.promesa {:entries [scittle.promesa] - :depends-on #{:scittle}} - :scittle.pprint {:entries [scittle.pprint] - :depends-on #{:scittle}} - :scittle.reagent {:entries [scittle.reagent] - :depends-on #{:scittle}} - :scittle.re-frame {:entries [scittle.re-frame] - :depends-on #{:scittle.reagent - :scittle}} - :scittle.cljs-ajax {:entries [scittle.cljs-ajax] - :depends-on #{:scittle}}} - :build-hooks [(shadow.cljs.build-report/hook)] - :output-dir "resources/public/js" - :devtools {:repl-pprint true}}}} diff --git a/resources/public/cljs/codemirror.cljs b/src/codemirror.cljs similarity index 100% rename from resources/public/cljs/codemirror.cljs rename to src/codemirror.cljs diff --git a/src/scittle/cljs_ajax.cljs b/src/scittle/cljs_ajax.cljs deleted file mode 100644 index 8d1df17..0000000 --- a/src/scittle/cljs_ajax.cljs +++ /dev/null @@ -1,13 +0,0 @@ -(ns scittle.cljs-ajax - (:require [ajax.core] - [sci.core :as sci] - [scittle.core :as scittle])) - -(def ans (sci/create-ns 'ajax.core nil)) - -(def ajax-namespace - (sci/copy-ns ajax.core ans)) - -(scittle/register-plugin! - ::ajax - {:namespaces {'ajax.core ajax-namespace}}) diff --git a/src/scittle/core.cljs b/src/scittle/core.cljs deleted file mode 100644 index 4e06389..0000000 --- a/src/scittle/core.cljs +++ /dev/null @@ -1,107 +0,0 @@ -(ns scittle.core - (:refer-clojure :exclude [time]) - (:require [cljs.reader :refer [read-string]] - [goog.object :as gobject] - [goog.string] - [sci.core :as sci] - [sci.impl.unrestrict] - [scittle.impl.common :refer [cljns]] - [scittle.impl.error :as error])) - -(set! sci.impl.unrestrict/*unrestricted* true) - -(clojure.core/defmacro time - "Evaluates expr and prints the time it took. Returns the value of expr." - [expr] - `(let [start# (cljs.core/system-time) - ret# ~expr] - (prn (cljs.core/str "Elapsed time: " - (.toFixed (- (system-time) start#) 6) - " msecs")) - ret#)) - -(def stns (sci/create-ns 'sci.script-tag nil)) -(def rns (sci/create-ns 'cljs.reader nil)) - -(def namespaces - {'clojure.core - {'time (sci/copy-var time cljns) - 'system-time (sci/copy-var system-time cljns) - 'random-uuid random-uuid - 'read-string (sci/copy-var read-string rns)} - 'goog.object {'set gobject/set - 'get gobject/get} - '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}}))) - -(def !last-ns (volatile! @sci/ns)) - -(defn- -eval-string [s] - (sci/binding [sci/ns @!last-ns] - (let [rdr (sci/reader s)] - (loop [res nil] - (let [form (sci/parse-next @!sci-ctx rdr)] - (if (= :sci.core/eof form) - (do - (vreset! !last-ns @sci/ns) - res) - (recur (sci/eval-form @!sci-ctx form)))))))) - -(defn ^:export eval-string [s] - (try (-eval-string s) - (catch :default e - (error/error-handler e (:src @!sci-ctx)) - (throw e)))) - -(defn register-plugin! [_plug-in-name sci-opts] - (swap! !sci-ctx sci/merge-opts sci-opts)) - -(defn- eval-script-tags* [script-tags] - (when-let [tag (first script-tags)] - (if-let [text (not-empty (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) - (sci/binding [sci/file scittle-id] - (eval-string text)) - (eval-script-tags* (rest script-tags))) - (let [src (.getAttribute tag "src") - req (js/XMLHttpRequest.) - _ (.open req "GET" src true) - _ (gobject/set req "onload" - (fn [] (this-as this - (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) - (sci/binding [sci/file src] - (eval-string response))) - (eval-script-tags* (rest script-tags)))))] - (.send req))))) - -(defn ^:export eval-script-tags [] - (let [script-tags (js/document.querySelectorAll "script[type='application/x-scittle']")] - (eval-script-tags* script-tags))) - -(def auto-load-disabled? (volatile! false)) - -(defn ^:export disable-auto-eval - "By default, scittle evaluates script nodes on the DOMContentLoaded - event using the eval-script-tags function. This function disables - that behavior." - [] - (vreset! auto-load-disabled? true)) - -(js/document.addEventListener - "DOMContentLoaded" - (fn [] (when-not @auto-load-disabled? (eval-script-tags))), false) - -(enable-console-print!) -(sci/alter-var-root sci/print-fn (constantly *print-fn*)) diff --git a/src/scittle/impl/common.cljs b/src/scittle/impl/common.cljs deleted file mode 100644 index a3bbd7e..0000000 --- a/src/scittle/impl/common.cljs +++ /dev/null @@ -1,4 +0,0 @@ -(ns scittle.impl.common - (:require [sci.core :as sci])) - -(def cljns (sci/create-ns 'clojure.core nil)) diff --git a/src/scittle/impl/error.cljs b/src/scittle/impl/error.cljs deleted file mode 100644 index b5edb4e..0000000 --- a/src/scittle/impl/error.cljs +++ /dev/null @@ -1,92 +0,0 @@ -(ns scittle.impl.error - (:refer-clojure :exclude [println]) - (:require [clojure.string :as str] - [sci.core :as sci])) - -(defn println [& strs] - (.error js/console (str/join " " strs))) - -(defn ruler [title] - (println (apply str "----- " title " " (repeat (- 50 7 (count title)) \-)))) - -(defn split-stacktrace [stacktrace verbose?] - (if verbose? [stacktrace] - (let [stack-count (count stacktrace)] - (if (<= stack-count 10) - [stacktrace] - [(take 5 stacktrace) - (drop (- stack-count 5) stacktrace)])))) - -(defn print-stacktrace - [stacktrace {:keys [:verbose?]}] - (let [stacktrace (sci/format-stacktrace stacktrace) - segments (split-stacktrace stacktrace verbose?) - [fst snd] segments] - (run! #(print % "\n") fst) - (when snd - (print "...\n") - (run! #(print % "\n") snd)))) - -(defn error-context [ex src-map] - (let [{:keys [:file :line :column]} (ex-data ex)] - (when (and file line) - (when-let [content (get src-map file)] - (let [matching-line (dec line) - start-line (max (- matching-line 4) 0) - end-line (+ matching-line 6) - [before after] (->> - (str/split-lines content) - (map-indexed list) - (drop start-line) - (take (- end-line start-line)) - (split-at (inc (- matching-line start-line)))) - snippet-lines (concat before - [[nil (str (str/join "" (repeat (dec column) " ")) - (str "^--- " (ex-message ex)))]] - after) - indices (map first snippet-lines) - max-size (reduce max 0 (map (comp count str) indices)) - snippet-lines (map (fn [[idx line]] - (if idx - (let [line-number (inc idx)] - (str (.padStart (str line-number) max-size "0") " " line)) - (str (str/join (repeat (+ 2 max-size) " ")) line))) - snippet-lines)] - (str "\n" (str/join "\n" snippet-lines))))))) - -(defn right-pad [s n] - (let [n (- n (count s))] - (str s (str/join (repeat n " "))))) - -(defn error-handler [e src-map] - (let [d (ex-data e) - sci-error? (isa? (:type d) :sci/error) - stacktrace (sci/stacktrace e)] - (ruler "Scittle error") - (when-let [name (.-name e)] - (when-not (= "Error" name) - (println "Type: " name))) - (when-let [m (.-message e)] - (println (str "Message: " m))) - (when-let [d (ex-data (ex-cause e) #_(.getCause e))] - (println (str "Data: ") - (pr-str d))) - (let [{:keys [:file :line :column]} d] - (when line - (println (str "Location: " - (when file (str file ":")) - line ":" column"")))) - (when-let [phase (:phase d)] - (println "Phase: " phase)) - (when-let [ec (when sci-error? - (error-context e src-map))] - (ruler "Context") - (println ec)) - (when sci-error? - (when-let - [st (let [st (with-out-str - (when stacktrace - (print-stacktrace stacktrace src-map)))] - (when-not (str/blank? st) st))] - (ruler "Stack trace") - (println st))))) diff --git a/src/scittle/nrepl.cljs b/src/scittle/nrepl.cljs deleted file mode 100644 index d96ed6b..0000000 --- a/src/scittle/nrepl.cljs +++ /dev/null @@ -1,86 +0,0 @@ -(ns scittle.nrepl - (:require - [clojure.edn :as edn] - [sci.nrepl.completions :refer [completions]] - [sci.nrepl.info :refer [info]] - [scittle.core :refer [!last-ns eval-string !sci-ctx]])) - -(defn nrepl-websocket [] - (.-ws_nrepl js/window)) - -(defn nrepl-reply [{:keys [id session]} {:keys [ns] :as payload}] - (.send (nrepl-websocket) - (str - (let [ns (or ns (str @!last-ns))] - (assoc payload :id id :session session :ns ns))))) - -(defn handle-nrepl-eval [{:keys [code] :as msg}] - (let [[kind val] (try [::success (eval-string code)] - (catch :default e - [::error (str e)]))] - (case kind - ::success - (do (nrepl-reply msg {:value (pr-str val)}) - (nrepl-reply msg {:status ["done"]})) - ::error - (do - (nrepl-reply msg {:err (pr-str val)}) - (nrepl-reply msg {:ex (pr-str val) - :status ["error" "done"]}))))) - -(defn handle-nrepl-info [msg] - (let [info (info (assoc msg :ctx @!sci-ctx))] - (nrepl-reply msg info))) - -(declare ops) - -(defn - handle-describe - [msg] - (nrepl-reply - msg - {:versions {"scittle-nrepl" {"major" "0" - "minor" "0" - "incremental" "1"}} - :ops (zipmap - (map - name - (concat - (keys ops) - ;; sci.nrepl browser_server.clj handles: - #{:clone :load-file} - ;; we are lying about close? - #{"close"})) - (repeat {})) - :status ["done"]})) - -(def ops - "Operations supported by the nrepl server." - {:eval handle-nrepl-eval - :info handle-nrepl-info - :eldoc handle-nrepl-info - :lookup handle-nrepl-info - :describe handle-describe - :complete (fn [msg] (let [completions (completions (assoc msg :ctx @!sci-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)))) - -(defn ws-url [host port path] - (str "ws://" host ":" port "/" path)) - -(when-let [ws-port (.-SCITTLE_NREPL_WEBSOCKET_PORT js/window)] - (set! (.-ws_nrepl js/window) - (new js/WebSocket (ws-url (.-hostname (.-location js/window)) ws-port "_nrepl")))) - -(when-let [ws (nrepl-websocket)] - (prn :ws ws) - (set! (.-onmessage ws) - (fn [event] - (handle-nrepl-message (edn/read-string (.-data event))))) - (set! (.-onerror ws) - (fn [event] - (js/console.log event)))) diff --git a/src/scittle/pprint.cljs b/src/scittle/pprint.cljs deleted file mode 100644 index c4d1209..0000000 --- a/src/scittle/pprint.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns scittle.pprint - (:require - [sci.configs.cljs.pprint :refer [config]] - [scittle.core :as scittle])) - -(scittle/register-plugin! - ::pprint - config) diff --git a/src/scittle/promesa.cljs b/src/scittle/promesa.cljs deleted file mode 100644 index 73c6325..0000000 --- a/src/scittle/promesa.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns scittle.promesa - (:require - [sci.configs.funcool.promesa :as p] - [scittle.core :as scittle])) - -(scittle/register-plugin! - ::promesa - p/config) diff --git a/src/scittle/re_frame.cljs b/src/scittle/re_frame.cljs deleted file mode 100644 index 39e219e..0000000 --- a/src/scittle/re_frame.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns scittle.re-frame - (:require - [sci.configs.re-frame.re-frame :as rf] - [scittle.core :as scittle])) - -(scittle/register-plugin! - ::re-frame - rf/config) diff --git a/src/scittle/reagent.cljs b/src/scittle/reagent.cljs deleted file mode 100644 index 6354ef7..0000000 --- a/src/scittle/reagent.cljs +++ /dev/null @@ -1,19 +0,0 @@ -(ns scittle.reagent - (:require - [reagent.dom :as rdom] - [sci.configs.reagent.reagent :refer [reagent-debug-namespace - reagent-namespace reagent-ratom-namespace]] - [sci.core :as sci] - [scittle.core :as scittle])) - -(def rdns (sci/create-ns 'reagent.dom nil)) - -(def reagent-dom-namespace - {'render (sci/copy-var rdom/render rdns)}) - -(scittle/register-plugin! - ::reagent - {:namespaces {'reagent.core reagent-namespace - 'reagent.dom reagent-dom-namespace - 'reagent.ratom reagent-ratom-namespace - 'reagent.debug reagent-debug-namespace}}) diff --git a/resources/public/test/codemirror.html b/test/codemirror.html similarity index 100% rename from resources/public/test/codemirror.html rename to test/codemirror.html