Permalink
Browse files

Adds the quote special form, allows inserting raw javascript strings.

  • Loading branch information...
arohner committed Nov 9, 2010
1 parent 798ccaa commit d038f5946c87c7bc8580e3b97e9d36f21f9c82d8
Showing with 9 additions and 2 deletions.
  1. +1 −1 project.clj
  2. +4 −1 src/com/reasonr/scriptjure.clj
  3. +4 −0 test/test_scriptjure.clj
View
@@ -1,4 +1,4 @@
-(defproject scriptjure "0.1.19"
+(defproject scriptjure "0.1.20"
:description "a clojure DSL for generating javascript"
:url "http://github.com/arohner/scriptjure"
:dependencies [[org.clojure/clojure "1.2.0"]
@@ -78,7 +78,7 @@
(defmethod emit :default [expr]
(str expr))
-(def special-forms (set ['var '. '.. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do 'aget 'while 'doseq 'str 'inc! 'dec! 'dec 'inc 'defined? 'and 'or '?]))
+(def special-forms (set ['var '. '.. 'if 'funcall 'fn 'quote 'set! 'return 'delete 'new 'do 'aget 'while 'doseq 'str 'inc! 'dec! 'dec 'inc 'defined? 'and 'or '?]))
(def prefix-unary-operators (set ['!]))
@@ -199,6 +199,9 @@
(defmethod emit-special 'or [type [_ & more]]
(apply str (interpose "||" (map emit more))))
+(defmethod emit-special 'quote [type [_ & more]]
+ (apply str more))
+
(defn emit-do [exprs]
(str/join "" (map (comp statement emit) exprs)))
View
@@ -111,6 +111,10 @@
(is (= (strip-whitespace (js (doseq [i [1 2 3] j [4 5]] (foo i j))))
"for (i in [1, 2, 3]) { for (j in [4, 5]) { foo(i, j); } }")))
+(deftest test-quote
+ (is (= (strip-whitespace (js (do (+ 1 1) (quote "alert()"))))
+ "(1 + 1); alert();")))
+
(deftest test-combine-forms
(let [stuff (js* (do
(var x 3)

0 comments on commit d038f59

Please sign in to comment.