Skip to content

Commit 725e5e4

Browse files
committed
fix(autoRouting): Fixed problem with autoRouting always overriding the route and not switching off correctly
1 parent 41bda0b commit 725e5e4

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

controller.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,41 @@ module.exports = Class.extend(
4646

4747
extend: function() {
4848
var extendingArgs = [].slice.call( arguments )
49-
, stack = new Error().stack.split( '\n' )
50-
, stack = stack.splice( 1, stack.length - 1)
51-
, extendingFilePath = false
52-
, extendingFileName = false
53-
, route = null;
54-
55-
while( stack.length > 0 && extendingFilePath === false ) {
56-
var file = stack.shift();
57-
if ( !/clever-controller/ig.test( file ) && !/uberclass/ig.test( file ) ) {
58-
if ( /\(([^\[\:]+).*\)/ig.test( file ) ) {
59-
extendingFilePath = RegExp.$1;
60-
extendingFileName = path.basename( extendingFilePath ).replace( /(controller)?.js/ig, '' ).toLowerCase();
49+
, autoRouting = ( extendingArgs.length === 2 )
50+
? extendingArgs[ 0 ].autoRouting !== false
51+
: false
52+
, definedRoute = ( extendingArgs.length === 2 )
53+
? extendingArgs[ 0 ].route !== undefined
54+
: false;
55+
56+
if ( autoRouting && !definedRoute ) {
57+
var stack = new Error().stack.split( '\n' )
58+
, stack = stack.splice( 1, stack.length - 1)
59+
, extendingFilePath = false
60+
, extendingFileName = false
61+
, route = null;
62+
63+
while( stack.length > 0 && extendingFilePath === false ) {
64+
var file = stack.shift();
65+
if ( !/clever-controller/ig.test( file ) && !/uberclass/ig.test( file ) ) {
66+
if ( /\(([^\[\:]+).*\)/ig.test( file ) ) {
67+
extendingFilePath = RegExp.$1;
68+
extendingFileName = path.basename( extendingFilePath ).replace( /(controller)?.js/ig, '' ).toLowerCase();
69+
}
6170
}
6271
}
63-
}
6472

65-
if ( [ '', 'controller' ].indexOf( extendingFileName ) === -1 && this.route === false ) {
66-
route = [ '/', extendingFileName ].join('');
67-
// debug( 'Binding automatic route name??' )
68-
if ( extendingArgs.length === 2 ) {
69-
extendingArgs[ 0 ].route = route;
70-
} else {
71-
extendingArgs.unshift({ route: route });
73+
if ( [ '', 'controller' ].indexOf( extendingFileName ) === -1 && this.route === false ) {
74+
route = [ '/', extendingFileName ].join('');
75+
// debug( 'Binding automatic route name??' )
76+
if ( extendingArgs.length === 2 ) {
77+
extendingArgs[ 0 ].route = route;
78+
} else {
79+
extendingArgs.unshift({ route: route });
80+
}
7281
}
7382
}
83+
7484

7585
return this._super.apply( this, extendingArgs );
7686
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clever-controller",
33
"description": "Lightning-fast flexible controller prototype",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"private": false,
66
"repository":
77
{

0 commit comments

Comments
 (0)