;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: views.lisp,v 1.58 2003/06/23 20:08:06 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
;;;; *************************************************************************
(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
: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)
: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"))
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)))))
(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)))))
((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)))
- (warn "source code compilation is 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
(write-char #\newline strm))
(defun initialize-xml-view (view)
- (initialize-text-view view)
(setf (file-start-str view) "") ; (std-xml-header)
(setf (list-start-indent view) t)
(setf (list-start-printer view) #'xmlformat-list-start-func)
(setf (list-end-printer view) #'xmlformat-list-end-func)
(setf (obj-start-printer view) (format nil "<~(~a~)>" (object-class-name view)))
(setf (obj-start-indent view) t)
- (setf (subobj-end-printer view) (format nil "</~(~a~)>" (object-class-name view)))
+ (setf (subobj-end-printer view) (format nil "</~(~a~)>~%" (object-class-name view)))
(setf (subobj-end-indent view) nil)
(setf (obj-data-indent view) nil))
(load-all-subobjects it))))
objs)
-(defun view-hyperobject (objs view category strm &optional (indent 0) filter
+(defun view-subobjects (obj strm &optional category (indent 0) filter
+ subobjects refvars link-printer)
+ (when (hyperobject-class-subobjects obj)
+ (dolist (subobj (hyperobject-class-subobjects obj))
+ (aif (slot-value obj (name-slot subobj))
+ (view-hyperobject
+ it (get-category-view (car (mklist it)) category)
+ category strm (1+ indent) filter subobjects refvars
+ link-printer)))))
+
+
+(defun view-hyperobject (objs view strm &optional category (indent 0) filter
subobjects refvars link-printer)
"Display a single or list of hyperobject-class instances and their subobjects"
(let-when (objlist (mklist objs))
(*print-level* nil))
(fmt-list-start (car objlist) view strm indent nobjs)
(dolist (obj objlist)
- (unless (and filter (not (funcall filter obj)))
- (fmt-obj-start obj view strm indent)
- (fmt-obj-data obj view strm (1+ indent) refvars link-printer)
- (fmt-obj-end obj view strm indent)
- (fmt-subobj-start obj view strm indent)
- (when (and subobjects (hyperobject-class-subobjects obj))
- (dolist (subobj (hyperobject-class-subobjects obj))
- (aif (slot-value obj (name-slot subobj))
- (view-hyperobject it
- (get-category-view (car (mklist it))
- category)
- category strm (1+ indent) filter
- subobjects refvars link-printer))))
- (fmt-subobj-end obj view strm indent)))
+ (awhen (printer view)
+ (funcall it obj strm))
+ (unless (and filter (not (funcall filter obj)))
+ (fmt-obj-start obj view strm indent)
+ (fmt-obj-data obj view strm (1+ indent) refvars link-printer)
+ (fmt-obj-end obj view strm indent)
+ (when subobjects
+ (fmt-subobj-start obj view strm indent)
+ (view-subobjects obj category strm indent filter subobjects
+ refvars link-printer)
+ (fmt-subobj-end obj view strm indent))))
(fmt-list-end (car objlist) view strm indent nobjs)))
objs)
(setq view (default-view (class-of (car objlist)))))
(when file-wrapper
(fmt-file-start view stream))
- (view-hyperobject objlist view category stream 0 filter subobjects refvars
+ (view-hyperobject objlist view stream category 0 filter subobjects refvars
link-printer)
(when file-wrapper
(fmt-file-end view stream)))