Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Scriptjure is licensed under the EPL, the same as Clojure core. See epl-v10.html in the root directory for more information.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"]])
:dependencies [[org.clojure/clojure "1.2.0"]])
2 changes: 1 addition & 1 deletion test/test_scriptjure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)