add plugin with macro
This commit is contained in:
parent
0c0d5afacd
commit
11dd0a1d15
3 changed files with 41 additions and 1 deletions
|
|
@ -15,7 +15,9 @@
|
|||
:modules
|
||||
{:scittle {:entries [scittle.core]}
|
||||
:scittle.reagent {:entries [scittle.reagent]
|
||||
:depends-on #{:scittle}}}
|
||||
:depends-on #{:scittle}}
|
||||
:scittle.makro-plugin {:entries [scittle.makro-plugin]
|
||||
:depends-on #{:scittle}}}
|
||||
:build-hooks [(shadow.cljs.build-report/hook)]
|
||||
:output-dir "resources/public/js"
|
||||
:devtools {:repl-pprint true}}}}
|
||||
|
|
|
|||
17
src/scittle/makro_plugin.cljs
Normal file
17
src/scittle/makro_plugin.cljs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(ns scittle.makro-plugin
|
||||
(:require
|
||||
[sci.core :as sci]
|
||||
[scittle.core :as scittle]))
|
||||
|
||||
(defn add-low-fn [_env _form x y & zs] `(str "__" ~x ~y ~zs))
|
||||
(def add-low-makro (with-meta add-low-fn {:sci/macro true}))
|
||||
|
||||
(def rns (sci/create-ns 'makro-plugin.core nil))
|
||||
|
||||
(def makro-plugin-namespace
|
||||
{'add-low-fn (sci/copy-var add-low-fn rns)
|
||||
'add-low-makro (sci/copy-var add-low-makro rns)})
|
||||
|
||||
(scittle/register-plugin!
|
||||
::makro-plugin
|
||||
{:namespaces {'makro-plugin.core makro-plugin-namespace}})
|
||||
21
test.html
Normal file
21
test.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="./resources/public/js/scittle.js"></script>
|
||||
<script src="./resources/public/js/scittle.makro-plugin.js"></script>
|
||||
<script type="application/x-scittle">
|
||||
(require '[makro-plugin.core :as m])
|
||||
(defn my-alert []
|
||||
(.log js/console (m/add-low-fn 1 2 3 4 5 6))
|
||||
;; shows as expected in console: ["cljs.core/str", "__", 3, 4, [5, 6]]
|
||||
(.log js/console (m/add-low-makro 1 2 3 4 5 6)))
|
||||
;; shows unexpectedly the same ["cljs.core/str", "__", 3, 4, [5, 6]]
|
||||
;; instead of "__34[56]"
|
||||
(set! (.-my_alert js/window) my-alert)
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="my_alert()">
|
||||
Click me!
|
||||
</button>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue