From 7933955a6943c8755cf3830bcc5e4b1c4b085e7b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 17 Jan 2016 23:54:34 +0200 Subject: [PATCH] Attach debug related attrs to rendered shapes. --- src/uxbox/ui/shapes.cljs | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/uxbox/ui/shapes.cljs b/src/uxbox/ui/shapes.cljs index ddf7db99e2..24b8bbab43 100644 --- a/src/uxbox/ui/shapes.cljs +++ b/src/uxbox/ui/shapes.cljs @@ -15,7 +15,13 @@ "Extract predefinet attrs from shapes." [shape] (select-keys shape [:rotation :width :height - :x :y :opacity :fill])) + :x :y :opacity :fill :view-box])) + +(defn- make-debug-attrs + [attrs] + (let [xf (map (fn [[x v]] + [(keyword (str "data-" (name x))) v]))] + (into {} xf attrs))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Implementation @@ -26,12 +32,28 @@ (let [key (str "use-" id) transform (-> (merge shape attrs) (svg/calculate-transform)) - attrs {:id key - :key key - :transform transform}] + attrs {:id key :key key :transform transform} + attrs (-> (extract-attrs shape) + (make-debug-attrs) + (merge attrs))] (html [:g attrs data]))) +(defmethod shapes/-render :builtin/group + [{:keys [items id] :as shape} attrs] + (let [key (str "group-" id) + tfm (-> (merge shape attrs) + (svg/calculate-transform)) + attrs {:id key :key key :transform tfm} + attrs (-> (extract-attrs shape) + (make-debug-attrs) + (merge attrs)) + shapes-by-id (get @st/state :shapes-by-id)] + (html + [:g attrs + (for [item (map #(get shapes-by-id %) items)] + (shapes/-render item nil))]))) + (defmethod shapes/-render-svg :builtin/icon [{:keys [data id view-box] :as shape} attrs] (let [key (str "icon-svg-" id) @@ -44,14 +66,3 @@ (html [:svg attrs data]))) -(defmethod shapes/-render :builtin/group - [{:keys [items id] :as shape} attrs] - (let [key (str "group-" id) - tfm (-> (merge shape attrs) - (svg/calculate-transform)) - attrs {:id key :key key :transform tfm} - shapes-by-id (get @st/state :shapes-by-id)] - (html - [:g attrs - (for [item (map #(get shapes-by-id %) items)] - (shapes/-render item nil))])))