diff --git a/README.markdown b/README.markdown index d16f9a2..8bc76c6 100644 --- a/README.markdown +++ b/README.markdown @@ -201,6 +201,31 @@ If you want to pass a js form from one clojure function to another, use js* `cljs` and `cljs*` are shortcuts for `(js (clj ...))` and `(js* (clj ..))` respectively. Note that both only take one form. +JS Macros +======= +You can create custom JS Macros using `scriptjure/defjsmacro`: + +```clojure +(defjsmacro on-ready [& body] + (.ready ($ document) (clj (list* (concat '(fn []) body))))) + +(js (on-ready (alert "hello"))) + +=> "$(document).ready(function() { + alert(\"hello\"); + })" +``` +Any time you want to evaluate a clojure variable in your macro, simply wrap it in a `(clj)` call: + +```clojure +(defjsmacro custom-alert [person] + (alert (str "hello " (clj person)))) + +(js (custom-alert "Joe")) + +=> "alert(\"hello \" + \"Joe\")" +``` + License ======= -Scriptjure is licensed under the EPL, the same as Clojure core. See epl-v10.html in the root directory for more information. \ No newline at end of file +Scriptjure is licensed under the EPL, the same as Clojure core. See epl-v10.html in the root directory for more information. diff --git a/project.clj b/project.clj index 79c7c57..ef4db2f 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject scriptjure "0.1.22" +(defproject com.ibdknox.scriptjure/scriptjure "0.1.23" :description "a clojure DSL for generating javascript" :url "http://github.com/arohner/scriptjure" - :dependencies [[org.clojure/clojure "1.2.0"]]) \ No newline at end of file + :dependencies [[org.clojure/clojure "1.2.0"]]) diff --git a/test/test_scriptjure.clj b/test/test_scriptjure.clj index 591209f..2ee0cab 100644 --- a/test/test_scriptjure.clj +++ b/test/test_scriptjure.clj @@ -173,6 +173,6 @@ (is (get-custom 'prn-hw))) (deftest custom-form-use - (is (= (js (prn-hw "custom"))) "alert(\"hello world custom\")")) + (is (= (js (prn-hw "custom")) "alert(\"hello world \" + \"custom\")"))) (run-tests)