« Back
Sammy.Application contextMatchesOptions ( context, match_options, positive )
Matches an object of options against an EventContext like object that
contains path and verb attributes. Internally Sammy uses this
for matching before() filters against specific options. You can set the
object to only match certain paths or verbs, or match all paths or verbs except
those that match the options.
Example
var app = $.sammy(),
context = {verb: 'get', path: '#/mypath'};
// match against a path string
app.contextMatchesOptions(context, '#/mypath'); //=> true
app.contextMatchesOptions(context, '#/otherpath'); //=> false
// equivilent to
app.contextMatchesOptions(context, {only: {path:'#/mypath'}}); //=> true
app.contextMatchesOptions(context, {only: {path:'#/otherpath'}}); //=> false
// match against a path regexp
app.contextMatchesOptions(context, /path/); //=> true
app.contextMatchesOptions(context, /^path/); //=> false
// match only a verb
app.contextMatchesOptions(context, {only: {verb:'get'}}); //=> true
app.contextMatchesOptions(context, {only: {verb:'post'}}); //=> false
// match all except a verb
app.contextMatchesOptions(context, {except: {verb:'post'}}); //=> true
app.contextMatchesOptions(context, {except: {verb:'get'}}); //=> false
// match all except a path
app.contextMatchesOptions(context, {except: {path:'#/otherpath'}}); //=> true
app.contextMatchesOptions(context, {except: {path:'#/mypath'}}); //=> false
comments powered by Disqus