Routes 1.1 Preview
The major feature I was waiting on for Routes 1.1 is for the most part done, mainly adding more unit tests for the new syntax now. As I mentioned previously when announcing Routes 1.0, this feature is the one quite a few people have been waiting for. The ability to split the route path somewhere other than on a /.
map.connect(':category/:(page).html', controller='stories', action='view')
map.connect('feeds/:(section).:(extension)', controller='feeds', action='formatter')
map.connect('archives/:(year):(month):(day).html', controller='archives', action='view',
requirements=dict(year=r'\d{4}',month=r'\d{2}',day=r'\d{2}'))
The new section dividers, :(something) can be used side-by-side as the last example above shows, however in such cases each path part must have a rigid regexp requirement placed on it to ensure proper collection of the variables. Typically you will have some characters in between each dynamic part so this issue doesn’t arise.
I’ve retained full backward compatibility with the old syntax as well, if you don’t designate the dynamic part using the () modifier it will fall back to looking for the next / instead. So far, all the existing (and extensive) unit tests are passing, in addition to new tests I’ve been adding.
>>> url_for(controller='archives', action='view', year=2004, month=10, day=12)
'/archives/20041012.html'
>>> url_for(controller='feeds',action='formatter',section='computers',extension='xml')
'/feeds/computers.xml'
If you’re interested in giving it a spin, it can be checked out and installed easily from the svn repository using setuptools:
sudo easy_install -U http://routes.groovie.org/svn/branches/newsplit
Feedback / Suggestions / Bug Reports greatly appreciated.





