On 4 Oct, 04:54, Nandan Bagchee <[email protected]> wrote:

[snip]

> Many people wonder how to handle URL tokens to make their widgets do
> different things, but looking at how plain nav works doesn't yield a
> solution. Or at least, handling URLs in this way seems to be a common
> question / initial stumbling block on this newsgroup.
>
> Could you post an abbreviated example of your widget? Inline would be best I
> think, to help people find the answer right away, or that and a gist.
>
> cheers,
>  Nandan

I currently have something along these lines:

;
; An example of prefix-based dispatch for Weblocks.
;
; This code allows you to have URLs like http://foo/details/callsign
and
; http://foo/limited/callsign, and dispatch to different widgets based
on
; pattern matching. In this case we dispatch to one widget for /
details
; and another for /limited, in both cases passing callsign to the
; target widget.
;
; Error handling is left as an exercise for the reader ;)
;
(defwidget prefix-selector (on-demand-selector)
  ()
  (:default-initargs :lookup-function #'galosh-selector)
  (:documentation "Foo"))

(defun galosh-selector (selector tokens)
  (cond ((equal (first tokens) "details")
(values (make-instance 'log-details :call (second tokens) :cols
*detail-columns*)
tokens nil :no-cache))
((equal (first tokens) "limited")
(values (make-instance 'log-details :call (second tokens) :cols
*limited-columns*)
tokens nil :no-cache))
(t
(values (make-instance 'funcall-widget :fun-designator (lambda (&rest
args)
(with-html (:p "Something else"))))
(car tokens) (cdr tokens)))))

(defwidget log-details ()
  ((call :accessor log-widget-call :initform nil :initarg :call)
   (cols :accessor log-widget-cols :initform *limited-
columns* :initarg :cols)))

(defmethod render-widget-body ((widget log-details) &rest args)
   ; your rendering code here)

(defun init-user-session (comp)
  (setf (composite-widgets comp)
    (make-instance 'prefix-selector)))


Nicer formatting at http://gist.github.com/613796

--
Mike

-- 
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.

Reply via email to