Skip to content

Commit

Permalink
Add support for SVG to compile-compound macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ideal-knee committed Nov 2, 2013
1 parent d87a136 commit 62b5922
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/dommy/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

(declare node)

(def +default-ns+ "http://www.w3.org/1999/xhtml")
(def +svg-ns+ "http://www.w3.org/2000/svg")
(def +svg-tags+ #{"svg" "g" "rect" "circle" "clipPath" "path" "line" "polygon" "polyline" "text" "textPath"})

(defn constant? [data]
(some #(% data) [number? keyword? string?]))

Expand Down Expand Up @@ -122,8 +126,9 @@
(first rest))
children (drop (if (or literal-attrs var-attrs) 1 0) rest)
[tag class-str id] (parse-keyword node-key)
dom-sym (gensym "dom")]
`(let [~dom-sym (.createElement js/document ~(name tag))]
dom-sym (gensym "dom")
element-ns (if (+svg-tags+ tag) +svg-ns+ +default-ns+)]
`(let [~dom-sym (.createElementNS js/document ~element-ns ~(name tag))]
~@(when-not (empty? class-str)
[`(set! (.-className ~dom-sym) ~class-str)])
~@(when id
Expand Down
6 changes: 5 additions & 1 deletion test/dommy/template_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,8 @@

(deftest classes-attr
(is= "class-42 class-43" (.-className (classes-attr-template 42 43)))
(is= "c1 c2" (.-className (classes-compilable-attr-template))))
(is= "c1 c2" (.-className (classes-compilable-attr-template))))

(deftest namespaces
(is= "http://www.w3.org/1999/xhtml" (.-namespaceURI (node [:p])))
(is= "http://www.w3.org/2000/svg" (.-namespaceURI (node [:circle]))))

0 comments on commit 62b5922

Please sign in to comment.