Wed Nov 18 08:57:44 UTC 2009 pix@kepibu.org
* status commit; add cxml:dom support
addfile ./traversal/dom.lisp
hunk ./oh-ducks.asd 24
- (:file "pt" :depends-on ("interface"))))
+ (:file "pt" :depends-on ("interface"))
+ (:file "dom" :depends-on ("interface"))))
hunk ./traversal/dom.lisp 1
+(in-package #:oh-ducks)
+
+;;; general accessors
+
+(defmethod element-children ((element dom:node))
+ (coerce (dom:child-nodes element) 'list))
+(defmethod element-parent ((element dom:node))
+ (dom:parent-node element))
+(defmethod element-attribute (attribute (element dom:node)) nil)
+(defmethod element-attribute ((attribute symbol) (element dom:element))
+ (element-attribute (string-downcase (symbol-name attribute)) element))
+(defmethod element-attribute ((attribute string) (element dom:element))
+ (dom:get-attribute element attribute))
+(defmethod element-type ((element dom:node)) nil)
+(defmethod element-type ((element dom:element))
+ (dom:tag-name element))
+
+;;; special accessors in case something special needs to happen
+(defmethod element-id ((element dom:node))
+ nil)
+(defmethod element-id ((element dom:element))
+ (element-attribute "id" element))
+
+(defmethod element-classes (element)
+ (split-sequence:split-sequence #\Space (element-attribute "class" element) :remove-empty-subseqs t))
hunk ./traversal/interface.lisp 12
-(defgeneric element-attribute (element-attribute element)
- (:documentation "Returns the value of the element-attribute of element, or nil if no such element-attribute exists."))
+(defgeneric element-attribute (attribute element)
+ (:documentation "Returns the value of the attribute of element, or nil if no such attribute exists."))
hunk ./traversal/interface.lisp 20
- (:documentation "Equivalent in spirit to (element-attribute :element-id element).")
+ (:documentation "Equivalent in spirit to (element-attribute :id element).")
hunk ./traversal/interface.lisp 24
- (:documentation "Equivalent in spirit to (element-attribute :class element), except it returns a sequence of individual element-classes.")
+ (:documentation "Equivalent in spirit to (element-attribute :class element), except it returns a sequence of individual classes.")
hunk ./traversal/interface.lisp 29
- (:documentation "Equivalent in spirit to (string-equal (element-type element) element-type), but not obligated to work under the assumption of string-designators.")
+ (:documentation "Equivalent in spirit to (string-equal (element-type element) type), but not obligated to work under the assumption of string-designators.")
hunk ./unification-templates.lisp 12
+(defvar *default-parser* 'pt "Determines the default parser when none is specified.")
+
hunk ./unification-templates.lisp 15
- (#+(or)
- (parser :reader parser) ;; subtype determines parser
- (handler :reader handler) ;; cxml/closure-html handler
+ ((parser :initarg :parser) ;; subtype generally determines parser
hunk ./unification-templates.lisp 21
+(defclass dom-template (xml-template) ())
+
hunk ./unification-templates.lisp 28
-(defmethod make-template ((kind (eql 'lhtml)) (spec cons))
- (make-instance 'lhtml-template :spec spec))
+(defgeneric document-parser (template)
+ (:documentation "Returns a function which, given an unparsed document, parses that document into some sort of structure.")
+ (:method ((template css-selector-template))
+ (slot-value template 'parser))
+ (:method ((template dom-template))
+ (lambda (document) (cxml:parse document (cxml-dom:make-dom-builder))))
+ (:method ((template lhtml-template))
+ (lambda (document) (chtml:parse document (chtml:make-lhtml-builder))))
+ (:method ((template pt-template))
+ (lambda (document) (chtml:parse document (chtml:make-pt-builder)))))
+
+(defun %spec-includes-opts (spec)
+ (keywordp (first (second spec))))
hunk ./unification-templates.lisp 43
- (make-instance 'pt-template :spec spec))
+ (destructuring-bind (&key parser)
+ (if (%spec-includes-opts spec)
+ (second spec)
+ (list :parser *default-parser*))
+ (case parser
+ ;; short names
+ ((lhtml :lhtml) (make-instance 'lhtml-template :spec spec))
+ ((pt :pt) (make-instance 'pt-template :spec spec))
+ ((dom :dom) (make-instance 'dom-template :spec spec))
+ ;; user-specified
+ (t (make-instance 'css-selector-template :parser parser :spec spec)))))
hunk ./unification-templates.lisp 56
- (let ((specifiers-and-vars (or css-specifiers (rest (template-spec template)))))
+ (let* ((spec (template-spec template))
+ (specifiers-and-vars (or css-specifiers (if (%spec-includes-opts spec)
+ (cddr spec)
+ (rest spec)))))
hunk ./unification-templates.lisp 90
+ (declare (ignore env))
hunk ./unification-templates.lisp 107
-(defmethod unify ((template lhtml-template) (document string)
+(defmethod unify (document (template css-selector-template)
hunk ./unification-templates.lisp 110
- (unify template (chtml:parse document (chtml:make-lhtml-builder)) env))
+ (unify template document env))
hunk ./unification-templates.lisp 112
-(defmethod unify ((template pt-template) (document string)
+(defmethod unify ((template css-selector-template) (document string)
hunk ./unification-templates.lisp 115
- (unify template (chtml:parse document (chtml:make-pt-builder)) env))
+ (unify template (funcall (document-parser template) document) env))
+
+(defmethod unify ((template css-selector-template) (document pathname)
+ &optional (env (make-empty-environment))
+ &key &allow-other-keys)
+ (unify template (funcall (document-parser template) document) env))
+