Skip to content

Commit

Permalink
(new) 'extension' option
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jan 22, 2011
1 parent abe12d0 commit 0490137
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ journey.Router = function Router(routes, options) {
this.routes = [];
this.options = options || {};

if (this.options.extension) {
this.options.extension = this.options.extension.replace('.', '\\.');
}

// Call map() in the context of `this.map`, so `this`
// can be used instead of the passed argument.
routes.call(map, map);
Expand All @@ -95,7 +99,8 @@ journey.map = function (context) {
pattern = this.paths.length ? '' : /.*/,
ignoreCase = false,
method = journey.Router.methods,
constraints = {};
constraints = {},
extension = context.options.extension ? '(?:' + context.options.extension + ')?' : '';

args.forEach(function (arg) {
if (journey.Router.methods.indexOf(arg) !== -1 || Array.isArray(arg)) {
Expand All @@ -122,7 +127,8 @@ journey.map = function (context) {
.join('/')
.match(/^\^?(.*?)\$?$/)[1] // Strip ^ and $
.replace(/^(\/|\\\/)(?!$)/, '') // Strip root / if pattern != '/'
.replace(/(\/|\\\/)+/g, '/') + '$'; // Squeeze slashes
.replace(/(\/|\\\/)+/g, '/') + // Squeeze slashes
extension + '$';

pattern = new(RegExp)(pattern, ignoreCase ? 'i' : '');

Expand Down

0 comments on commit 0490137

Please sign in to comment.