0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

Move shapes rendering implementation under uxbox.ui namespace.

This commit is contained in:
Andrey Antukh 2016-01-02 18:03:16 +02:00
parent d833543368
commit b937408bab
3 changed files with 47 additions and 37 deletions

View file

@ -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}]

View file

@ -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]) $

View file

@ -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]])))