Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add in defjsmacro

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
commit 2eae9600dfd701702d7cb19621ce2e75c6cf1c76 1 parent 634e038
@ibdknox ibdknox authored
Showing with 17 additions and 10 deletions.
  1. +12 −4 src/com/reasonr/scriptjure.clj
  2. +5 −6 test/test_scriptjure.clj
View
16 src/com/reasonr/scriptjure.clj
@@ -345,18 +345,26 @@
;; Custom forms
;;**********************************************************
+(defonce custom-forms (atom {}))
+
+(defmacro defjsmacro [nme params & body]
+ `(do
+ (defn ~nme ~params
+ (js*
+ ~@body))
+ (add-custom-form '~nme ~nme)))
+
(defn add-custom-form [form func]
(swap! custom-forms assoc form func))
(defn get-custom [form]
(get @custom-forms form))
+(defn custom-form? [expr]
+ (get-custom expr))
+
(defn emit-custom [head expr]
(when-let [func (get-custom head)]
(let [v (apply func (next expr))]
(emit v))))
-(defonce custom-forms (atom {}))
-
-(defn custom-form? [expr]
- (get @custom-forms expr))
View
11 test/test_scriptjure.clj
@@ -8,9 +8,6 @@
[str]
(str/trim (str/replace (str/replace str #"\n" " ") #"[ ]+" " ")))
-(defn prn-hw [n z]
- (js* (alert (str "hello world " (clj n)))))
-
(deftest number-literal
(is (= (js 42) "42"))
(is (= (js 1/2) "0.5")))
@@ -169,11 +166,13 @@
(is (= (strip-whitespace(js (set! x 1 y 2)))
"x = 1; y = 2;")))
+(defjsmacro prn-hw [n]
+ (alert (str "hello world " (clj n))))
+
(deftest custom-form-add
- (add-custom-form 'prn-hw prn-hw))
- (is (contains? @custom-forms 'prn-hw))
+ (is (get-custom 'prn-hw)))
(deftest custom-form-use
- (is (= (js (prn-hw "chris"))) "alert(\"hello world chris\")"))
+ (is (= (js (prn-hw "custom"))) "alert(\"hello world custom\")"))
(run-tests)
Please sign in to comment.
Something went wrong with that request. Please try again.