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 * Courseware related routes
*/ */
app.get('/coursewares', coursewareController.returnNextCourseware); app.get('/coursewares/', coursewareController.returnNextCourseware);
app.get( app.get(
'/coursewares/:coursewareName', '/coursewares/:coursewareName',
coursewareController.returnIndividualCourseware coursewareController.returnIndividualCourseware

View File

@ -58,33 +58,39 @@ exports.returnIndividualCourseware = function(req, res, next) {
next(err); next(err);
} }
courseware = courseware.pop(); courseware = courseware.pop();
// 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')
}
// Redirect to full name if the user only entered a partial
var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-'); var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) { if (dashedNameFull != dashedName) {
return res.redirect('../coursewares/' + dashedNameFull); return res.redirect('../coursewares/' + dashedNameFull);
} }
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 {
res.render('coursewares/show', {
title: courseware.name,
dashedName: dashedName,
name: courseware.name,
brief: courseware.description[0],
details: courseware.description.slice(1),
tests: courseware.tests,
challengeSeed: courseware.challengeSeed,
cc: !!req.user,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id
}); // Render the view for the user
} res.render('coursewares/show', {
title: courseware.name,
dashedName: dashedName,
name: courseware.name,
brief: courseware.description[0],
details: courseware.description.slice(1),
tests: courseware.tests,
challengeSeed: courseware.challengeSeed,
cc: !!req.user,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id
});
}); });
}; };

View File

@ -21,6 +21,15 @@ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor")
var editor = myCodeMirror; var editor = myCodeMirror;
editor.setSize("100%", "auto"); 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; var attempts = 0;
if (attempts) { if (attempts) {

View File

@ -23,14 +23,22 @@ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor")
} }
}); });
var editor = myCodeMirror; 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"); editor.setSize("100%", "auto");
var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>" + var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>" +
"<script>document.domain = 'localhost'</script>" + "<script>document.domain = 'localhost'</script>" +
"<script src='/js/lib/chai/chai.js'></script>" + "<script src='/js/lib/chai/chai.js'></script>" +
"<script src='/js/lib/chai/chai-jquery.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>" + "<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='//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'/>" + "<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'/>" +