chaplinjs/chaplin — pull request #258 by Rendez (2012-11-15 11:14:07+00:00)
Title: Option to apply RegExp from constraints to match named params.

I came up with this while integrating routes at moviepilot.com as well as in 90% of the sites the use of pretty URLs is extensive. Extracting the numeric ID from a URL can be done in a controller action, but it should be a feature of the Router/Route to be able to extract it given a RegExp, after matching with the path.

For this I've taken a simple, non-breaking approach where Router may be passed an option `applyConstraints` which gets delegated to every new `Route` instance it creates, to allow the use of defined `constraints` for matching named params, e.g.:

```coffee
router.match 'constraints/:id', 'null#null',
constraints:
id: /([\d]+)[\w\-$]*/

router.route '/constraints/123-foo'
```

The containing params object shall expose `id` with value of `123`, while still be able to use the constraint as usual.