Tab now inserts two spaces, the path "coursewares/" is no longer broken

This commit is contained in:
Nathan Leniz
2015-02-06 12:36:55 -05:00
parent c22a38972b
commit f627c156fc
4 changed files with 48 additions and 25 deletions

2
app.js
View File

@ -289,7 +289,7 @@ app.post('/completed-bonfire/', bonfireController.completedBonfire);
* Courseware related routes
*/
app.get('/coursewares', coursewareController.returnNextCourseware);
app.get('/coursewares/', coursewareController.returnNextCourseware);
app.get(
'/coursewares/:coursewareName',
coursewareController.returnIndividualCourseware

View File

@ -58,16 +58,22 @@ exports.returnIndividualCourseware = function(req, res, next) {
next(err);
}
courseware = courseware.pop();
var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
return res.redirect('../coursewares/' + dashedNameFull);
}
// Handle not found
if (courseware.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a challenge with that name. Please double check the name."
});
return res.redirect('/coursewares')
} else {
}
// Redirect to full name if the user only entered a partial
var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
return res.redirect('../coursewares/' + dashedNameFull);
}
// Render the view for the user
res.render('coursewares/show', {
title: courseware.name,
dashedName: dashedName,
@ -84,7 +90,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
coursewareHash: courseware._id
});
}
});
};

View File

@ -21,6 +21,15 @@ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor")
var editor = myCodeMirror;
editor.setSize("100%", "auto");
// Hijack tab key to enter two spaces intead
editor.setOption("extraKeys", {
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces);
}
});
var attempts = 0;
if (attempts) {

View File

@ -23,14 +23,22 @@ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor")
}
});
var editor = myCodeMirror;
// Hijack tab key to insert two spaces instead
editor.setOption("extraKeys", {
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces);
}
});
editor.setSize("100%", "auto");
var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>" +
"<script>document.domain = 'localhost'</script>" +
"<script src='/js/lib/chai/chai.js'></script>" +
"<script src='/js/lib/chai/chai-jquery.js'></script>" +
"<script src='//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js'></script>" +
"<script src='//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.0/ui-bootstrap-tpls.min.js'></script>" +
"<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js'></script>" +
"<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.min.css'/>" +
"<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'/>" +