quirkey/sammy — pull request #115 by flashingpumpkin (2011-11-08 15:01:30+00:00)
Title: contextMatchesOptions + path array

Hi

I'm using `this.before` but need to exclude multiple paths. Someone on the group had this problem too [0] and the proposed solution was to add a single regex handling all paths. That's fine with a low number of paths - else it gets very unreadable and a pain to maintain.

I've added support for `Sammy.Application.contextMatchesOptions` to take a path array. Taken from the code:

var app = $.sammy(),
context = {verb: 'get', path: '#/mypath'};

// match multiple paths
app.contextMatchesOptions(context, {path: ['#/mypath', '#/otherpath']}); //=> true
app.contextMatchesOptions(context, {path: ['#/otherpath', '#/thirdpath']}); //=> false
// equivalent to
app.contextMatchesOptions(context, {only: {path: ['#/mypath', '#/otherpath']}}); //=> true
app.contextMatchesOptions(context, {only: {path: ['#/otherpath', '#/thirdpath']}}); //=> false
// match all except multiple paths
app.contextMatchesOptions(context, {except: {path: ['#/mypath', '#/otherpath']}}); //=> false
app.contextMatchesOptions(context, {except: {path: ['#/otherpath', '#/thirdpath']}}); //=> true

[0] https://groups.google.com/d/topic/sammyjs/5twqVEOyl6c/discussion