X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=inline;f=views.lisp;h=6c102965ef1cbfef5b86a54fe61c4777d48c93bc;hb=6ff5ef506bb52b4a98cb7a0b3726f5d3a9637944;hp=6776e39e1bc57a8455aa4a7711f09e7a4de281e4;hpb=3537a8422aeb2817b41ee835c5ff45ba1d973c98;p=hyperobject.git diff --git a/views.lisp b/views.lisp index 6776e39..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.56 2003/06/17 17:50:45 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) @@ -92,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")) @@ -105,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))))) @@ -122,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))))) @@ -141,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 @@ -318,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))) @@ -386,6 +390,12 @@ (setf (link-ampersand view) "&")))) +(defun make-std-object-slots-view (class-name slots) + #'(lambda (obj strm) + ) + + ) + ;;;; ************************************************************************* ;;;; View Data Format Section ;;;; ************************************************************************* @@ -406,6 +416,7 @@ (setf (list-start-printer view) (compile nil (eval '(lambda (obj nitems indent strm) + (declare (ignore indent)) (write-user-name-maybe-plural obj nitems strm) (write-char #\: strm) (write-char #\Newline strm))))) @@ -415,7 +426,9 @@ (setf (indenter view) #'indent-spaces)) (defun html-list-start-func (obj nitems indent strm) - (write-string "