Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #16 from arthuredelstein/master

Various small bug fixes
  • Loading branch information...
commit 4635737283c164e4a7619be098e635ccc892de19 2 parents a08ef99 + 6b77e0f
Chris Granger authored
12 src/crate/binding.cljs
@@ -110,6 +110,9 @@
110 110 (fn [_ _ _ [event el v]]
111 111 (func event el v)))))
112 112
  113 +(defn opt [bc k]
  114 + ((.-opts bc) k))
  115 +
113 116 (defn- bc-add [bc path key]
114 117 (let [sa (subatom (.-atm bc) path)
115 118 elem ((opt bc :as) sa)]
@@ -123,9 +126,6 @@
123 126 (set! (.-stuff bc) (dissoc (.-stuff bc) key))
124 127 (notify (.-notif bc) nil [:remove (:elem prev) nil])) )
125 128
126   -(defn opt [bc k]
127   - ((.-opts bc) k))
128   -
129 129 (defn ->indexed [coll]
130 130 (cond
131 131 (map? coll) (seq coll)
@@ -138,7 +138,7 @@
138 138 (defn ->path [bc & segs]
139 139 (concat (or (opt bc :path) []) segs))
140 140
141   -(defn- bc-compare [bc neue keyfn]
  141 +(defn- bc-compare [bc neue]
142 142 (let [prev (.-stuff bc)
143 143 pset (into #{} (keys prev))
144 144 nset (->keyed neue (opt bc :keyfn))
@@ -163,7 +163,7 @@
163 163 bc (bound-collection. atm (notifier. nil) opts {})]
164 164 (add-watch atm (gensym "bound-coll") (fn [_ _ _ neue]
165 165 (bc-compare bc neue)))
166   - (bc-compare bc @atm keyfn)
  166 + (bc-compare bc @atm)
167 167 bc))
168 168
169 169
@@ -181,4 +181,4 @@
181 181
182 182 (defn bound [atm & [func]]
183 183 (let [func (or func identity)]
184   - (atom-binding. atm func {})))
  184 + (atom-binding. atm func)))
38 src/crate/compiler.cljs
@@ -24,6 +24,24 @@
24 24 (defn capture-binding [tag b]
25 25 (swap! bindings conj [tag b]))
26 26
  27 +(defn as-content [parent content]
  28 + (doseq[c content]
  29 + (let [child (cond
  30 + (nil? c) nil
  31 + (map? c) (throw "Maps cannot be used as content")
  32 + (string? c) (gdom/createTextNode c)
  33 + (vector? c) (elem-factory c)
  34 + ;;TODO: there's a bug in clojurescript that prevents seqs from
  35 + ;; being considered collections
  36 + (seq? c) (as-content parent c)
  37 + (bind/binding-coll? c) (do (capture-binding :coll c) (as-content parent [(bind/value c)]))
  38 + (bind/binding? c) (do (capture-binding :text c) (as-content parent [(bind/value c)]))
  39 + (.-nodeName c) c
  40 + (.-get c) (.get c 0)
  41 + :else (gdom/createTextNode (str c)))]
  42 + (when child
  43 + (gdom/appendChild parent child)))))
  44 +
27 45 (defmulti dom-binding (fn [type _ _] type))
28 46 (defmethod dom-binding :text [_ b elem]
29 47 (bind/on-change b (fn [v]
@@ -70,7 +88,7 @@
70 88 (dom-style elem k v))
71 89 (bind/binding? v) (do
72 90 (capture-binding :attr [:style v])
73   - (dom-style (bind/value v))))
  91 + (dom-style elem (bind/value v))))
74 92 elem)
75 93 ([elem k v]
76 94 (let [v (if (bind/binding? v)
@@ -100,24 +118,6 @@
100 118 (. elem (setAttribute (name k) v))))
101 119 elem))
102 120
103   -(defn as-content [parent content]
104   - (doseq[c content]
105   - (let [child (cond
106   - (nil? c) nil
107   - (map? c) (throw "Maps cannot be used as content")
108   - (string? c) (gdom/createTextNode c)
109   - (vector? c) (elem-factory c)
110   - ;;TODO: there's a bug in clojurescript that prevents seqs from
111   - ;; being considered collections
112   - (seq? c) (as-content parent c)
113   - (bind/binding-coll? c) (do (capture-binding :coll c) (as-content parent [(bind/value c)]))
114   - (bind/binding? c) (do (capture-binding :text c) (as-content parent [(bind/value c)]))
115   - (.-nodeName c) c
116   - (.-get c) (.get c 0)
117   - :else (gdom/createTextNode (str c)))]
118   - (when child
119   - (gdom/appendChild parent child)))))
120   -
121 121 ;; From Weavejester's Hiccup: https://github.com/weavejester/hiccup/blob/master/src/hiccup/core.clj#L57
122 122 (def ^{:doc "Regular expression that parses a CSS-style id and class from a tag name." :private true}
123 123 re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
10 src/crate/util.cljs
@@ -20,11 +20,11 @@
20 20 (defn escape-html
21 21 "Change special characters into HTML character entities."
22 22 [text]
23   - (.. (as-str text)
24   - (replace "&" "&")
25   - (replace "<" "&lt;")
26   - (replace ">" "&gt;")
27   - (replace "\"" "&quot;")))
  23 + (-> (as-str text)
  24 + (str/replace "&" "&amp;")
  25 + (str/replace "<" "&lt;")
  26 + (str/replace ">" "&gt;")
  27 + (str/replace "\"" "&quot;")))
28 28
29 29 (defn to-uri
30 30 "Prepends the base-url to the supplied URI."

0 comments on commit 4635737

Please sign in to comment.
Something went wrong with that request. Please try again.