From 82f84222de93a999167cf99774fe8404b6513817 Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Wed, 28 Aug 2013 19:05:12 +0000 Subject: [PATCH] Added maps as form of arguments for the build macro. --- project.clj | 7 +++++-- src/clojurefx/core.clj | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index 67be34d..6ecca41 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,9 @@ (defproject clojurefx "0.1.0-SNAPSHOT" - :description "Helper functions and probably a wrapper to simplify usage of JavaFX in Clojure.
-You'll need to have jfxrt.jar in your local maven repository. See [this coderwall protip](https://coderwall.com/p/4yjy1a) for how to make this happen." + :description "Helper functions and probably a wrapper to simplify usage of JavaFX in Clojure. + +You'll need to have jfxrt.jar in your local maven repository. See [this coderwall protip](https://coderwall.com/p/4yjy1a) for how to make this happen. + +**This is not yet on clojars, but it will be there soon. Until then, clone it and install locally.**" :url "https://www.github.com/zilti/clojurefx" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} diff --git a/src/clojurefx/core.clj b/src/clojurefx/core.clj index b1013bd..e2d6cd5 100644 --- a/src/clojurefx/core.clj +++ b/src/clojurefx/core.clj @@ -90,11 +90,21 @@ Don't use this yourself; See the macros \"build\" and \"deffx\" below. (symbol (str k "." (camel (name builder)))))))))) (defmacro build - "This helper macro makes it easier to use the [JavaFX builder classes](http://docs.oracle.com/javafx/2/api/javafx/util/Builder.html). Example: (build button (text \"Close me.\") (cancelButton true))." + "This helper macro makes it easier to use the [JavaFX builder classes](http://docs.oracle.com/javafx/2/api/javafx/util/Builder.html). You can also use a map, so it is possible to compose the arguments for the builder over time. + +**Examples:** + + * `(build button (text \"Close me.\") (cancelButton true))` + * `(build button {:text \"Close me.\" :cancelButton true})`" [what & args] - `(.. ~(get-qualified what) create - ~@args - build)) + (if (and (= 1 (count args)) + (map? (first args))) + `(build ~what ~@(for [entry# (keys (first args))] + `(~(symbol (name entry#)) ~((first args) entry#)))) + + `(.. ~(get-qualified what) create + ~@args + build))) (defmacro deffx "Uses build and assigns the result to a symbol."