X-Git-Url: http://git.kpe.io/?p=hyperobject.git;a=blobdiff_plain;f=views.lisp;h=6c102965ef1cbfef5b86a54fe61c4777d48c93bc;hp=836a43cac97bd011fee9942fb96557f28ee927e5;hb=6ff5ef506bb52b4a98cb7a0b3726f5d3a9637944;hpb=ad24378821413cd0ca0f4f13cc6cc8945fc593ac diff --git a/views.lisp b/views.lisp index 836a43c..6c10296 100644 --- a/views.lisp +++ b/views.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: views.lisp,v 1.55 2003/06/17 04:56:02 kevin Exp $ +;;;; $Id: views.lisp,v 1.60 2003/07/11 18:02:41 kevin Exp $ ;;;; ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg ;;;; ************************************************************************* @@ -16,10 +16,7 @@ (defclass object-view () - ((object-class-name :initform nil :initarg :object-class-name - :accessor object-class-name - :documentation "Name of class of object to be viewed.") - (object-class :initform nil :initarg :object-class + ((object-class :initform nil :initarg :object-class :accessor object-class :documentation "Class of object to be viewed.") (slots :initform nil :initarg :slots :accessor slots @@ -32,6 +29,8 @@ :documentation "Source code for generating view.") (country-language :initform :en :initarg :country-language :documentation "Country's Language for this view.") + (printer :initform nil :initarg :printer :accessor printer + :documentation "default function that prints the object") ;; (file-start-str :type (or string null) :initform nil :initarg :file-start-str :accessor file-start-str) @@ -55,6 +54,14 @@ :accessor obj-end-printer) (obj-end-indent :initform nil :initarg :obj-end-indent :accessor obj-end-indent) + (subobj-start-printer :type (or string function null) :initform nil :initarg :subobj-start-printer + :accessor subobj-start-printer) + (subobj-start-indent :initform nil :initarg :subobj-start-indent + :accessor subobj-start-indent) + (subobj-end-printer :type (or string function null) :initform nil :initarg :subobj-end-printer + :accessor subobj-end-printer) + (subobj-end-indent :initform nil :initarg :subobj-end-indent + :accessor subobj-end-indent) (obj-data-indent :initform nil :initarg :obj-data-indent :accessor obj-data-indent) (obj-data-printer :type (or function null) :initform nil @@ -63,9 +70,15 @@ (obj-data-print-code :type (or function null) :initform nil :initarg :obj-data-print-code :accessor obj-data-print-code) - (obj-data-end-str :type (or string null) :initform nil - :initarg :obj-data-end-str - :accessor obj-data-end-str) + (obj-data-start-printer :type (or function string null) :initform nil + :initarg :obj-data-start-printer + :accessor obj-data-start-printer) + (obj-data-end-printer :type (or string null) :initform nil + :initarg :obj-data-end-printer + :accessor obj-data-end-printer) + (indenter :type (or function null) :initform nil + :accessor indenter + :documentation "Function that performs hierarchical indenting") (link-slots :type list :initform nil :documentation "List of slot names that have hyperlinks" :accessor link-slots) @@ -78,7 +91,7 @@ :accessor link-href-end) (link-ampersand :type (or string null) :initform nil :initarg :link-ampersand :accessor link-ampersand)) - (:default-initargs :link-page "disp-func1") + (:default-initargs :link-page "lookup-func1") (:documentation "View class for a hyperobject")) @@ -91,10 +104,9 @@ it (let ((view (make-instance 'object-view - :object-class-name (class-name obj-class) - :object-class obj-class - :category category - :slots slots))) + :object-class (find-class obj-class) + :category category + :slots slots))) (push view (views obj-class)) view))))) @@ -108,14 +120,12 @@ (setf (default-print-slots cl) (mapcar #'slot-definition-name (class-slots cl)))) (let ((views '())) - (dolist (view-def (views cl)) + (dolist (view-def (direct-views cl)) (push (make-object-view cl view-def) views)) (setf (views cl) (nreverse views))) (cond - ((default-view cl) - (setf (default-view cl) (make-object-view cl (default-view cl)))) - ((car (views cl)) - (setf (default-view cl) (make-object-view cl (car (views cl))))) + ((views cl) + (setf (default-view cl) (car (views cl)))) (t (setf (default-view cl) (make-object-view cl :default))))) @@ -127,44 +137,51 @@ ((eq view-def :default) (let* ((name (class-name cl)) (view (make-instance 'object-view :name "automatic" - :object-class-name name - :object-class cl + :object-class (class-name cl) :category :compact-text))) view)) ((consp view-def) - (apply #'make-instance 'object-view view-def)) + (make-instance 'object-view + :object-class (class-name cl) + :name (getf view-def :name) + :source-code (getf view-def :source-code))) (t (error "Invalid parameter to make-object-view: ~S" view-def)))) -(defmethod initialize-instance :after ((view object-view) - &rest initargs &key &allow-other-keys) - (initialize-view (object-class view) view)) +(defmethod initialize-instance :after ((self object-view) + &rest initargs + &key + &allow-other-keys) + (initialize-view self)) -(defun initialize-view (obj-cl view) +(defun initialize-view (view) "Calculate all view slots for a hyperobject class" - (cond - ((category view) - (initialize-view-by-category obj-cl view)) - ((source-code view) - (initialize-view-by-source-code obj-cl view)) - (t - (setf (category view) :compact-text) - (initialize-view-by-category obj-cl view)))) - -(defun initialize-view-by-source-code (obj-cl view) + (let ((obj-cl (find-class (object-class view)))) + (cond + ((category view) + (initialize-view-by-category obj-cl view)) + ((source-code view) + (initialize-view-by-source-code view)) + (t + (setf (category view) :compact-text) + (initialize-view-by-category obj-cl view))))) + +(defun initialize-view-by-source-code (view) "Initialize a view based upon a source code" - (let ((source-code (source-code view))) - (error "not implemented") - ) - ) + (let* ((source-code (source-code view)) + (*package* (symbol-package (object-class view))) + (printer `(lambda (x s) + (declare (ignorable x s)) + ,@source-code))) + (setf (printer view) + (compile nil (eval printer))))) (defmacro write-simple (v s) `(typecase ,v (string (write-string ,v ,s)) - #+allegro (fixnum - (excl::print-fixnum ,s 10 ,v)) + (write-fixnum ,v ,s)) (symbol (write-string (symbol-name ,v) ,s)) (t @@ -304,7 +321,8 @@ :xhtml :xhtml-labels :xhtml-link-labels :xhtml-link :html-link :xml :xml-labels :xml-link :ie-xml-link - :xml-link-labels :ie-xml-link-labels) + :xml-link-labels :ie-xml-link-labels + :display-table :edit-table) (error "Unknown view category ~A" (category view))) (unless (slots view) (setf (slots view) (default-print-slots obj-cl))) @@ -343,8 +361,10 @@ (case (category view) ((or :compact-text :compact-text-labels) (initialize-text-view view)) - ((or :html :xhtml :html-labels :xhtml-labels) + ((or :html :html-labels) (initialize-html-view view)) + ((or :xhtml :xhtml-labels) + (initialize-xhtml-view view)) ((or :xml :xml-labels) (initialize-xml-view view)) ((or :html-link :html-link-labels) @@ -353,7 +373,7 @@ (setf (link-href-end view) "a") (setf (link-ampersand view) "&")) ((or :xhtml-link :xhtml-link-labels) - (initialize-html-view view) + (initialize-xhtml-view view) (setf (link-href-start view) "a href=") (setf (link-href-end view) "a") (setf (link-ampersand view) "&")) @@ -370,6 +390,12 @@ (setf (link-ampersand view) "&")))) +(defun make-std-object-slots-view (class-name slots) + #'(lambda (obj strm) + ) + + ) + ;;;; ************************************************************************* ;;;; View Data Format Section ;;;; ************************************************************************* @@ -389,48 +415,69 @@ (defun initialize-text-view (view) (setf (list-start-printer view) (compile nil - (eval '(lambda (obj nitems strm) + (eval '(lambda (obj nitems indent strm) + (declare (ignore indent)) (write-user-name-maybe-plural obj nitems strm) (write-char #\: strm) (write-char #\Newline strm))))) (setf (list-start-indent view) t) (setf (obj-data-indent view) t) - (setf (obj-data-end-str view) +newline-string+)) + (setf (obj-data-end-printer view) +newline-string+) + (setf (indenter view) #'indent-spaces)) -(defun html-list-start-func (obj nitems strm) - (write-string "