Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge and fix warnings

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
commit b7bde41a082b06384c741051518de3c9b8be1943 2 parents df66930 + c1dcdfa
@ibdknox authored
View
14 src/crate/binding.cljs
@@ -110,6 +110,9 @@
(fn [_ _ _ [event el v]]
(func event el v)))))
+(defn opt [bc k]
+ ((.-opts bc) k))
+
(defn- bc-add [bc path key]
(let [sa (subatom (.-atm bc) path)
elem ((opt bc :as) sa)]
@@ -123,9 +126,6 @@
(set! (.-stuff bc) (dissoc (.-stuff bc) key))
(notify (.-notif bc) nil [:remove (:elem prev) nil])) )
-(defn opt [bc k]
- ((.-opts bc) k))
-
(defn ->indexed [coll]
(cond
(map? coll) (seq coll)
@@ -138,7 +138,7 @@
(defn ->path [bc & segs]
(concat (or (opt bc :path) []) segs))
-(defn- bc-compare [bc neue keyfn]
+(defn- bc-compare [bc neue]
(let [prev (.-stuff bc)
pset (into #{} (keys prev))
nset (->keyed neue (opt bc :keyfn))
@@ -163,7 +163,7 @@
bc (bound-collection. atm (notifier. nil) opts (sorted-map))]
(add-watch atm (gensym "bound-coll") (fn [_ _ _ neue]
(bc-compare bc neue)))
- (bc-compare bc @atm (:keyfn opts))
+ (bc-compare bc @atm)
bc))
(defn map-bound [as atm & [opts]]
@@ -177,7 +177,7 @@
bc (bound-collection. atm (notifier. nil) opts (sorted-map))]
(add-watch atm (gensym "bound-coll") (fn [_ _ _ neue]
(bc-compare bc neue)))
- (bc-compare bc @atm (:keyfn opts))
+ (bc-compare bc @atm)
bc))
(defn binding? [b]
@@ -197,4 +197,4 @@
(defn bound [atm & [func]]
(let [func (or func identity)]
- (atom-binding. atm func {})))
+ (atom-binding. atm func)))
View
43 src/crate/compiler.cljs
@@ -24,6 +24,24 @@
(defn capture-binding [tag b]
(swap! bindings conj [tag b]))
+(defn as-content [parent content]
+ (doseq[c content]
+ (let [child (cond
+ (nil? c) nil
+ (map? c) (throw "Maps cannot be used as content")
+ (string? c) (gdom/createTextNode c)
+ (vector? c) (elem-factory c)
+ ;;TODO: there's a bug in clojurescript that prevents seqs from
+ ;; being considered collections
+ (seq? c) (as-content parent c)
+ (bind/binding-coll? c) (do (capture-binding :coll c) (as-content parent [(bind/value c)]))
+ (bind/binding? c) (do (capture-binding :text c) (as-content parent [(bind/value c)]))
+ (.-nodeName c) c
+ (.-get c) (.get c 0)
+ :else (gdom/createTextNode (str c)))]
+ (when child
+ (gdom/appendChild parent child)))))
+
(defmulti dom-binding (fn [type _ _] type))
(defmethod dom-binding :text [_ b elem]
(bind/on-change b (fn [v]
@@ -102,28 +120,15 @@
(. elem (setAttribute (name k) v))))
elem))
-(defn as-content [parent content]
- (doseq[c content]
- (let [child (cond
- (nil? c) nil
- (map? c) (throw "Maps cannot be used as content")
- (string? c) (gdom/createTextNode c)
- (vector? c) (elem-factory c)
- ;;TODO: there's a bug in clojurescript that prevents seqs from
- ;; being considered collections
- (seq? c) (as-content parent c)
- (bind/binding-coll? c) (do (capture-binding :coll c) (as-content parent [(bind/value c)]))
- (bind/binding? c) (do (capture-binding :text c) (as-content parent [(bind/value c)]))
- (.-nodeName c) c
- (.-get c) (.get c 0)
- :else (gdom/createTextNode (str c)))]
- (when child
- (gdom/appendChild parent child)))))
-
;; From Weavejester's Hiccup: https://github.com/weavejester/hiccup/blob/master/src/hiccup/core.clj#L57
(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]]
@@ -141,7 +146,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]
View
10 src/crate/util.cljs
@@ -20,11 +20,11 @@
(defn escape-html
"Change special characters into HTML character entities."
[text]
- (.. (as-str text)
- (replace "&" "&amp;")
- (replace "<" "&lt;")
- (replace ">" "&gt;")
- (replace "\"" "&quot;")))
+ (-> (as-str text)
+ (str/replace "&" "&amp;")
+ (str/replace "<" "&lt;")
+ (str/replace ">" "&gt;")
+ (str/replace "\"" "&quot;")))
(defn to-uri
"Prepends the base-url to the supplied URI."
Please sign in to comment.
Something went wrong with that request. Please try again.