Bring element-matches-p more in line with CSS terms as subject-p
Mon Jan 4 01:04:12 UTC 2010 pix@kepibu.org
* Bring element-matches-p more in line with CSS terms as subject-p
diff -rN -u old-Oh, Ducks!/notes new-Oh, Ducks!/notes
--- old-Oh, Ducks!/notes 2013-07-04 19:23:15.000000000 +0000
+++ new-Oh, Ducks!/notes 2013-07-04 19:23:15.000000000 +0000
@@ -124,7 +124,7 @@
see <selectors.lisp>. Generally, you should add a class which is a
subclass of combinator or simple-selector, augment parse-selector with
an appropriate regular expression, and define a method on
-element-matches-p.
+subject-p.
I also recommend submitting a patch. Other people might want to use
that selector, too!
diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp
--- old-Oh, Ducks!/selectors.lisp 2013-07-04 19:23:15.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2013-07-04 19:23:15.000000000 +0000
@@ -106,18 +106,18 @@
(defun subjects-of (selector element)
(nconc
- (when (element-matches-p element selector) (list element))
+ (when (subject-p element selector) (list element))
(subjects-in-list selector (element-children element))))
-(defgeneric element-matches-p (element selector))
+(defgeneric subject-p (element selector))
-(defmethod element-matches-p (element (selector type-selector))
+(defmethod subject-p (element (selector type-selector))
(element-type-equal element (selector-arg selector)))
-(defmethod element-matches-p (element (selector id-selector))
+(defmethod subject-p (element (selector id-selector))
(string= (element-id element) (selector-arg selector)))
-(defmethod element-matches-p (element (selector nth-child-selector))
+(defmethod subject-p (element (selector nth-child-selector))
(when-let* ((parent (element-parent element))
(pos (position element (funcall (typecase selector
(nth-last-child-selector #'reverse)
@@ -134,42 +134,42 @@
(t (and (zerop (mod (- pos b) a))
(not (minusp (/ (- pos b) a)))))))))
-(defmethod element-matches-p (element (selector class-selector))
+(defmethod subject-p (element (selector class-selector))
(member (selector-arg selector)
(element-classes element)
:test #'string=))
-(defmethod element-matches-p (element (selector universal-selector))
+(defmethod subject-p (element (selector universal-selector))
(declare (ignore element selector))
t)
-(defmethod element-matches-p (element (selector %implicit-element-selector))
+(defmethod subject-p (element (selector %implicit-element-selector))
(eq element *implicit-element*))
-(defmethod element-matches-p (element (selector list))
- (every (curry #'element-matches-p element) selector))
+(defmethod subject-p (element (selector list))
+ (every (curry #'subject-p element) selector))
-(defmethod element-matches-p (element (selector child-combinator))
- (element-matches-p (element-parent element) (matcher selector)))
+(defmethod subject-p (element (selector child-combinator))
+ (subject-p (element-parent element) (matcher selector)))
-(defmethod element-matches-p (element (selector descendant-combinator))
- (some (rcurry #'element-matches-p (matcher selector)) (element-ancestors element)))
+(defmethod subject-p (element (selector descendant-combinator))
+ (some (rcurry #'subject-p (matcher selector)) (element-ancestors element)))
-(defmethod element-matches-p (element (selector adjacent-combinator))
+(defmethod subject-p (element (selector adjacent-combinator))
(let* ((parent (element-parent element))
(siblings (element-children parent))
(ourpos (position element siblings :test #'eq)))
(and ourpos
(> ourpos 0)
- (element-matches-p (elt siblings (1- ourpos)) (matcher selector)))))
+ (subject-p (elt siblings (1- ourpos)) (matcher selector)))))
-(defmethod element-matches-p (element (selector sibling-combinator))
+(defmethod subject-p (element (selector sibling-combinator))
(let* ((parent (element-parent element))
(siblings (element-children parent))
(ourpos (position element siblings :test #'eq)))
(and ourpos
(> ourpos 0)
- (find-if (rcurry #'element-matches-p (matcher selector)) siblings :end ourpos))))
+ (find-if (rcurry #'subject-p (matcher selector)) siblings :end ourpos))))
;; Hello excessively long name
(defun terminating-implicit-sibling-combinator-p (selector)