Yes: the dispatcher class was introduced some two years ago.
Its current name is 'selector' with a convenience subclass that is
very similar to the old dispatcher class called 'on-demand-selector'.
Check out these source files:
weblocks/src/widgets/selector.lisp
weblocks/src/widgets/on-demand-selector.lisp
They contain lots of documentation.
Feel free to ask more about it around here.
Leslie
What is missing?
On Apr 6, 12:30 pm, "Leslie P. Polzer" <s...@viridian-project.de>
wrote:
Intended to handle urls like /tags/foo/bar/baz, /author/author-name
(and /posts/post-name, /2009/Aug/01/ etc. can be added)
---- pasted ---
(in-package :simple-blog)
;; Define callback function to initialize new sessions
(defun init-user-session (comp)
(setf (composite-widgets comp)
(make-instance 'nunb-blog-toplevel)))
(defwidget nunb-blog-toplevel (on-demand-selector)
((menu-widget :documentation "Show a menu-standin .. TODO"))
(:default-initargs :lookup-function #'blog-selector-choose-post))
(defmethod blog-selector-choose-post (selector tokens)
"Given the selector and a set of tokens, return the blog post, or
carp if not found.
Because of the way the toplevel is called, it will also be the
resp. of this fn. to
return a menu-ish widget that shows what url paths are available
(ie the monthly archive
sidebar that most blogs have). We'll start with english, and as an
exercise see how hard
it would be to add other languages."
(break (format nil "TOKENS ~{~S, ~} ~%" tokens))
(cond
((equal (first tokens) "tags")
(values (make-instance 'funcall-widget :fun-designator (lambda
(&rest args)
(with-html (:div "Search posts by tags"))))
tokens nil))
((equal (first tokens) "author")
(values (make-instance 'funcall-widget :fun-designator
(lambda (&rest args)
(with-html (:div "Search posts by author"))))
tokens nil))
(t ;; Handle year/month/date and year/month/title
(make-instance 'funcall-widget :fun-designator (lambda (&rest
args)
(with-html (:div "Fell through to year/month/date and year/
month/title case"))))
))
)
(defclass* tagged-item ()
((tags :documentation "Use tags")))
(defclass* nunb-post (post)
((ts :documentation "I like timestamps")))
Can someone tell me if this is a good idea? The dispatcher will return
a widget that is a composite of the menu widget and the post that was
found (or a post-not-found widget). The menuish-widget won't explictly
be added to the widget-tree, but rather the dispatcher'll take care of
rendering it..
I cannot think of another way to handle REST urls, but it's worth a
shot:
Q: can a parent selector return a menuish-widget, *not* consume any
tokens, and delegate the rest of the ui (finding and displaying a post
or not-found message) to another dispatcher? How would the code look
in that case?
It also may be instructive to put this up on github with accompanying
commentary as to how one'd go about developing a blog (with
"mainstream features" :-) that intends to look like, say
blogspot.com .. any collaborators?
After a quick review I can't see any major problems.
Depends on the app too, as usual.
> I cannot think of another way to handle REST urls, but it's worth a
> shot:
>
> Q: can a parent selector return a menuish-widget, *not* consume any
> tokens, and delegate the rest of the ui (finding and displaying a post
> or not-found message) to another dispatcher? How would the code look
> in that case?
It's very simple. You just return the widget (i.e. the sub-
dispatcher), NIL
as consumed tokens and the full list of tokens as remaining tokens.
The tree walk for dispatch will then continue at the sub-dispatcher
level.
> It also may be instructive to put this up on github with accompanying
> commentary as to how one'd go about developing a blog (with
> "mainstream features" :-) that intends to look like, say
> blogspot.com .. any collaborators?
No time right now, sorry. :/ But perhaps someone else would be
interested in working on this as a learning experience?
Leslie
Trastabuga is, I think :-P
And is aggieben around?
Andrei
> When I just started with hunchentoot a while ago and wrote a little
> web site I had never had problems with displaying menu and making REST-
> style urls.
Selectors have several advantages:
1. modular & maintainable
2. better security / app design
3. caching of widgets at URLs
> I think Weblocks should give a user an easy way to get down to the
> hunchentoot dispatcher (maybe Weblocks already has it, I just couldn't
> figure it out) and map any widget to any url regular expression or
> function.
Use hunchentoot-create-prefix-dispatcher or the equivalent h-c-regex-
d
> I think that navigation control should be extended so that it would
> allow some kind of regex-url to widget mapping (or funcall-widget to
> widget mapping) and the ability to redraw itself based on the
> currently selected url.
You can subclass the navigation widget, and write a custom get-widget-
for-tokens method to accomplish this.
Apologies, the above does not work as I had expected.
Double apologies (meta-apology?) ..it does work, I had linked to
pre-1.0 hunchentoot by mistake.
http://paste.lisp.org/+23D3 has the working code.