Render properly image on view application.

This commit is contained in:
Andrey Antukh 2017-01-30 18:53:42 +01:00
parent 0d46c5bac7
commit ae5cef3907
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
4 changed files with 5 additions and 11 deletions

View file

@ -40,7 +40,6 @@
:circle (circle-shape shape) :circle (circle-shape shape)
:image (let [image-id (:image shape) :image (let [image-id (:image shape)
image (get-in @*state* [:images image-id])] image (get-in @*state* [:images image-id])]
;; (println "shape-wrapper" image)
(image-shape (assoc shape :image image))))) (image-shape (assoc shape :image image)))))
(mx/defc shape-component (mx/defc shape-component
@ -57,17 +56,13 @@
:version "1.1" :version "1.1"
:xmlnsXlink "http://www.w3.org/1999/xlink" :xmlnsXlink "http://www.w3.org/1999/xlink"
:xmlns "http://www.w3.org/2000/svg"} :xmlns "http://www.w3.org/2000/svg"}
;; TODO: properly handle background
#_(background) #_(background)
(for [item (reverse (:shapes page))] (for [item (reverse (:shapes page))]
(-> (shape item) (-> (shape-component item)
(mx/with-key (str item))))])) (mx/with-key (str item))))]))
(defn render-page (defn render-page
[id]
(let [page (get-in @st/state [:pages id])]
(mx/render-static-html (page-svg page))))
(defn render-page*
[id] [id]
(let [page (get-in @st/state [:pages id])] (let [page (get-in @st/state [:pages id])]
(when (:shapes page) (when (:shapes page)

View file

@ -122,7 +122,7 @@
(defn- grid-item-thumbnail-will-mount (defn- grid-item-thumbnail-will-mount
[own] [own]
(let [[project] (:rum/args own) (let [[project] (:rum/args own)
svg (exports/render-page* (:page-id project)) svg (exports/render-page (:page-id project))
url (some-> svg url (some-> svg
(blob/create "image/svg+xml") (blob/create "image/svg+xml")
(blob/create-uri))] (blob/create-uri))]

View file

@ -65,6 +65,5 @@
:transform (str xfmt) :transform (str xfmt)
:width width :width width
:height height} :height height}
attrs (merge props (attrs/extract-style-attrs shape))] attrs (merge props (attrs/extract-style-attrs shape))]
[:image attrs])) [:image attrs]))

View file

@ -44,7 +44,7 @@
(defn- download-page-svg (defn- download-page-svg
[{:keys [name id] :as page}] [{:keys [name id] :as page}]
(let [content (exports/render-page id) (let [content (or (exports/render-page id) "")
blob (blob/create content "image/svg+xml") blob (blob/create content "image/svg+xml")
uri (blob/create-uri blob) uri (blob/create-uri blob)
link (.createElement js/document "a") link (.createElement js/document "a")
@ -64,7 +64,7 @@
(defn- generate-files (defn- generate-files
[pages] [pages]
(reduce (fn [acc {:keys [id name]}] (reduce (fn [acc {:keys [id name]}]
(let [content (exports/render-page id)] (let [content (or (exports/render-page id) "")]
(conj acc [(str (str/uslug name) ".svg") (conj acc [(str (str/uslug name) ".svg")
(blob/create content "image/svg+xml")]))) (blob/create content "image/svg+xml")])))
[] []