:empty selector
selectors.lisp
Mon Jan 4 06:32:27 UTC 2010 pix@kepibu.org
* :empty selector
--- old-Oh, Ducks!/selectors.lisp 2015-11-13 22:17:04.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2015-11-13 22:17:04.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)