;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: views.lisp,v 1.46 2003/05/22 20:40:03 kevin Exp $
+;;;; $Id: views.lisp,v 1.52 2003/06/12 12:02:31 kevin Exp $
;;;;
;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
;;;; *************************************************************************
-(in-package :hyperobject)
-
-(eval-when (:compile-toplevel :execute)
- (declaim (optimize (speed 2) (safety 2) (compilation-speed 0) (debug 2))))
+(in-package #:hyperobject)
(defclass object-view ()
(link-slots :type list :initform nil
:documentation "List of slot names that have hyperlinks"
:accessor link-slots)
- (link-page-name :type (or string null) :initform nil :initarg :link-page-name
- :accessor link-page-name)
+ (link-page-printer :type (or string function symbol null) :initform nil
+ :initarg :link-page-printer
+ :accessor link-page-printer)
(link-href-start :type (or string null) :initform nil :initarg :link-href-start
:accessor link-href-start)
(link-href-end :type (or string null) :initform nil :initarg :link-href-end
:accessor link-href-end)
(link-ampersand :type (or string null) :initform nil :initarg :link-ampersand
:accessor link-ampersand))
- (:default-initargs :link-page-name "disp-func1")
+ (:default-initargs :link-page-printer "disp-func1")
(:documentation "View class for a hyperobject"))
:category :compact-text)))
view))
((consp view-def)
- (eval `(make-instance ,view-def)))
+ (apply #'make-instance 'object-view view-def))
(t
(error "Invalid parameter to make-object-view: ~S" view-def))))
(let* ((slot-data (slot-value obj name))
(fmt-data (if formatter
(funcall formatter slot-data)
- slot-data))
- (data (if cdata
- (kmrcl:xml-cdata fmt-data)
- fmt-data)))
- (write-simple data strm)))
-
+ slot-data)))
+ (if cdata
+ (write-xml-cdata fmt-data strm)
+ (write-simple fmt-data strm))))
(defun ppfc-html (title name type formatter cdata print-func)
(vector-push-extend '(write-string "<span class=\"" s) print-func)
(defun push-print-fun-code (category slot nlink print-func)
(let* ((formatter (esd-print-formatter slot))
(name (slot-definition-name slot))
- (namestr-lower (string-downcase (symbol-name name)))
- (xml-namestr (escape-xml-string namestr-lower))
- (xml-tag (escape-xml-string namestr-lower))
+ (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))
(cdata (not (null
(and (in category :xml :xhtml :xml-link :xhtml-link
(vector-push-extend
`(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
(:compact-text-labels
- (vector-push-extend `(write-string ,namestr-lower s) print-func)
+ (vector-push-extend `(write-string ,user-name s) print-func)
(vector-push-extend '(write-char #\space s) print-func)
(vector-push-extend
`(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
((or :html :xhtml)
- (ppfc-html namestr-lower name type formatter cdata print-func))
+ (ppfc-html user-name name type formatter cdata print-func))
(:xml
(ppfc-xml xml-tag name type formatter cdata print-func))
(:html-labels
- (ppfc-html-labels namestr-lower name type formatter cdata print-func))
+ (ppfc-html-labels user-name name type formatter cdata print-func))
(:xhtml-labels
- (ppfc-xhtml-labels xml-namestr namestr-lower name type formatter cdata print-func))
+ (ppfc-xhtml-labels xml-user-name user-name name type formatter cdata print-func))
(:xml-labels
- (ppfc-xml-labels xml-namestr xml-tag name type formatter cdata print-func))
+ (ppfc-xml-labels xml-user-name xml-tag name type formatter cdata print-func))
((or :html-link :xhtml-link)
(if hyperlink
(ppfc-html-link name type formatter cdata nlink print-func)
- (ppfc-html namestr-lower name type formatter cdata print-func)))
+ (ppfc-html user-name name type formatter cdata print-func)))
((or :xml-link :ie-xml-link)
(if hyperlink
(ppfc-html-link name type formatter cdata nlink print-func)
(ppfc-xml xml-tag name type formatter cdata print-func)))
(:html-link-labels
(if hyperlink
- (ppfc-html-link-labels namestr-lower name type formatter cdata nlink
+ (ppfc-html-link-labels user-name name type formatter cdata nlink
print-func)
- (ppfc-html-labels namestr-lower name type formatter cdata print-func)))
+ (ppfc-html-labels user-name name type formatter cdata print-func)))
(:xhtml-link-labels
(if hyperlink
- (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
+ (ppfc-html-link-labels xml-user-name name type formatter cdata nlink
print-func)
- (ppfc-xhtml-labels xml-tag namestr-lower name type formatter cdata
+ (ppfc-xhtml-labels xml-tag user-name name type formatter cdata
print-func)))
((or :xml-link-labels :ie-xml-link-labels)
(if hyperlink
- (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
+ (ppfc-html-link-labels xml-user-name name type formatter cdata nlink
print-func)
- (ppfc-xml-labels xml-tag namestr-lower name type formatter cdata
+ (ppfc-xml-labels xml-tag user-name name type formatter cdata
print-func))))))
(when (and (view-has-links-p view) (esd-hyperlink slot))
(push (slot-definition-name slot) links)))
- (when (plusp (length print-func))
- (setf (obj-data-print-code view) `(lambda (x s links)
- (declare (ignorable links))
- ,@(map 'list #'identity print-func)))
- (setf (obj-data-printer view)
- (compile nil (eval (obj-data-print-code view)))))
+ (vector-push-extend 'x print-func) ;; return object
+ (setf (obj-data-print-code view) `(lambda (x s links)
+ (declare (ignorable s links))
+ ,@(map 'list #'identity print-func)))
+ (setf (obj-data-printer view)
+ (compile nil (eval (obj-data-print-code view))))
(setf (link-slots view) (nreverse links)))
(with-output-to-string (s)
(write-string (link-href-start view) s)
(write-char #\" s)
- (write-string (make-url (link-page-name view)) s)
- (write-string "?func=" s)
- (write-simple fieldfunc s)
- (write-string (link-ampersand view) s)
- (write-string "key=" s)
- (write-simple fieldvalue s)
- (dolist (var refvars)
- (write-string (link-ampersand view) s)
- (write-simple (car var) s)
- (write-char #\= s)
- (write-simple (cdr var) s))
- (write-char #\" s)))
+ (let ((link-page (link-page-printer view)))
+ (typecase link-page
+ (string
+ (write-string (make-url link-page) s)
+ (write-string "?func=" s)
+ (write-simple fieldfunc s)
+ (write-string (link-ampersand view) s)
+ (write-string "key=" s)
+ (write-simple fieldvalue s)
+ (dolist (var refvars)
+ (write-string (link-ampersand view) s)
+ (write-simple (car var) s)
+ (write-char #\= s)
+ (write-simple (cdr var) s))
+ (write-char #\" s))
+ (null
+ nil)
+ ((or symbol function)
+ (funcall link-page fieldfunc fieldvalue refvars s))))))
(defun make-link-end (obj view fieldname)
(declare (ignore obj fieldname))
(defun view-hyperobject (objs view category strm &optional (indent 0) filter
subobjects refvars)
"Display a single or list of hyperobject-class instances and their subobjects"
- (declare (fixnum indent))
(let-when (objlist (mklist objs))
(let ((nobjs (length objlist))
(*print-pretty* nil)
(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)
+ (view-hyperobject it
+ (get-category-view (car (mklist it))
+ category)
category strm (1+ indent) filter
subobjects refvars))))
(fmt-obj-end obj view strm indent)))
(defun view (objs &key (stream *standard-output*) category view
filter subobjects refvars file-wrapper)
- "EXPORTED Function: prints hyperobject-class objects. Simplies call to view-hyperobject"
+ "EXPORTED Function: prints hyperobject-class objects. Calls view-hyperobject"
(let-when (objlist (mklist objs))
(when category
(setq view (get-category-view (car objlist) category)))