From 64d2b1e4dcf394deb3588a150bb04e9014e1117c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 28 Aug 2016 14:06:35 +0300 Subject: [PATCH] Add basic functionality for render page to plain SVG. --- src/uxbox/main.cljs | 1 + src/uxbox/main/exports.cljs | 56 +++++++++++++++++++++++++++++++++++++ src/uxbox/util/mixins.cljs | 3 ++ 3 files changed, 60 insertions(+) create mode 100644 src/uxbox/main/exports.cljs diff --git a/src/uxbox/main.cljs b/src/uxbox/main.cljs index e9ae8d537..6f1143a4e 100644 --- a/src/uxbox/main.cljs +++ b/src/uxbox/main.cljs @@ -7,6 +7,7 @@ (ns uxbox.main (:require [uxbox.util.rstore :as rs] + [uxbox.main.exports] [uxbox.main.state :as st] [uxbox.main.locales :as lc] [uxbox.main.ui :as ui])) diff --git a/src/uxbox/main/exports.cljs b/src/uxbox/main/exports.cljs new file mode 100644 index 000000000..8b3079e1e --- /dev/null +++ b/src/uxbox/main/exports.cljs @@ -0,0 +1,56 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) 2016 Andrey Antukh +(ns uxbox.main.exports + "The main logic for SVG export functionality." + (:require [uxbox.main.state :as st] + [uxbox.main.ui.shapes.rect :refer (rect-shape)] + [uxbox.main.ui.shapes.icon :refer (icon-shape)] + [uxbox.main.ui.shapes.text :refer (text-shape)] + [uxbox.main.ui.shapes.group :refer (group-shape)] + [uxbox.main.ui.shapes.path :refer (path-shape)] + [uxbox.main.ui.shapes.circle :refer (circle-shape)] + [uxbox.util.mixins :as mx])) + +(mx/defc background + [] + [:rect + {:x 0 :y 0 + :width "100%" + :height "100%" + :fill "white"}]) + +(declare shape) +(declare shape*) + +(mx/defc shape* + [{:keys [type] :as s}] + (case type + :group (group-shape s shape) + :text (text-shape s) + :icon (icon-shape s) + :rect (rect-shape s) + :path (path-shape s) + :circle (circle-shape s))) + +(mx/defc shape + [sid] + (shape* (get-in @st/state [:shapes-by-id sid]))) + +(mx/defc page-svg + [{:keys [width height] :as page}] + [:svg {:width width + :height height + :version "1.1" + :xmlns "http://www.w3.org/2000/svg"} + (background) + (for [item (reverse (:shapes page))] + (-> (shape item) + (mx/with-key (str item))))]) + +(defn render-page + [id] + (let [page (get-in @st/state [:pages-by-id id])] + (mx/render-static-html (page-svg page)))) diff --git a/src/uxbox/util/mixins.cljs b/src/uxbox/util/mixins.cljs index 3921dfe5e..7aae23296 100644 --- a/src/uxbox/util/mixins.cljs +++ b/src/uxbox/util/mixins.cljs @@ -7,6 +7,7 @@ (ns uxbox.util.mixins (:refer-clojure :exclude [concat]) (:require [sablono.core :refer-macros [html]] + [sablono.server :as server] [rum.core :as rum] [lentes.core :as l] [goog.dom.forms :as gforms])) @@ -47,3 +48,5 @@ (def reactive rum/reactive) (def dom-node rum/dom-node) (def with-key rum/with-key) +(def render-html server/render) +(def render-static-html server/render-static)