Permalink
Browse files

Merge pull request #16 from arthuredelstein/master

Various small bug fixes
  • Loading branch information...
2 parents a08ef99 + 6b77e0f commit 4635737283c164e4a7619be098e635ccc892de19 @ibdknox committed Sep 7, 2012
Showing with 30 additions and 30 deletions.
  1. +6 −6 src/crate/binding.cljs
  2. +19 −19 src/crate/compiler.cljs
  3. +5 −5 src/crate/util.cljs
View
12 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 {})]
(add-watch atm (gensym "bound-coll") (fn [_ _ _ neue]
(bc-compare bc neue)))
- (bc-compare bc @atm keyfn)
+ (bc-compare bc @atm)
bc))
@@ -181,4 +181,4 @@
(defn bound [atm & [func]]
(let [func (or func identity)]
- (atom-binding. atm func {})))
+ (atom-binding. atm func)))
View
38 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]
@@ -70,7 +88,7 @@
(dom-style elem k v))
(bind/binding? v) (do
(capture-binding :attr [:style v])
- (dom-style (bind/value v))))
+ (dom-style elem (bind/value v))))
elem)
([elem k v]
(let [v (if (bind/binding? v)
@@ -100,24 +118,6 @@
(. 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#]+))?")
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 "&" "&")
- (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."

0 comments on commit 4635737

Please sign in to comment.