X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/b8c8985156e0ce7de77973d5899221116dcc3c96..87e47dd67949ba2d7e8e95912517d7d6366a303c:/src/lisp-on-lines.lisp diff --git a/src/lisp-on-lines.lisp b/src/lisp-on-lines.lisp index a5415ae..3c02bd9 100644 --- a/src/lisp-on-lines.lisp +++ b/src/lisp-on-lines.lisp @@ -8,8 +8,41 @@ ;;;; or Meta-Model. ;;;; ** Initialisation +(defmethod find-default-attributes ((object t)) + "return the default attributes for a given object using the meta-model's meta-data" + (append (mapcar #'(lambda (s) + (cons (car s) + (gen-pslot + (if (meta-model:foreign-key-p object (car s)) + 'foreign-key + (cadr s)) + (string (car s)) (car s)))) + (meta-model:list-slot-types object)) + (mapcar #'(lambda (s) + (cons s (append (gen-pslot 'has-many (string s) s) + `(:presentation + (make-presentation + ,object + :type :one-line))))) + (meta-model:list-has-many object)) + (find-default-presentation-attribute-definitions))) + +(defmethod set-default-attributes ((object t)) + "Set the default attributes for MODEL" + (clear-attributes object) + (mapcar #'(lambda (x) + (setf (find-attribute object (car x)) (cdr x))) + (find-default-attributes object))) + +;;;; This automagically initialises any meta model + +(eval-when (:compile-toplevel :load-toplevel :execute) + (defmethod meta-model::generate-base-class-expander :after (meta-model name args) + (set-default-attributes name))) + ;;;; The following macros are used to initialise a set of database tables as LoL objects. + (eval-when (:compile-toplevel :load-toplevel :execute) (defun generate-define-view-for-table (table) " @@ -30,18 +63,24 @@ This involves creating a meta-model, a clsql view-class, and the setting up the "expands to init-i-f-t using the listing of tables provided by meta-model" `(define-view-for-table ,@(meta-model::list-tables))) + + +;;;; These are some macros over the old presentation system. +;;;; Considered depreciated, they will eventually be implemented in terms of the new +;;;; display system, and delegated to backwards-compat-0.2.lisp + (eval-when (:compile-toplevel :load-toplevel :execute) (defun %make-view (object type attributes args) - (when attributes - (setf args - (cons `(:attributes ,attributes) args))) - `(mewa::make-presentation - ,object - :type ,type - ,@(when args - `(:initargs - '(,@ (mapcan #'identity args))))))) + (when attributes + (setf args + (cons `(:attributes ,attributes) args))) + `(mewa::make-presentation + ,object + :type ,type + ,@(when args + `(:initargs + '(,@ (mapcan #'identity args))))))) (defmethod make-view (object &rest args &key (type :viewer) &allow-other-keys ) @@ -72,7 +111,11 @@ This involves creating a meta-model, a clsql view-class, and the setting up the (mewa::find-attribute-slot self slot-name)) (defmethod present-slot-view ((self mewa) slot-name &optional (instance (instance self))) - (present-slot (slot-view self slot-name) instance)) + (let ((v (slot-view self slot-name))) + + (if v + (present-slot v instance) + (<:as-html slot-name)))) (defmethod find-slots-of-type (model &key (type 'string)