[Bese-devel] Introduction and questions...
Drew Crampsie
drewc at tech.coop
Sat Nov 12 13:11:33 UTC 2005
Jan Rychter wrote:
> One immediate comment on what we have now: I don't think I will ever use
> its automated presentation facilities (things like generating form
> labels from the names of CLOS slots). I believe that in all practical
> applications (e.g. code that is used by users, not developers) one will
> want to have an object specifying the interface and one will want to
> provide names and paramerers for all form elements.
>
> In general, presentation-type approach seems neat in theory, but is
> usually too strict in practice. For example, viewing data and accepting
> data are completely different things in most web applications -- you
> usually view data grouped in tables and you accept it on a per-item
> basis in forms. I can't fit that into a presentation framework without
> a lot of pain.
My Lisp-on-Lines framework 'solves' (fsvo solves) this problem by using
a presentation system that is more dynamic in nature. For example :
(defclass simple-content (content)
((title :accessor title :initarg :title :initform "")
(show-title-p :accessor show-title-p :initarg :show-title-p :initform t)
(body :accessor body :initarg :body :initform "")))
(lol:define-meta-model simple-content ()
((title :type string)
(body :type string)
(name :type string)
(show-title-p :type boolean)))
(lol:set-default-attributes 'simple-content)
Obviously, these three forms should be combined into a "DEFCLASS/META"
macro, but i have not yet gotten around to it.
With that information, you have enough to display a default
viewer/editor/creator/one-line/as-string or another view of the object.
There are some simple macros for handling that sort of thing, all of
them share a simple syntax, so you can do something like "
(lol:call-view ((make-instance 'simple-content) :editor)
(name title body))
and all the details are hidden away for you. For the most part, the
default attributes are not enough, so LoL makes it real easy to modify :
(lol:define-attributes (simple-content faq-item)
(body mewa::text)
(show-title-p mewa::mewa-boolean)
(:one-line t :attributes (title))
(:viewer content-viewer)
(:editor
content-editor
:attributes (name title show-title-p (body :type dojo-editor)))
(:creator
content-editor
:attributes (name title show-title-p (body :type dojo-editor))))
A lot of the time, the default object presentations are enough (the T in
the :one-line means 'use the default', though in this case, i needed a
custom presentation:
(defcomponent content-presentation (lol::mewa-viewer)
())
(defmethod lol:present ((self content-presentation))
(<:div :class "content"
(when (show-title-p (lol:instance self))
(<:h2 (lol:present-slot-view self 'title)))
(lol:present-slot-view self 'body)
(when (editablep self)
(<ucw:a :action (lol:call-view ((lol:instance self) :editor))
(<:as-html "edit")))))
Note that you _never_ have to manually create INPUT tags, this is all
handled by the mewa system. All you have to do is declare a slot
editable (either in define-attributes, or when using CALL-VIEW,
PRESENT-VIEW, MAKE-VIEW and friends.
The system actually works, and works well, i have delivered commercial
applications using LoL, and, minus a few memory leak (which i've just
located), everything is working really well.
For those few instances where the defaults don't handle it, it is
trivial to create custom presentation objects and get all the
flexibility one needs.
The next version (lol 0.2) will use contextL in the backend to avoid the
current mess of conditionals in the presentation objects:
;;; a PITA :
(cond ((editablep foo)
... editing code)
((linkedp foo)
(<ucw:a :Action (foo foo) .....))
But the syntax should remain untouched.
> Overall, what I'm looking for is an API where I'd use a minimal number
> of lines of code, but where I'd still get reasonable
> flexibility. Quoting Einstein: "Everything should be made as simple as
> possible, but not simpler."
LoL probably meets your needs, and is available just by mailing me and
asking _really_ nice :).
In the event that UCW ends up with a great forms library, it would be
simple to change LoL to use it underneath, although, LoL itself could
probably be used to make a great form library for UCW, but that is
neither here nor there right now.
An LoL release (0.1) is forthcoming, if anybody wants to
help/play/insult my lack of forsight, just drop me a line.
drewc
>
> --J.
> _______________________________________________
> bese-devel mailing list
> bese-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/bese-devel
More information about the bese-devel
mailing list