mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-23 18:00:26 +00:00
extracted switchRouteMatcher and added necessary libraries to angular-scenario
This commit is contained in:
parent
177873df86
commit
cb5d211927
5 changed files with 50 additions and 39 deletions
7
Rakefile
7
Rakefile
|
|
@ -37,6 +37,13 @@ task :compile_scenario do
|
|||
src/scenario/angular.prefix \
|
||||
src/Angular.js \
|
||||
src/JSON.js \
|
||||
src/Scope.js \
|
||||
src/Parser.js \
|
||||
src/Resource.js \
|
||||
src/Browser.js \
|
||||
src/apis.js \
|
||||
src/services.js \
|
||||
src/AngularPublic.js \
|
||||
src/scenario/Runner.js \
|
||||
src/scenario/DSL.js \
|
||||
src/scenario/angular.suffix \
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ angular.scenario.dsl.browser = {
|
|||
var self = this;
|
||||
self.testFrame.load(function(){
|
||||
self.testFrame.unbind();
|
||||
self.testDocument = jQuery(self.testWindow.document);
|
||||
self.testWindow = self.testFrame[0].contentWindow;
|
||||
self.testDocument = jQuery(self.testWindow.document);
|
||||
self.$browser = self.testWindow.angular.service.$browser();
|
||||
self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
|
||||
self.notifyWhenNoOutstandingRequests(done);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ angular.scenario.Runner.prototype = {
|
|||
jQuery(this).toggleClass('collapsed');
|
||||
});
|
||||
this.testFrame = body.find('#testView iframe');
|
||||
this.testWindow = this.testFrame[0].contentWindow;
|
||||
function logger(parent) {
|
||||
var container;
|
||||
return function(type, text) {
|
||||
|
|
@ -100,27 +99,30 @@ angular.scenario.Runner.prototype = {
|
|||
|
||||
execute: function(name, callback) {
|
||||
var spec = this.specs[name],
|
||||
self = this,
|
||||
result = {
|
||||
passed: false,
|
||||
failed: false,
|
||||
finished: false,
|
||||
fail: function(error) {
|
||||
result.passed = false;
|
||||
result.failed = true;
|
||||
result.error = error;
|
||||
result.log('fail', isString(error) ? error : toJson(error)).fail();
|
||||
}
|
||||
};
|
||||
specThis = {
|
||||
passed: false,
|
||||
failed: false,
|
||||
finished: false,
|
||||
fail: function(error) {
|
||||
result.passed = false;
|
||||
result.failed = true;
|
||||
result.error = error;
|
||||
result.log('fail', isString(error) ? error : toJson(error)).fail();
|
||||
}
|
||||
},
|
||||
specThis = createScope({
|
||||
result: result,
|
||||
testWindow: this.testWindow,
|
||||
testFrame: this.testFrame
|
||||
};
|
||||
testFrame: this.testFrame,
|
||||
testWindow: this.testWindow
|
||||
}, angularService, {});
|
||||
this.self = specThis;
|
||||
var stepLogger = this.logger('spec', name);
|
||||
spec.nextStepIndex = 0;
|
||||
function done() {
|
||||
result.finished = true;
|
||||
stepLogger.close();
|
||||
self.self = null;
|
||||
(callback||noop).call(specThis);
|
||||
}
|
||||
function next(){
|
||||
|
|
|
|||
|
|
@ -158,10 +158,33 @@ angularService("$invalidWidgets", function(){
|
|||
return invalidWidgets;
|
||||
});
|
||||
|
||||
function switchRouteMatcher(on, when, dstName) {
|
||||
var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
|
||||
params = [],
|
||||
dst = {};
|
||||
foreach(when.split(/\W/), function(param){
|
||||
if (param) {
|
||||
var paramRegExp = new RegExp(":" + param + "([\\W])");
|
||||
if (regex.match(paramRegExp)) {
|
||||
regex = regex.replace(paramRegExp, "([^\/]*)$1");
|
||||
params.push(param);
|
||||
}
|
||||
}
|
||||
});
|
||||
var match = on.match(new RegExp(regex));
|
||||
if (match) {
|
||||
foreach(params, function(name, index){
|
||||
dst[name] = match[index + 1];
|
||||
});
|
||||
if (dstName) this.$set(dstName, dst);
|
||||
}
|
||||
return match ? dst : null;
|
||||
}
|
||||
|
||||
angularService('$route', function(location, params){
|
||||
var routes = {},
|
||||
onChange = [],
|
||||
matcher = angularWidget('NG:SWITCH').route,
|
||||
matcher = switchRouteMatcher,
|
||||
parentScope = this,
|
||||
dirty = 0,
|
||||
$route = {
|
||||
|
|
|
|||
|
|
@ -317,26 +317,5 @@ var ngSwitch = angularWidget('NG:SWITCH', function (element){
|
|||
equals: function(on, when) {
|
||||
return on == when;
|
||||
},
|
||||
route: function(on, when, dstName) {
|
||||
var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
|
||||
params = [],
|
||||
dst = {};
|
||||
foreach(when.split(/\W/), function(param){
|
||||
if (param) {
|
||||
var paramRegExp = new RegExp(":" + param + "([\\W])");
|
||||
if (regex.match(paramRegExp)) {
|
||||
regex = regex.replace(paramRegExp, "([^\/]*)$1");
|
||||
params.push(param);
|
||||
}
|
||||
}
|
||||
});
|
||||
var match = on.match(new RegExp(regex));
|
||||
if (match) {
|
||||
foreach(params, function(name, index){
|
||||
dst[name] = match[index + 1];
|
||||
});
|
||||
if (dstName) this.$set(dstName, dst);
|
||||
}
|
||||
return match ? dst : null;
|
||||
}
|
||||
route: switchRouteMatcher
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue