Add attribute-equal selector
selectors.lisp
Wed Feb 10 08:50:16 UTC 2010 pix@kepibu.org
* Add attribute-equal selector
--- old-Oh, Ducks!/selectors.lisp 2015-10-28 01:23:35.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2015-10-28 01:23:35.000000000 +0000
@@ -42,8 +42,10 @@
(defclass nth-last-of-type-selector (nth-of-type-selector) ())
(defclass empty-selector (simple-selector) ())
-(defclass attribute-selector (simple-selector) ())
+(defclass attribute-selector (simple-selector)
+ ((val :reader attribute-value :initarg :value)))
(defclass attribute-present-selector (attribute-selector) ())
+(defclass attribute-equal-selector (attribute-selector) ())
(defmethod initialize-instance :after ((selector nth-child-selector)
&key (asign "+") a
@@ -110,6 +112,9 @@
(#T(regexp$ ("[" $name "]") (?attribute))
(cons (make-instance 'attribute-present-selector :arg attribute)
(parse-selector &rest)))
+ (#T(regexp$ ("[" $name "=" $name "]") (?attribute ?value))
+ (cons (make-instance 'attribute-equal-selector :arg attribute :value value)
+ (parse-selector &rest)))
;; cyclic (An+B, n+B)
(#T(regexp$ (":nth-child(" \s* an+b \s* ")")
(?asign ?a ?bsign ?b))
@@ -271,6 +276,10 @@
(defmethod subject-p ((selector attribute-present-selector) element)
(element-attribute (selector-arg selector) element))
+(defmethod subject-p ((selector attribute-equal-selector) element)
+ (when-let* ((val (element-attribute (selector-arg selector) element)))
+ (string= val (attribute-value selector))))
+
(defmethod subject-p ((selector %implicit-element-selector) element)
(eq element *implicit-element*))