X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=views.lisp;h=a90064ad5197f0fa1a4919a8999c2fb21684e1e5;hb=de7eaca7f5f852ffb39102ecaa3e3368c4306faf;hp=b8074830479fe8f40096c7fc3cae324858ced219;hpb=15567a20f92d9af44aaba8b8c697b215215816fa;p=hyperobject.git
diff --git a/views.lisp b/views.lisp
index b807483..a90064a 100644
--- a/views.lisp
+++ b/views.lisp
@@ -11,7 +11,7 @@
;;;;
;;;; This file is Copyright (c) 2000-2004 by Kevin M. Rosenberg
;;;; *************************************************************************
-
+
(in-package #:hyperobject)
@@ -23,7 +23,7 @@
:documentation "List of effective slots for object to be viewed.")
(id :initform nil :initarg :id :accessor id
:documentation "id for this view.")
- (source-code :initform nil :initarg :source-code :accessor source-code
+ (source-code :initform nil :initarg :source-code :accessor source-code
:documentation "Source code for generating view.")
(country-language :initform :en :initarg :country-language
:documentation "Country's Language for this view.")
@@ -65,7 +65,7 @@
(obj-data-printer :type (or function null) :initform nil
:initarg :obj-data-printer
:accessor obj-data-printer)
- (obj-data-print-code :type (or function null) :initform nil
+ (obj-data-print-code :type (or function list null) :initform nil
:initarg :obj-data-print-code
:accessor obj-data-print-code)
(obj-data-start-printer :type (or function string null) :initform nil
@@ -111,8 +111,8 @@
(make-instance (class-name obj-cl))
(setq cpl (class-precedence-list obj-cl))))
(find-view-id-in-class-precedence (second cpl) vid)))))
-
-
+
+
(defun get-view-id (obj vid &optional slots)
"Find or make a category view for an object"
(let ((obj-cl (class-of obj)))
@@ -147,7 +147,7 @@
((typep view-def 'object-view)
view-def)
((eq view-def :default)
- (make-instance 'object-view
+ (make-instance 'object-view
:object-class (class-name cl)
:id :compact-text))
((consp view-def)
@@ -160,11 +160,12 @@
(error "Invalid parameter to make-object-view: ~S" view-def))))
(defmethod initialize-instance :after ((self object-view)
- &rest initargs
+ &rest initargs
&key
&allow-other-keys)
+ (declare (ignore initargs))
(initialize-view self))
-
+
(defun initialize-view (view)
"Calculate all view slots for a hyperobject class"
(let ((obj-cl (find-class (object-class view))))
@@ -183,20 +184,20 @@
"Initialize a view based upon a source code"
(let* ((source-code (source-code view))
(printer `(lambda
- (,(intern (symbol-name '#:self)
+ (,(intern (symbol-name '#:self)
(symbol-package (object-class view)))
- ,(intern (symbol-name '#:s)
+ ,(intern (symbol-name '#:s)
(symbol-package (object-class view))))
- (declare (ignorable
- ,(intern (symbol-name '#:self)
+ (declare (ignorable
+ ,(intern (symbol-name '#:self)
(symbol-package (object-class view)))
- ,(intern (symbol-name '#:s)
+ ,(intern (symbol-name '#:s)
(symbol-package (object-class view)))))
- (with-slots ,(slots view)
- ,(intern (symbol-name '#:self)
+ (with-slots ,(slots view)
+ ,(intern (symbol-name '#:self)
(symbol-package (object-class view)))
,@source-code))))
- (setf (printer view)
+ (setf (printer view)
(compile nil (eval printer)))))
(defmacro write-simple (v s)
@@ -240,7 +241,7 @@
(vector-push-extend '(write-string "
" s) print-func)
(ppfc-html title name type formatter cdata print-func)
(vector-push-extend '(write-string " | " s) print-func))
-
+
(defun ppfc-html-labels (label name type formatter cdata print-func)
(vector-push-extend '(write-string "" s) print-func)
(vector-push-extend `(write-string ,label s) print-func)
@@ -262,11 +263,11 @@
(defun ppfc-html-link (name type formatter cdata nlink print-func)
(declare (fixnum nlink))
(vector-push-extend '(write-char #\< s) print-func)
- (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func)
+ (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func)
(vector-push-extend '(write-char #\> s) print-func)
(vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
(vector-push-extend '(write-string "" s) print-func)
- (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func)
+ (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func)
(vector-push-extend '(write-char #\> s) print-func))
(defun ppfc-html-link-labels (label name type formatter cdata nlink print-func)
@@ -281,7 +282,8 @@
(user-name (esd-user-name slot))
(xml-user-name (escape-xml-string user-name))
(xml-tag (escape-xml-string user-name))
- (type (slot-value slot 'type))
+ (type (slot-definition-type slot))
+
(cdata (not (null
(and (in vid :xml :xhtml :xml-link :xhtml-link
:xml-labels :ie-xml-labels
@@ -290,7 +292,7 @@
(or formatter
(lisp-type-is-a-string type))))))
(hyperlink (esd-hyperlink slot)))
-
+
(case vid
(:compact-text
(vector-push-extend
@@ -359,11 +361,11 @@
"Initialize a view based upon a preset vid"
(unless (creatable-view-id-p obj-cl (id view))
(error "Unable to automatically create view id ~A" (id view)))
-
+
(unless (slots view) (setf (slots view) (default-print-slots obj-cl)))
(let ((links '())
- (print-func (make-array 10 :fill-pointer 0 :adjustable t)))
+ (print-func (make-array 20 :fill-pointer 0 :adjustable t)))
(do* ((slots (slots view) (cdr slots))
(slot-name (car slots) (car slots))
@@ -372,7 +374,7 @@
((null slots))
(unless slot
(error "Slot ~A is not found in class ~S" slot-name obj-cl))
-
+
(push-print-fun-code (id view) slot (length links) print-func)
(when (> (length slots) 1)
(vector-push-extend '(write-char #\space s) print-func))
@@ -386,7 +388,7 @@
,@(map 'list #'identity print-func)))
(setf (obj-data-printer view)
(compile nil (eval (obj-data-print-code view))))
-
+
(setf (link-slots view) (nreverse links)))
(finalize-view-by-id view)
@@ -589,6 +591,7 @@
(setf (list-end-printer view) #'xmlformat-list-end-func)
(setf (obj-start-printer view) (format nil "<~(~a~)>" name))
(setf (obj-start-indent view) t)
+ (setf (obj-end-printer view) (format nil "~(~a~)>~%" name))
(setf (subobj-end-printer view) (format nil "~(~a~)>~%" name))
(setf (subobj-end-indent view) nil)
(setf (obj-data-indent view) nil)))
@@ -640,7 +643,7 @@
(defun fmt-obj-end (obj view strm indent)
(when (obj-end-indent view)
(awhen (indenter view)
- (funcall it indent strm)))
+ (funcall it indent strm)))
(awhen (obj-end-printer view)
(if (stringp it)
(write-string it strm)
@@ -658,13 +661,13 @@
(defun fmt-subobj-end (obj view strm indent)
(when (subobj-end-indent view)
(awhen (indenter view)
- (funcall it indent strm)))
+ (funcall it indent strm)))
(awhen (subobj-end-printer view)
(if (stringp it)
(write-string it strm)
(funcall it obj strm))))
-
-;;; Object Data
+
+;;; Object Data
(defun make-link-start (view fieldfunc fieldvalue refvars link-printer)
@@ -688,7 +691,7 @@
(link-printer
(funcall link-printer link-page fieldfunc fieldvalue refvars s))))
(write-char #\" s)))
-
+
(defun make-link-end (obj view fieldname)
(declare (ignore obj fieldname))
(link-href-end view))
@@ -751,7 +754,7 @@
strm vid (1+ indent) filter subobjects refvars
link-printer)))))
-
+
(defun view-hyperobject (objs view strm &optional vid (indent 0) filter
subobjects refvars link-printer)
"Display a single or list of hyperobject-class instances and their subobjects"
@@ -771,11 +774,13 @@
(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 strm vid indent filter subobjects
- refvars link-printer)
- (fmt-subobj-end obj view strm indent))))
+ (if subobjects
+ (progn
+ (fmt-subobj-start obj view strm indent)
+ (view-subobjects obj strm vid indent filter subobjects
+ refvars link-printer)
+ (fmt-subobj-end obj view strm indent))
+ (fmt-subobj-start obj view strm indent))))
(fmt-list-end (car objlist) view strm indent nobjs)))
objs)