diff --git a/src/dommy/macros.clj b/src/dommy/macros.clj index 0037dfb..3ae6592 100644 --- a/src/dommy/macros.clj +++ b/src/dommy/macros.clj @@ -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?])) @@ -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 diff --git a/test/dommy/template_test.cljs b/test/dommy/template_test.cljs index abd6d6c..eff4345 100644 --- a/test/dommy/template_test.cljs +++ b/test/dommy/template_test.cljs @@ -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)))) \ No newline at end of file + (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]))))