On Feb 15, 3:42 am, nunb <[email protected]> wrote:
> I have used a general presentation before, it's especially useful for
> last-minute checks on types etc, or to use differing output formatting in
> different places.
>
> :present-as (functioncall :function #'person-show-comma-name) ;; Bagchee,
> Nandan
> :present-as (functioncall :function #'person-show-name) ;;
> Nandan Bagchee
>
> ;; Check for type:
>
> (todo-date :label "Data" :present-as (functioncall :function (f_ (if (typep
> _ 'local-time::timestamp) (timestamp->european-date-string _) "err"))))
Yes, this is right on target; I am sorry that I didn't see this when
I faced my problem. My only additional suggestions would be that a)
there be an additional function option so that you have access to the
entire object since the formatting might depend on another field in
the class, and b) this function be subclassed so that all you would
have to do is give it the formatting string.
So in my attempt at solving this, I have two options, ":present-as
(html-function :on-obj #'some-function)" which can operate on the
entire class object, or ":present-as (html-function :on-value #'some-
function)" which does the same thing as your, more well written,
function above.
What remains to be done is to have the (b) part done which allows a
short hand for simple formatting, e.g. :present-as (value-format "$,
2f")
(export '(html-function html-function-presentation html-function-
presentation-body))
(defclass html-function-presentation (text-presentation)
((on-obj :initform nil
:initarg :on-obj
:accessor html-function-presentation-on-obj
:documentation "Func of the link. This can be a string or a
function that accepts same parameters as
'render-view-field-value'. The function is expected to render
the func into the usual output stream. Its return value is
ignored.")
(on-value :initform nil
:initarg :on-value
:accessor html-function-presentation-on-value)
)
(:documentation "Presents text as a html-function."))
(defmethod render-view-field-value (value (presentation html-function-
presentation)
field view widget obj &rest args
&key highlight &allow-other-keys)
(declare (ignore highlight))
(let ((objfunc (lambda (value presentation field view widget obj
&rest args)
(apply (html-function-presentation-on-obj presentation) (list
obj))))
(valuefunc (lambda (value presentation field view widget obj &rest
args)
(apply (html-function-presentation-on-value presentation)
(list
value)))))
(if (null value)
(call-next-method)
(with-html
(cond
((html-function-presentation-on-obj presentation)
(apply objfunc value presentation field view widget obj
args))
((html-function-presentation-on-value presentation)
(apply valuefunc value presentation field view widget obj
args))
(null (str value)))))))
--
You received this message because you are subscribed to the Google Groups
"weblocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/weblocks?hl=en.