ok disbaled map is now just instants

This commit is contained in:
Peter Cottle 2013-01-02 11:22:54 -08:00
parent 4046916432
commit 4aeb56c840
6 changed files with 77 additions and 188 deletions

View file

@ -4845,6 +4845,8 @@ var Constants = require('../util/constants');
var Views = require('../views');
var util = require('../util');
var Command = require('../models/commandModel').Command;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
/**
* Globals
@ -4952,6 +4954,9 @@ function CommandUI() {
collection: this.commandCollection
});
this.parseWaterfall = new ParseWaterfall();
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
}
@ -4959,7 +4964,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
events.trigger('commandSubmittedPassive', value);
util.splitTextCommand(value, function(command) {
this.commandCollection.add(new Command({
rawStr: command
rawStr: command,
parseWaterfall: this.parseWaterfall
}));
}, this);
};
@ -5228,7 +5234,7 @@ var parse = function(str) {
_.each(regexMap, function(regex, thisMethod) {
if (regex.exec(str)) {
options = str.slice(thisMethod.length + 1);
method = thisMethod;
method = thisMethod.slice('git '.length);
}
}, this);
@ -5352,6 +5358,7 @@ var SandboxCommands = require('../level/SandboxCommands');
// more or less a static class
function ParseWaterfall(options) {
options = options || {};
this.shortcutWaterfall = options.shortcutWaterfall || [
GitCommands.shortcutMap
];
@ -5484,6 +5491,48 @@ var instantCommands = [
exports.instantCommands = instantCommands;
});
require.define("/src/js/level/disabledMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var GitCommands = require('../git/commands');
var Errors = require('../util/errors');
var GitError = Errors.GitError;
function DisabledMap(options) {
options = options || {};
this.disabledMap = options.disabledMap || {
'git cherry-pick': true,
'git rebase': true
};
}
DisabledMap.prototype.getInstantCommands = function() {
// this produces an array of regex / function pairs that can be
// piped into a parse waterfall to disable certain git commmands
// :D
var instants = [];
var onMatch = function() {
throw new GitError({
msg: 'That git command is disabled for this level!'
});
};
_.each(this.disabledMap, function(val, disabledCommand) {
var gitRegex = GitCommands.regexMap[disabledCommand];
if (!gitRegex) {
throw new Error('wuttttt this disbaled command' + disabledCommand +
' has no regex matching');
}
instants.push([gitRegex, onMatch]);
});
return instants;
};
exports.DisabledMap = DisabledMap;
});
require.define("/src/js/visuals/visualization.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
@ -14359,6 +14408,8 @@ var Constants = require('../util/constants');
var Views = require('../views');
var util = require('../util');
var Command = require('../models/commandModel').Command;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
/**
* Globals
@ -14466,6 +14517,9 @@ function CommandUI() {
collection: this.commandCollection
});
this.parseWaterfall = new ParseWaterfall();
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
}
@ -14473,7 +14527,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
events.trigger('commandSubmittedPassive', value);
util.splitTextCommand(value, function(command) {
this.commandCollection.add(new Command({
rawStr: command
rawStr: command,
parseWaterfall: this.parseWaterfall
}));
}, this);
};
@ -14573,7 +14628,7 @@ var parse = function(str) {
_.each(regexMap, function(regex, thisMethod) {
if (regex.exec(str)) {
options = str.slice(thisMethod.length + 1);
method = thisMethod;
method = thisMethod.slice('git '.length);
}
}, this);
@ -16548,7 +16603,7 @@ exports.TreeCompare = TreeCompare;
});
require("/src/js/git/treeCompare.js");
require.define("/src/js/level/disableMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
require.define("/src/js/level/disabledMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var GitCommands = require('../git/commands');
@ -16556,9 +16611,10 @@ var Errors = require('../util/errors');
var GitError = Errors.GitError;
function DisabledMap(options) {
options = options || {};
this.disabledMap = options.disabledMap || {
'cherry-pick': true,
'rebase': true
'git cherry-pick': true,
'git rebase': true
};
}
@ -16588,97 +16644,7 @@ exports.DisabledMap = DisabledMap;
});
require("/src/js/level/disableMap.js");
require.define("/src/js/level/inputWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var Main = require('../app');
var GitCommands = require('../git/commands');
var Errors = require('../util/errors');
var CommandProcessError = Errors.CommandProcessError;
var GitError = Errors.GitError;
var Warning = Errors.Warning;
var CommandResult = Errors.CommandResult;
/**
* This class supports a few things we need for levels:
~ A disabled map (to prevent certain git commands from firing)
~ A post-git command hook (to compare the git tree against the solution)
~ Extra level-specific commands (like help, hint, etc) that are async
**/
function InputWaterfall(options) {
options = options || {};
this.listenEvent = options.listenEvent || 'processCommand';
this.disabledMap = options.disabledMap || {
'git cherry-pick': true,
'git rebase': true
};
this.listen();
}
InputWaterfall.prototype.listen = function() {
Main.getEvents().on(this.listenEvent, this.process, this);
};
InputWaterfall.prototype.mute = function() {
Main.getEvents().off(this.listenEvent, this.process, this);
};
InputWaterfall.prototype.process = function(command, callback) {
if (this.checkDisabledMap(command)) {
callback();
return;
}
// for now, just immediately fire it
Main.getEvents().trigger('processGitCommand', command, callback);
};
InputWaterfall.prototype.sliceGitOff = function(str) {
return str.slice('git '.length);
};
InputWaterfall.prototype.checkDisabledMap = function(command) {
try {
this.loopDisabledMap(command);
} catch(err) {
Errors.filterError(err);
command.set('error', err);
return true;
}
// not needed explicitly, but included for clarity
return false;
};
InputWaterfall.prototype.loopDisabledMap = function(command) {
var toTest = this.sliceGitOff(command.get('rawStr'));
var regexMap = GitCommands.regexMap;
_.each(this.disabledMap, function(val, disabledGitCommand) {
disabledGitCommand = this.sliceGitOff(disabledGitCommand);
var regex = regexMap[disabledGitCommand];
if (!regex) {
console.warn('wut, no regex for command', disabledGitCommand);
return;
}
if (regex.test(toTest)) {
throw new GitError({
msg: 'That git command is disabled for this level!'
});
}
}, this);
};
exports.InputWaterfall = InputWaterfall;
});
require("/src/js/level/inputWaterfall.js");
require("/src/js/level/disabledMap.js");
require.define("/src/js/level/parseWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
@ -16687,6 +16653,7 @@ var SandboxCommands = require('../level/SandboxCommands');
// more or less a static class
function ParseWaterfall(options) {
options = options || {};
this.shortcutWaterfall = options.shortcutWaterfall || [
GitCommands.shortcutMap
];

View file

@ -5,6 +5,8 @@ var Constants = require('../util/constants');
var Views = require('../views');
var util = require('../util');
var Command = require('../models/commandModel').Command;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
/**
* Globals
@ -112,6 +114,9 @@ function CommandUI() {
collection: this.commandCollection
});
this.parseWaterfall = new ParseWaterfall();
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
}
@ -119,7 +124,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
events.trigger('commandSubmittedPassive', value);
util.splitTextCommand(value, function(command) {
this.commandCollection.add(new Command({
rawStr: command
rawStr: command,
parseWaterfall: this.parseWaterfall
}));
}, this);
};

View file

@ -71,7 +71,7 @@ var parse = function(str) {
_.each(regexMap, function(regex, thisMethod) {
if (regex.exec(str)) {
options = str.slice(thisMethod.length + 1);
method = thisMethod;
method = thisMethod.slice('git '.length);
}
}, this);

View file

@ -6,9 +6,10 @@ var Errors = require('../util/errors');
var GitError = Errors.GitError;
function DisabledMap(options) {
options = options || {};
this.disabledMap = options.disabledMap || {
'cherry-pick': true,
'rebase': true
'git cherry-pick': true,
'git rebase': true
};
}

View file

@ -1,86 +0,0 @@
var _ = require('underscore');
var Main = require('../app');
var GitCommands = require('../git/commands');
var Errors = require('../util/errors');
var CommandProcessError = Errors.CommandProcessError;
var GitError = Errors.GitError;
var Warning = Errors.Warning;
var CommandResult = Errors.CommandResult;
/**
* This class supports a few things we need for levels:
~ A disabled map (to prevent certain git commands from firing)
~ A post-git command hook (to compare the git tree against the solution)
~ Extra level-specific commands (like help, hint, etc) that are async
**/
function InputWaterfall(options) {
options = options || {};
this.listenEvent = options.listenEvent || 'processCommand';
this.disabledMap = options.disabledMap || {
'git cherry-pick': true,
'git rebase': true
};
this.listen();
}
InputWaterfall.prototype.listen = function() {
Main.getEvents().on(this.listenEvent, this.process, this);
};
InputWaterfall.prototype.mute = function() {
Main.getEvents().off(this.listenEvent, this.process, this);
};
InputWaterfall.prototype.process = function(command, callback) {
if (this.checkDisabledMap(command)) {
callback();
return;
}
// for now, just immediately fire it
Main.getEvents().trigger('processGitCommand', command, callback);
};
InputWaterfall.prototype.sliceGitOff = function(str) {
return str.slice('git '.length);
};
InputWaterfall.prototype.checkDisabledMap = function(command) {
try {
this.loopDisabledMap(command);
} catch(err) {
Errors.filterError(err);
command.set('error', err);
return true;
}
// not needed explicitly, but included for clarity
return false;
};
InputWaterfall.prototype.loopDisabledMap = function(command) {
var toTest = this.sliceGitOff(command.get('rawStr'));
var regexMap = GitCommands.regexMap;
_.each(this.disabledMap, function(val, disabledGitCommand) {
disabledGitCommand = this.sliceGitOff(disabledGitCommand);
var regex = regexMap[disabledGitCommand];
if (!regex) {
console.warn('wut, no regex for command', disabledGitCommand);
return;
}
if (regex.test(toTest)) {
throw new GitError({
msg: 'That git command is disabled for this level!'
});
}
}, this);
};
exports.InputWaterfall = InputWaterfall;

View file

@ -5,6 +5,7 @@ var SandboxCommands = require('../level/SandboxCommands');
// more or less a static class
function ParseWaterfall(options) {
options = options || {};
this.shortcutWaterfall = options.shortcutWaterfall || [
GitCommands.shortcutMap
];