From a43e50fde54539f9aaff6df86302cd035e4b8cbb Mon Sep 17 00:00:00 2001 From: Chris Granger Date: Mon, 13 Jun 2011 03:03:01 -0700 Subject: [PATCH 1/3] fixed invalid test due to paren misplacement Signed-off-by: Chris Granger --- project.clj | 4 ++-- test/test_scriptjure.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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) From 6970cf38adea7be0187feb39a33cf334860c5552 Mon Sep 17 00:00:00 2001 From: Chris Granger Date: Mon, 13 Jun 2011 03:11:21 -0700 Subject: [PATCH 2/3] add JS macros to the readme Signed-off-by: Chris Granger --- README.markdown | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index d16f9a2..fafe4d7 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. From 86130f150714ca016bc4215d8c282e1e031e4037 Mon Sep 17 00:00:00 2001 From: Chris Granger Date: Mon, 13 Jun 2011 03:12:09 -0700 Subject: [PATCH 3/3] final readme fix Signed-off-by: Chris Granger --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index fafe4d7..8bc76c6 100644 --- a/README.markdown +++ b/README.markdown @@ -212,7 +212,7 @@ You can create custom JS Macros using `scriptjure/defjsmacro`: (js (on-ready (alert "hello"))) => "$(document).ready(function() { - alert("hello"); + alert(\"hello\"); })" ``` Any time you want to evaluate a clojure variable in your macro, simply wrap it in a `(clj)` call: