From b937408babd395968e1d716a48755e4f9910d11e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 2 Jan 2016 18:03:16 +0200 Subject: [PATCH] Move shapes rendering implementation under uxbox.ui namespace. --- frontend/uxbox/shapes.cljs | 42 +++++------------------------------ frontend/uxbox/ui.cljs | 3 ++- frontend/uxbox/ui/shapes.cljs | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 frontend/uxbox/ui/shapes.cljs diff --git a/frontend/uxbox/shapes.cljs b/frontend/uxbox/shapes.cljs index 1c55d8f44..da498e812 100644 --- a/frontend/uxbox/shapes.cljs +++ b/frontend/uxbox/shapes.cljs @@ -1,6 +1,4 @@ -(ns uxbox.shapes - (:require [sablono.core :refer-macros [html]] - [uxbox.util.data :refer (remove-nil-vals)])) +(ns uxbox.shapes) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Types @@ -28,11 +26,11 @@ ([shape attrs] (-render shape attrs))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Implementation +;; Implementation Api ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn- dispatch-by-type - [shape props] + [shape & params] (:type shape)) (defmulti -render @@ -43,37 +41,9 @@ dispatch-by-type :hierarchy #'+hierarchy+) -(defn transform-attrs - [{:keys [view-box] :as data}] - (if view-box - (assoc data :view-box (apply str (interpose " " view-box))) - data)) - -(defn extract-attrs - "Extract predefinet attrs from shapes." - [shape] - (select-keys shape [:width :height :view-box :x :y :cx :cy])) - -(defmethod -render :builtin/icon - [{:keys [data id] :as shape} attrs] - (let [attrs (as-> shape $ - (extract-attrs $) - (remove-nil-vals $) - (merge $ attrs) - (transform-attrs $))] - (html - [:svg (merge attrs {:key (str id)}) data]))) - -(defmethod -render :builtin/icon-svg - [{:keys [image id] :as shape} attrs] - (let [attrs (as-> shape $ - (extract-attrs $) - (remove-nil-vals $) - (merge $ attrs) - (transform-attrs $))] - (html - [:svg (merge attrs {:key (str id)}) - [:image image]]))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Implementation +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmethod -move ::shape [shape {:keys [dx dy] :as opts}] diff --git a/frontend/uxbox/ui.cljs b/frontend/uxbox/ui.cljs index ebad1e6af..ad46f35eb 100644 --- a/frontend/uxbox/ui.cljs +++ b/frontend/uxbox/ui.cljs @@ -11,7 +11,8 @@ [uxbox.ui.dashboard :as dashboard] [uxbox.ui.workspace :refer (workspace)] [uxbox.ui.util :as util] - [uxbox.ui.mixins :as mx])) + [uxbox.ui.mixins :as mx] + [uxbox.ui.shapes])) (def ^:static state (as-> (l/select-keys [:location :location-params]) $ diff --git a/frontend/uxbox/ui/shapes.cljs b/frontend/uxbox/ui/shapes.cljs new file mode 100644 index 000000000..a8b883dbe --- /dev/null +++ b/frontend/uxbox/ui/shapes.cljs @@ -0,0 +1,39 @@ +(ns uxbox.ui.shapes + "A ui related implementation for uxbox.shapes ns." + (:require [sablono.core :refer-macros [html]] + [uxbox.shapes :as shapes] + [uxbox.util.data :refer (remove-nil-vals)])) + +(defn- transform-attrs + [{:keys [view-box] :as data}] + (if view-box + (assoc data :view-box (apply str (interpose " " view-box))) + data)) + +(defn- extract-attrs + "Extract predefinet attrs from shapes." + [shape] + (select-keys shape [:width :height :view-box :x :y :cx :cy])) + +(defmethod shapes/-render :builtin/icon + [{:keys [data id] :as shape} attrs] + (let [attrs (as-> shape $ + (extract-attrs $) + (remove-nil-vals $) + (merge $ attrs) + (transform-attrs $))] + (html + [:svg (merge attrs {:key (str id)}) data]))) + +(defmethod shapes/-render :builtin/icon-svg + [{:keys [image id] :as shape} attrs] + (let [attrs (as-> shape $ + (extract-attrs $) + (remove-nil-vals $) + (merge $ attrs) + (transform-attrs $))] + (html + [:svg (merge attrs {:key (str id)}) + [:image image]]))) + +