Add attribute-present selector
selectors.lisp
Wed Feb 10 08:28:34 UTC 2010 pix@kepibu.org
* Add attribute-present selector
--- old-Oh, Ducks!/selectors.lisp 2015-12-04 07:04:58.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2015-12-04 07:04:58.000000000 +0000
@@ -42,6 +42,9 @@
(defclass nth-last-of-type-selector (nth-of-type-selector) ())
(defclass empty-selector (simple-selector) ())
+(defclass attribute-selector (simple-selector) ())
+(defclass attribute-present-selector (attribute-selector) ())
+
(defmethod initialize-instance :after ((selector nth-child-selector)
&key (asign "+") a
(bsign "+") b
@@ -103,6 +106,10 @@
(#T(regexp$ (\s+) ())
(list (make-instance 'descendant-combinator :matcher (or (parse-selector &rest) %implicit-element-selector))))
;; simple selectors
+ ;; attribute selectors
+ (#T(regexp$ ("[" $name "]") (?attribute))
+ (cons (make-instance 'attribute-present-selector :arg attribute)
+ (parse-selector &rest)))
;; cyclic (An+B, n+B)
(#T(regexp$ (":nth-child(" \s* an+b \s* ")")
(?asign ?a ?bsign ?b))
@@ -261,6 +268,9 @@
(declare (ignore element selector))
t)
+(defmethod subject-p ((selector attribute-present-selector) element)
+ (element-attribute (selector-arg selector) element))
+
(defmethod subject-p ((selector %implicit-element-selector) element)
(eq element *implicit-element*))