Wednesday, October 22nd, 2008
Kevin Dangoor from SitePen recently announced the release of a small pet project: Reinhardt. From the blog:
A typical server-side web framework today includes three main components: a URL dispatching to some controller object scheme, a template engine, and a data mapping facility. Currently in Dojo, you’ll find that the latter two items already exist. dojox.dtl provides the first one, and dojo.data provides the second.
Given that Dojo already offers an implementation of the Django template engine, and that regular expression-based URL dispatch was a good fit for our problem at hand, I decided to [create a] URL dispatch on the model provided by Django.
Reinhardt is the name I gave to this client-side web framework.
Using Reinhardt, you pair regular expressions to method calls:
- var patterns = reinhardt.urldispatch.patterns("demo.code",
- [/^list\/(\d*)$/, "showMovieList", ["year"]],
- [/^search$/, "search"],
(The first argument to the
patterns function provides the URL prefix required for Reinhardt to dispatch a URL.)
Hacking Support for Groups
- [/^movie\/(\d+)\/$/, "whatyear", ['id']],
- [/^movie\/([\w ]+)\/$/, "whatyear", ["name"]],
Kevin explains further about this feature:
These two entries show that the patterns are matched in order. movie/10/ would match both of the expressions. But, movie/Cars/ will only match the second. If the first one is a match, demo.code.whatyear is called with an ‘id’ attribute on the parameters object. If the second matches, there will be a ‘name’ attribute passed to that same function.
Kevin imagines a future where this hack could go away:
Not Quite a Project Yet
At this point, it simply offers URL dispatch. I can imagine a client-side framework offering tools to help you organize large Dojo-based applications in easy to understand, simple to grow manner. The built-in URL dispatch could also provide automatic history and back button support. For now, however, it is just a small bit of code to make client-side URL dispatch clean and simple.
I should note at this point that Reinhardt is more of a demo than a real open source project. However, it is a straightforward implementation and includes unit tests, so you can confidently use it for real URL dispatch work.
Posted by Ben Galbraith at 7:00 am