From 9fb13ba73d3d46d2a8f66aa12db9f1203fc0afac Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 9 Nov 2016 11:24:26 +0100 Subject: [PATCH] Add support for preconditions to defc and defcs macros. --- src/uxbox/util/mixins.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/uxbox/util/mixins.clj b/src/uxbox/util/mixins.clj index 4f34ae4a2..eafa11437 100644 --- a/src/uxbox/util/mixins.clj +++ b/src/uxbox/util/mixins.clj @@ -30,8 +30,14 @@ (recur (assoc r :mixins mixins) (inc s) (first n) (rest n))) (recur (assoc r :mixins [v]) (inc s) (first n) (rest n))) (recur r (inc s) v n)) - 3 (let [sym (:name r) - func `(fn ~sym ~v ~(s/compile-html `(do ~@n)))] + 3 (if (vector? v) + (recur (assoc r :args v) (inc s) (first n) (rest n)) + (throw (ex-info "Invalid" {}))) + 4 (let [sym (:name r) + args (:args r) + func (if (map? v) + `(fn ~sym ~args ~v ~(s/compile-html `(do ~@n))) + `(fn ~sym ~args ~(s/compile-html `(do ~@(cons v n)))))] [func (:doc r) (:mixins r) sym])))) (defmacro defc