Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from emezeske/attr-fixes

Handle boolean attributes like hiccup does.
  • Loading branch information...
commit c1dcdfaeb0d13f8fbde08155708a7ee3284c41b1 2 parents 4635737 + ede7b06
@ibdknox authored
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/crate/compiler.cljs
View
7 src/crate/compiler.cljs
@@ -122,6 +122,11 @@
(def ^{:doc "Regular expression that parses a CSS-style id and class from a tag name." :private true}
re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
+(defn- normalize-map-attrs [map-attrs]
+ (into {} (map (fn [[n v]] (if (true? v) [n (name n)] [n v]))
+ (filter (comp boolean second)
+ map-attrs))))
+
(defn- normalize-element
"Ensure a tag vector is of the form [tag-name attrs content]."
[[tag & content]]
@@ -139,7 +144,7 @@
:class (if class (string/replace class #"\." " "))}))
map-attrs (first content)]
(if (map? map-attrs)
- [nsp tag (merge tag-attrs map-attrs) (next content)]
+ [nsp tag (merge tag-attrs (normalize-map-attrs map-attrs)) (next content)]
[nsp tag tag-attrs content])))
(defn parse-content [elem content]
Please sign in to comment.
Something went wrong with that request. Please try again.