Mon Jan 4 06:32:27 UTC 2010 pix@kepibu.org
* :empty selector
diff -rN -u old-Oh, Ducks!/notes new-Oh, Ducks!/notes
--- old-Oh, Ducks!/notes 2013-07-24 10:35:00.000000000 +0000
+++ new-Oh, Ducks!/notes 2013-07-24 10:35:00.000000000 +0000
@@ -134,7 +134,7 @@
* [ ] selectors involving descendants
** write documentation
** improve selector support
-*** positional selectors [18/19]
+*** positional selectors [19/19]
* [X] :nth-child(an+b)
* [X] :nth-child(b)
* [X] :nth-child(odd|even)
@@ -153,7 +153,7 @@
* [X] :last-of-type
* [X] :only-child
* [X] :only-of-type
- * [ ] :empty
+ * [X] :empty
*** attribute selectors [0/7]
* [ ] attribute-present [att]
* [ ] attribute-equal [att=val]
diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp
--- old-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:00.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:00.000000000 +0000
@@ -40,6 +40,7 @@
(defclass nth-last-child-selector (nth-child-selector) ())
(defclass nth-of-type-selector (nth-child-selector) ())
(defclass nth-last-of-type-selector (nth-of-type-selector) ())
+(defclass empty-selector (simple-selector) ())
(defmethod initialize-instance :after ((selector nth-child-selector)
&key (asign "+") a
@@ -182,6 +183,8 @@
(list* (make-instance 'nth-of-type-selector :a 0 :b 1)
(make-instance 'nth-last-of-type-selector :a 0 :b 1)
(parse-selector &rest)))
+ (#T(regexp$ (":empty") ())
+ (cons (make-instance 'empty-selector) (parse-selector &rest)))
(#T(regexp$ (#\# $name) (?id))
(cons (make-instance 'id-selector :arg id) (parse-selector &rest)))
(#T(regexp$ (#\. $name) (?class))
@@ -246,6 +249,9 @@
(remove-if-not (rcurry #'element-type-equal (element-type element))
(element-children parent))))))
+(defmethod subject-p ((selector empty-selector) element)
+ (= 0 (length (element-children element))))
+
(defmethod subject-p ((selector class-selector) element)
(member (selector-arg selector)
(element-classes element)
diff -rN -u old-Oh, Ducks!/tests.lisp new-Oh, Ducks!/tests.lisp
--- old-Oh, Ducks!/tests.lisp 2013-07-24 10:35:00.000000000 +0000
+++ new-Oh, Ducks!/tests.lisp 2013-07-24 10:35:00.000000000 +0000
@@ -87,6 +87,11 @@
"<div>I <i>really</i> <b>like</b> cheese. Do you not <i>dislike</i> cheese?</div>")
(values i))
+(match (#T(html (:model pt)
+ ("body :empty" . ?empty))
+ "<div><p><br></p><p>testing<i>i</i>testing</p></div>")
+ (values empty))
+
;; Sometimes, you want to match a thing inside a thing, in which case
;; combinators should implicitly assume an unspecified right side means
;; "whatever element I gave you".