Merge pull request #4223 from FreeCodeCamp/feature/head-tail-challenges
Add head/tail to challenges spec
This commit is contained in:
@ -1,2 +1 @@
|
||||
public/**/*.js
|
||||
client/main.js
|
||||
|
@ -7,23 +7,25 @@ var common = (function() {
|
||||
init: []
|
||||
};
|
||||
|
||||
common.challengeName = common.challengeName || window.challenge_Name ?
|
||||
window.challenge_Name :
|
||||
'';
|
||||
common.challengeName = common.challengeName || window.challenge_Name || '';
|
||||
|
||||
common.challengeType = common.challengeType || window.challengeType ?
|
||||
window.challengeType :
|
||||
0;
|
||||
common.challengeType = common.challengeType || window.challengeType || 0;
|
||||
|
||||
common.challengeId = common.challengeId || window.challenge_Id;
|
||||
|
||||
common.challengeSeed = common.challengeSeed || window.challengeSeed ?
|
||||
window.challengeSeed :
|
||||
[];
|
||||
common.challengeSeed = common.challengeSeed || window.challengeSeed || [];
|
||||
|
||||
common.seed = common.challengeSeed.reduce(function(seed, line) {
|
||||
return seed + line + '\n';
|
||||
}, '');
|
||||
common.head = common.head || '';
|
||||
common.tail = common.tail || '';
|
||||
|
||||
common.arrayToNewLineString = function arrayToNewLineString(seedData) {
|
||||
seedData = Array.isArray(seedData) ? seedData : [seedData];
|
||||
return seedData.reduce(function(seed, line) {
|
||||
return '' + seed + line + '\n';
|
||||
}, '');
|
||||
};
|
||||
|
||||
common.seed = common.arrayToNewLineString(common.challengeSeed);
|
||||
|
||||
common.replaceScriptTags = function replaceScriptTags(value) {
|
||||
return value
|
||||
@ -482,7 +484,7 @@ var editor = (function(CodeMirror, emmetCodeMirror, common) {
|
||||
}(window.CodeMirror, window.emmetCodeMirror, common));
|
||||
|
||||
|
||||
var tests = tests || [];
|
||||
var tests = common.tests || [];
|
||||
|
||||
var libraryIncludes =
|
||||
"<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'>" +
|
||||
@ -873,17 +875,8 @@ function updatePreview() {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof prodOrDev !== 'undefined') {
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
var nodeEnv = window.prodOrDev === 'production' ?
|
||||
'http://www.freecodecamp.com' :
|
||||
'http://localhost:3001';
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
if (common.challengeType === '0') {
|
||||
setTimeout(updatePreview, 300);
|
||||
}
|
||||
if (common.challengeType === '0') {
|
||||
setTimeout(updatePreview, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1119,7 +1112,10 @@ var reassembleTest = function(test, data) {
|
||||
};
|
||||
|
||||
var runTests = function(err, data) {
|
||||
var editorValue = editor.getValue();
|
||||
var head = common.arrayToNewLineString(common.head);
|
||||
var tail = common.arrayToNewLineString(common.tail);
|
||||
|
||||
var editorValue = head + editor.getValue() + tail;
|
||||
// userTests = userTests ? null : [];
|
||||
var allTestsPassed = true;
|
||||
pushed = false;
|
||||
@ -1371,6 +1367,8 @@ common.init.push((function() {
|
||||
}(window.$)));
|
||||
|
||||
function bonfireExecute(shouldTest) {
|
||||
var head = common.arrayToNewLineString(common.head);
|
||||
var tail = common.arrayToNewLineString(common.tail);
|
||||
var codeOutput = common.codeOutput;
|
||||
initPreview = false;
|
||||
goodTests = 0;
|
||||
@ -1383,7 +1381,7 @@ function bonfireExecute(shouldTest) {
|
||||
common.challengeType !== '0' &&
|
||||
!editor.getValue().match(/\$\s*?\(\s*?\$\s*?\)/gi)
|
||||
) {
|
||||
var userJavaScript = editor.getValue();
|
||||
var userJavaScript = head + editor.getValue() + tail;
|
||||
var failedCommentTest = false;
|
||||
|
||||
var openingComments = userJavaScript.match(/\/\*/gi);
|
||||
@ -1502,7 +1500,7 @@ $(document).ready(function() {
|
||||
bonfireExecute(true);
|
||||
}
|
||||
});
|
||||
} else if (common.challengeType !== 7) {
|
||||
} else if (common.challengeType !== '7' && common.challengeType !== '2') {
|
||||
bonfireExecute(true);
|
||||
}
|
||||
|
||||
|
1069
client/main.js
1069
client/main.js
File diff suppressed because it is too large
Load Diff
@ -44,6 +44,16 @@
|
||||
"tests": {
|
||||
"type": "array"
|
||||
},
|
||||
"head": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "appended to user code"
|
||||
},
|
||||
"tail": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "prepended to user code"
|
||||
},
|
||||
"challengeSeed": {
|
||||
"type": "array"
|
||||
},
|
||||
|
@ -44,8 +44,9 @@
|
||||
" return false;",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"}",
|
||||
"",
|
||||
"}"
|
||||
],
|
||||
"tail": [
|
||||
"welcomeToBooleans();"
|
||||
],
|
||||
"type": "waypoint",
|
||||
@ -67,9 +68,9 @@
|
||||
"challengeSeed": [
|
||||
"var ourName = \"Free Code Camp\";",
|
||||
"",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"tail": [
|
||||
"if(typeof(myName) !== \"undefined\"){(function(v){return v;})(myName);}"
|
||||
],
|
||||
"type": "waypoint",
|
||||
|
@ -288,27 +288,34 @@ module.exports = function(app) {
|
||||
|
||||
// save user does nothing if user does not exist
|
||||
return Observable.just({
|
||||
|
||||
title: challenge.name,
|
||||
dashedName: origChallengeName,
|
||||
name: challenge.name,
|
||||
details: challenge.description,
|
||||
description: challenge.description,
|
||||
tests: challenge.tests,
|
||||
challengeSeed: challenge.challengeSeed,
|
||||
verb: utils.randomVerb(),
|
||||
phrase: utils.randomPhrase(),
|
||||
compliment: utils.randomCompliment(),
|
||||
challengeId: challenge.id,
|
||||
challengeType: challenge.challengeType,
|
||||
dashedName: origChallengeName,
|
||||
|
||||
challengeSeed: challenge.challengeSeed,
|
||||
head: challenge.head,
|
||||
tail: challenge.tail,
|
||||
tests: challenge.tests,
|
||||
|
||||
// video challenges
|
||||
video: challenge.challengeSeed[0],
|
||||
|
||||
// bonfires specific
|
||||
difficulty: Math.floor(+challenge.difficulty),
|
||||
bonfires: challenge,
|
||||
MDNkeys: challenge.MDNlinks,
|
||||
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
||||
|
||||
// htmls specific
|
||||
environment: utils.whichEnvironment()
|
||||
environment: utils.whichEnvironment(),
|
||||
|
||||
verb: utils.randomVerb(),
|
||||
phrase: utils.randomPhrase(),
|
||||
compliment: utils.randomCompliment()
|
||||
});
|
||||
})
|
||||
.subscribe(
|
||||
|
@ -70,20 +70,6 @@ block content
|
||||
br
|
||||
#testSuite.negative-10
|
||||
br
|
||||
script(type="text/javascript").
|
||||
var tests = !{JSON.stringify(tests)};
|
||||
var challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
var challenge_Id = !{JSON.stringify(challengeId)};
|
||||
var challenge_Name = !{JSON.stringify(name)};
|
||||
var started = Math.floor(Date.now());
|
||||
var challengeType = !{JSON.stringify(challengeType)};
|
||||
var dashedName = !{JSON.stringify(dashedName)};
|
||||
var _ = R;
|
||||
var dashed = !{JSON.stringify(dashedName)};
|
||||
var username;
|
||||
if (user)
|
||||
script(type="text/javascript").
|
||||
username = !{JSON.stringify(user.username)};
|
||||
|
||||
.col-md-8.col-lg-9
|
||||
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
|
||||
@ -91,7 +77,7 @@ block content
|
||||
form.code
|
||||
.form-group.codeMirrorView
|
||||
textarea#codeEditor(autofocus=true, style='display: none;')
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
|
||||
|
||||
#complete-courseware-dialog.modal(tabindex='-1')
|
||||
.modal-dialog.animated.fadeIn.fast-animation
|
||||
@ -125,15 +111,30 @@ block content
|
||||
a.btn.btn-lg.btn-info.btn-block#reset-button(href='#', data-dismiss='modal', aria-hidden='true') Clear my code
|
||||
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
|
||||
include ../partials/challenge-modals
|
||||
script.
|
||||
script(type="text/javascript").
|
||||
var common = window.common = { init: [] };
|
||||
|
||||
common.tests = !{JSON.stringify(tests)};
|
||||
common.head = !{JSON.stringify(head)};
|
||||
common.tail = !{JSON.stringify(tail)};
|
||||
|
||||
common.challengeId = !{JSON.stringify(challengeId)};
|
||||
common.challengeName = !{JSON.stringify(name)};
|
||||
common.challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
common.challengeType = !{JSON.stringify(challengeType)};
|
||||
common.dashedName = !{JSON.stringify(dashedName)};
|
||||
|
||||
common.started = Math.floor(Date.now());
|
||||
common.username = !{JSON.stringify(user && user.username || '')};
|
||||
|
||||
include ../partials/challenge-footer
|
||||
script.
|
||||
document.addEventListener('gitter-sidecar-ready', function(e) {
|
||||
if (window.main) {
|
||||
window.main.chat.createHelpChat('freecodecamp/helpbonfires', '#challenge-help-btn', 'Bonfires Help');
|
||||
}
|
||||
});
|
||||
|
||||
var MDNlinks = !{JSON.stringify(MDNlinks)};
|
||||
if (!MDNlinks.length) {
|
||||
if (!!{JSON.stringify(MDNlinks.length)}) {
|
||||
$('#MDN-links').addClass('collapse');
|
||||
}
|
||||
|
@ -58,26 +58,12 @@ block content
|
||||
.button-spacer
|
||||
#testSuite
|
||||
br
|
||||
script(type="text/javascript").
|
||||
$('#next-courseware-button').attr('disabled', 'disabled');
|
||||
var tests = !{JSON.stringify(tests)};
|
||||
var challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
var challenge_Id = !{JSON.stringify(challengeId)};
|
||||
var challenge_Name = !{JSON.stringify(name)};
|
||||
var prodOrDev = !{JSON.stringify(environment)};
|
||||
var dashedName = !{JSON.stringify(dashedName)};
|
||||
var challengeType = !{JSON.stringify(challengeType)};
|
||||
var started = Math.floor(Date.now());
|
||||
.col-md-5.col-lg-6
|
||||
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
|
||||
#mainEditorPanel
|
||||
form.code
|
||||
.codeMirrorView
|
||||
textarea#codeEditor(autofocus=true, style='display: none;')
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
script.
|
||||
editor.setOption('lint', false);
|
||||
editor.setOption("mode", "text/html");
|
||||
.col-md-4.col-lg-3
|
||||
.hidden-xs.hidden-sm
|
||||
img.iphone-position.iframe-scroll(src="https://s3.amazonaws.com/freecodecamp/iphone6-frame.png", style = "z-index: -2;")
|
||||
@ -100,9 +86,30 @@ block content
|
||||
else
|
||||
#next-challenge.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter)
|
||||
include ../partials/challenge-modals
|
||||
script(type="text/javascript").
|
||||
$('#next-courseware-button').attr('disabled', 'disabled');
|
||||
var common = window.common || { init: [] };
|
||||
|
||||
common.tests = !{JSON.stringify(tests)};
|
||||
common.head = !{JSON.stringify(head)};
|
||||
common.tail = !{JSON.stringify(tail)};
|
||||
|
||||
common.challengeId = !{JSON.stringify(challengeId)};
|
||||
common.challengeName = !{JSON.stringify(name)};
|
||||
common.challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
common.challengeType = !{JSON.stringify(challengeType)};
|
||||
common.dashedName = !{JSON.stringify(dashedName)};
|
||||
|
||||
common.prodOrDev = !{JSON.stringify(environment)};
|
||||
common.started = Math.floor(Date.now());
|
||||
|
||||
include ../partials/challenge-footer
|
||||
script.
|
||||
document.addEventListener('gitter-sidecar-ready', function(e) {
|
||||
if (window.main) {
|
||||
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
|
||||
}
|
||||
});
|
||||
|
||||
editor.setOption('lint', false);
|
||||
editor.setOption("mode", "text/html");
|
||||
|
@ -61,25 +61,12 @@ block content
|
||||
br
|
||||
#testSuite.negative-10
|
||||
br
|
||||
script(type="text/javascript").
|
||||
var tests = !{JSON.stringify(tests)};
|
||||
var challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
var challenge_Id = !{JSON.stringify(challengeId)};
|
||||
var challenge_Name = !{JSON.stringify(name)};
|
||||
var dashedName = !{JSON.stringify(dashedName)};
|
||||
var started = Math.floor(Date.now());
|
||||
var challengeType = !{JSON.stringify(challengeType)};
|
||||
var _ = R;
|
||||
var dashed = !{JSON.stringify(dashedName)};
|
||||
.col-md-8.col-lg-9
|
||||
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
|
||||
#mainEditorPanel
|
||||
form.code
|
||||
.codeMirrorView
|
||||
textarea#codeEditor(autofocus=true, style='display: none;')
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
script.
|
||||
editor.setOption("mode", "javascript");
|
||||
#complete-courseware-dialog.modal(tabindex='-1')
|
||||
.modal-dialog.animated.fadeIn.fast-animation
|
||||
.modal-content
|
||||
@ -97,9 +84,24 @@ block content
|
||||
else
|
||||
#next-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter)
|
||||
include ../partials/challenge-modals
|
||||
script(type="text/javascript").
|
||||
var common = window.common = { init: [] };
|
||||
|
||||
common.tests = !{JSON.stringify(tests)};
|
||||
common.head = !{JSON.stringify(head)};
|
||||
common.tail = !{JSON.stringify(tail)};
|
||||
|
||||
common.challengeId = !{JSON.stringify(challengeId)};
|
||||
common.challengeName = !{JSON.stringify(name)};
|
||||
common.challengeSeed = !{JSON.stringify(challengeSeed)};
|
||||
common.challengeType = !{JSON.stringify(challengeType)};
|
||||
common.dashedName = !{JSON.stringify(dashedName)};
|
||||
|
||||
common.started = Math.floor(Date.now());
|
||||
|
||||
include ../partials/challenge-footer
|
||||
script.
|
||||
var MDNlinks = !{JSON.stringify(MDNlinks)};
|
||||
if (!MDNlinks.length) {
|
||||
if (!!{JSON.stringify(MDNlinks.length)}) {
|
||||
$('#MDN-links').addClass('collapse');
|
||||
}
|
||||
document.addEventListener('gitter-sidecar-ready', function(e) {
|
||||
@ -107,3 +109,4 @@ block content
|
||||
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
|
||||
}
|
||||
});
|
||||
editor.setOption("mode", "javascript");
|
||||
|
@ -34,14 +34,15 @@ block content
|
||||
#challenge-step-btn-submit.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge
|
||||
else
|
||||
a.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
script.
|
||||
var common = window.common || { init: [] };
|
||||
|
||||
common.challengeId = !{JSON.stringify(challengeId)};
|
||||
common.challengeName = !{JSON.stringify(name)};
|
||||
common.challengeType = 7;
|
||||
common.challengeType = !{JSON.stringify(challengeType)};
|
||||
common.dashedName = !{JSON.stringify(dashedName || '')};
|
||||
common.isHonest = !{JSON.stringify(isHonest || false)};
|
||||
common.isFrontEndCert = !{JSON.stringify(isFrontEndCert || false)};
|
||||
common.isFullStackCert = !{JSON.stringify(isFullStackCert || false)};
|
||||
common.challengeSeed = !{JSON.stringify(challengeSeed || [])};
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
|
@ -75,14 +75,19 @@ block content
|
||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter)
|
||||
script.
|
||||
$('body').bind('keydown', controlEnterHandler);
|
||||
|
||||
include ../partials/challenge-modals
|
||||
script.
|
||||
var challenge_Id = !{JSON.stringify(challengeId)};
|
||||
var challenge_Name = !{JSON.stringify(name)};
|
||||
var challengeType = !{JSON.stringify(challengeType)};
|
||||
var dashedName = !{JSON.stringify(dashedName)};
|
||||
var common = window.common = { init: [] };
|
||||
|
||||
common.challengeId = !{JSON.stringify(challengeId)};
|
||||
common.challengeName = !{JSON.stringify(name)};
|
||||
common.challengeType = !{JSON.stringify(challengeType)};
|
||||
common.dashedName = !{JSON.stringify(dashedName)};
|
||||
|
||||
document.addEventListener('gitter-sidecar-ready', function(e) {
|
||||
if (window.main) {
|
||||
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
|
||||
}
|
||||
});
|
||||
include ../partials/challenge-modals
|
||||
include ../partials/challenge-footer
|
||||
|
5
server/views/partials/challenge-footer.jade
Normal file
5
server/views/partials/challenge-footer.jade
Normal file
@ -0,0 +1,5 @@
|
||||
script(src=rev('/js', 'commonFramework.js'))
|
||||
script.
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('currentDashedName', typeof common !== 'undefined' && common.dashedName || '');
|
||||
}
|
@ -19,7 +19,3 @@
|
||||
h3 This will restore your code editor to its original state.
|
||||
a.btn.btn-lg.btn-info.btn-block#reset-button(href='#', data-dismiss='modal', aria-hidden='true') Clear my code
|
||||
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
|
||||
script.
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('currentDashedName', typeof common !== 'undefined' && common.dashedName || dashedName || '');
|
||||
}
|
||||
|
@ -35,5 +35,4 @@ script.
|
||||
// Leave the below lines alone!
|
||||
script(src=rev('/js', 'main.js'))
|
||||
script(src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js")
|
||||
script(src="/bower_components/ramda/dist/ramda.min.js")
|
||||
script(src='/bower_components/lightbox2/dist/js/lightbox.min.js')
|
||||
|
@ -1,10 +1,7 @@
|
||||
.spacer
|
||||
.spacer
|
||||
#story-list.story-list
|
||||
|
||||
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
|
||||
script.
|
||||
|
||||
var getLinkedName = function getLinkedName(name) {
|
||||
return name.trim().toLowerCase().replace(/\s/g, '-');
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
.spacer
|
||||
.col-xs-12
|
||||
script.
|
||||
var storyURL = !{JSON.stringify(storyURL)};
|
||||
var storyTitle = !{JSON.stringify(storyTitle)};
|
||||
var storyImage = !{JSON.stringify(storyImage)};
|
||||
var storyMetaDescription = !{JSON.stringify(storyMetaDescription)};
|
||||
var main = window.main || { init: [] };
|
||||
main.storyURL = !{JSON.stringify(storyURL)};
|
||||
main.storyTitle = !{JSON.stringify(storyTitle)};
|
||||
main.storyImage = !{JSON.stringify(storyImage)};
|
||||
main.storyMetaDescription = !{JSON.stringify(storyMetaDescription)};
|
||||
|
||||
form.form-horizontal.control-label-story-submission#story-submission-form(name="submitStory")
|
||||
.col-xs-12
|
||||
.form-group
|
||||
|
Reference in New Issue
Block a user