(in-package #:oh-ducks.traversal) (defmethod unify::occurs-in-p ((var symbol) (pat dom:element) env) (declare (ignore var pat env)) nil) (defmethod unify:unify ((template oh-ducks::css-selector-template) (document dom:document) &optional (env (unify:make-empty-environment)) &key) (unify:unify template (dom:document-element document) env)) ;;; general accessors (defmethod element-children ((element dom:element)) (remove-if-not #'dom:element-p (coerce (dom:child-nodes element) 'list))) (defmethod element-parent ((element dom:element)) (let ((parent (dom:parent-node element))) (unless (typep parent 'dom:document) parent))) (defmethod element-attribute ((attribute symbol) (element dom:element)) (element-attribute (string-downcase (symbol-name attribute)) element)) (defmethod element-attribute ((attribute string) (element dom:element)) (when-let* ((attribute-node (dom:get-attribute-node element attribute))) (dom:value attribute-node))) (defmethod element-type ((element dom:element)) (dom:tag-name element)) (defmethod element-content ((element dom:element)) (mapcar (lambda (node) (typecase node (dom:element node) (dom:text (dom:data node)) (t (error "Unsure what to do.")))) (coerce (dom:child-nodes element) 'list))) ;;; special accessors in case something special needs to happen (defmethod element-id ((element dom:element)) (element-attribute "id" element)) (defmethod element-classes ((element dom:element)) (split-sequence:split-sequence #\Space (element-attribute "class" element) :remove-empty-subseqs t))