Dispatcher class

7 views
Skip to first unread message

Trastabuga

unread,
Apr 6, 2010, 11:17:18 AM4/6/10
to weblocks
I've read in a number of tutorials and posts references to a
Dispatcher class but I couldn't find any traces of it in neither Dev
nor Stable branches.
Still, I think that would be an extremely useful class to have as it
would enable users do things that they can't do with the navigation
widget.
Any plans to include this class in the framework?

Leslie P. Polzer

unread,
Apr 6, 2010, 12:30:53 PM4/6/10
to webl...@googlegroups.com

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

Trastabuga

unread,
Apr 6, 2010, 1:09:22 PM4/6/10
to weblocks
How do I combine Navigation + on-demand-selector? If I try something
like that, it doesn't actually map the the "static" url to the text
widget.
(defun make-home-page ()
(let* ((tests (make-tests-page))
(navigation (make-navigation "Navigation"
"admin" (make-config-page)
"tests" tests))
(on-demand (make-instance 'static-selector
:panes (list (cons "static" "some
test page")))))
(make-instance 'composite
:widgets
(list navigation on-demand))))

What is missing?

On Apr 6, 12:30 pm, "Leslie P. Polzer" <s...@viridian-project.de>
wrote:

nunb

unread,
Apr 7, 2010, 2:24:16 AM4/7/10
to weblocks
Something to get started with: http://paste.lisp.org/+236G

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")))

nunb

unread,
Apr 7, 2010, 2:41:25 AM4/7/10
to weblocks
Add a menu-ish widget (to display an archive-like summary by tag,
author, and date)

http://paste.lisp.org/+236G/1

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?

Leslie P. Polzer

unread,
Apr 7, 2010, 7:22:38 AM4/7/10
to weblocks
On Apr 7, 8:41 am, nunb <nandan.bagc...@gmail.com> wrote:
> Add a menu-ish widget (to display an archive-like summary by tag,
> author, and date)
>
> http://paste.lisp.org/+236G/1
>
> Can someone tell me if this is a good idea?

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

nunb

unread,
Apr 7, 2010, 7:52:48 AM4/7/10
to weblocks
> > 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?

Trastabuga is, I think :-P

And is aggieben around?

http://github.com/nunb/resty-weblocgks/

Trastabuga

unread,
Apr 7, 2010, 11:50:44 AM4/7/10
to weblocks
I really liked the idea of a dispatcher you proposed at
http://github.com/nunb/resty-weblocgks/
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.
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.
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.
Sure, I'd like to help as much as I can.

Andrei

Message has been deleted

nunb

unread,
Apr 7, 2010, 9:31:25 PM4/7/10
to weblocks
Sorry, my previous post was too rambling.

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

nunb

unread,
Apr 12, 2010, 2:23:09 AM4/12/10
to weblocks

> Use hunchentoot-create-prefix-dispatcher or the equivalent h-c-regex-d

Apologies, the above does not work as I had expected.

http://paste.lisp.org/+23D2/2

nunb

unread,
Apr 12, 2010, 2:45:26 AM4/12/10
to weblocks

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.

Reply all
Reply to author
Forward
0 new messages