cljs.pprint (#39)

This commit is contained in:
Michiel Borkent 2022-08-31 13:45:37 +02:00 committed by GitHub
parent 7bf5bc087d
commit cf65ffaf20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 11 deletions

3
bb.edn
View file

@ -15,7 +15,8 @@
(fs/delete-tree ".shadow-cljs"))}
shadow:watch {:doc "Development build. Starts webserver and watches for changes."
:task (clojure "-M:dev -m shadow.cljs.devtools.cli watch main")}
: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])

View file

@ -2,7 +2,9 @@
:deps
{org.clojure/clojure {:mvn/version "1.10.3"}
org.babashka/sci {:mvn/version "0.3.5"}
org.babashka/sci {:git/url "https://github.com/babashka/sci"
:git/sha "133a7565749ac6cd5a8308182f0b1c7fc47e8a3d"}
#_{:local/root "../babashka/sci"}
reagent/reagent {:mvn/version "1.1.0"}
cljsjs/react {:mvn/version "17.0.2-0"}
cljsjs/react-dom {:mvn/version "17.0.2-0"}
@ -14,7 +16,7 @@
#_{:local/root "../sci.nrepl"}
{:git/sha "e83421ce9349c36df56a2eb936196dbb65b0de63"}
io.github.babashka/sci.configs
{:git/sha "fcd367c6a6115c5c4e41f3a08ee5a8d5b3387a18"}}
{:git/sha "63225c8606d593c595d2f10a6fa5bf38103852df"}}
:aliases
{:dev

View file

@ -7,6 +7,8 @@
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="js/scittle.reagent.js" type="application/javascript"></script>
<script src="js/scittle.cljs-ajax.js" type="application/javascript"></script>
<script src="js/scittle.pprint.js" type="application/javascript"></script>
<script type="application/x-scittle">
(defn my-alert []
(js/alert "You clicked!"))
@ -118,6 +120,19 @@
Click me!
</button>
<a name="pprint"></a>
<h2><a href="#pprint">cljs.pprint plugin</a></h2>
To enable <a href="https://cljs.github.io/api/cljs.pprint/">cljs-ajax</a>,
in addition to <tt>scittle.js</tt>, you need to include <tt>scittle.pprint.js</tt>:
<pre><code data-type="scittle" data-src="html/cljs-ajax.html" class="html"></code></pre>
<button onclick="make_request()">
Click me!
</button>
<a name="repl"></a>
<h2><a href="#nrepl">REPL</a></h2>

View file

@ -18,6 +18,8 @@
: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.cljs-ajax {:entries [scittle.cljs-ajax]

View file

@ -4,9 +4,12 @@
[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]
@ -29,11 +32,12 @@
'goog.object {'set gobject/set
'get gobject/get}})
(def !sci-ctx (atom (sci/init {:namespaces namespaces
:classes {'js js/window
:allow :all}
:disable-arity-checks true})))
(def !sci-ctx
(atom (sci/init {:namespaces namespaces
:classes {'js js/window
:allow :all
'Math js/Math}
:ns-aliases {'clojure.pprint 'cljs.pprint}})))
(def !last-ns (volatile! @sci/ns))
@ -103,4 +107,3 @@
(enable-console-print!)
(sci/alter-var-root sci/print-fn (constantly *print-fn*))

8
src/scittle/pprint.cljs Normal file
View file

@ -0,0 +1,8 @@
(ns scittle.pprint
(:require
[sci.configs.cljs.pprint :refer [config]]
[scittle.core :as scittle]))
(scittle/register-plugin!
::promesa
config)

View file

@ -1,6 +1,7 @@
(ns scittle.promesa
(:require [scittle.core :as scittle]
[sci.configs.funcool.promesa :as p]))
(:require
[sci.configs.funcool.promesa :as p]
[scittle.core :as scittle]))
(scittle/register-plugin!
::promesa