Skip to content

Commit

Permalink
finished wiring in the enlive syntax into the core selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ckirkendall committed Jul 26, 2012
1 parent 21a953d commit 95381c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions project/cljs-src/enfocus/core.cljs
@@ -1,5 +1,6 @@
(ns enfocus.core
(:require [goog.net.XhrIo :as xhr]
(:require [enfocus.enlive.syntax :as en]
[goog.net.XhrIo :as xhr]
[goog.dom.query :as query]
[goog.style :as style]
[goog.events :as events]
Expand Down Expand Up @@ -417,7 +418,7 @@
(let [callback (mouse-enter-leave func)]
(set! (.-listen callback) func)
(set! (.-scope callback) opt-scope)
(if op-handler
(if opt-handler
(.listen opt-handler elm (name event) callback)
(events/listen elm (name event) callback)))))
(set! (.-unlisten obj)
Expand Down Expand Up @@ -618,7 +619,7 @@
([css-sel] (css-select "" js/document css-sel))
([dom-node css-sel] (css-select "" dom-node css-sel))
([id-mask-sym dom-node css-sel]
(let [sel (string/trim (string/replace (create-sel-str id-mask-sym css-sel) " :" ":"))
(let [sel (string/trim (en/convert (create-sel-str id-mask-sym css-sel)))
ret (dcss/sel dom-node sel)]
ret)))

Expand Down
10 changes: 6 additions & 4 deletions project/cljs-src/enfocus/enlive/syntax.cljs
Expand Up @@ -7,19 +7,21 @@
(coll? item) (apply str (map #(sel-to-string %) item))))

(defn convert [sel]
(apply str (interpose " " (map sel-to-string sel))))
(if (string? sel)
sel
(apply str (interpose " " (map sel-to-string sel)))))

(defn- attr-pairs [op elms]
(let [ts (fn [[x y]] (str "[" x op "='" y "']"))]
(apply str (map ts (partition elms 2)))))
(let [ts (fn [[x y]] (str "[" (name x) op "='" y "']"))]
(apply str (map ts (partition 2 elms)))))

(defn attr? [& elms]
(apply str (map #(str "[" (name %) "]") elms)))

(defn attr= [& elms] (attr-pairs "" elms))

(defn attr-has [x & vals]
(let [ts (fn [y] (str "[" x "~='" y "']"))]
(let [ts (fn [y] (str "[" (name x) "~='" y "']"))]
(apply str (map ts vals))))

(defn attr-starts [& elms] (attr-pairs "^" elms))
Expand Down
8 changes: 5 additions & 3 deletions project/cljs-src/enfocus/example.cljs
@@ -1,6 +1,7 @@
(ns enfocus.example
(:use [enfocus.enlive.syntax :only [attr=]])
(:require [enfocus.core :as ef])
(:require-macros [enfocus.macros :as em]))
(:require-macros [enfocus.macros :as em]))



Expand Down Expand Up @@ -59,13 +60,14 @@
["tr > *:first-child"] (em/content test-desc)
["tr > *:last-child > span"] (em/content value))


(em/deftemplate test-cases "templates/test-grid.html" []
["#test3 > *:last-child"] (em/content (success))
["#test4 > *:last-child"] (em/content (success))
["#test5 > *:last-child"] (em/html-content "<span class='success'>success</span>")
["#test6 > *:last-child"] (em/set-attr :test6 "cool")
["td[test6='cool']"] (em/content (success))
;["td[test6='cool']"] (em/content (success))
[[:td (attr= :test6 "cool")]] (em/content (success))
["#test7"] (em/remove-attr :foo)
["#test7 > *:last-child"] (em/content (success))
["tr[foo]"] (em/html-content "<span class='fail'>fail</span>") ;should do nothing
Expand Down

0 comments on commit 95381c9

Please sign in to comment.