Add head/tail to challenge spec.

Lint EVERYTHING!
This commit is contained in:
Berkeley Martinez
2015-11-06 16:35:57 -08:00
parent 5b4eafe751
commit 5dbfbfcf57
15 changed files with 724 additions and 574 deletions

View File

@ -7,23 +7,25 @@ var common = (function() {
init: [] init: []
}; };
common.challengeName = common.challengeName || window.challenge_Name ? common.challengeName = common.challengeName || window.challenge_Name || '';
window.challenge_Name :
'';
common.challengeType = common.challengeType || window.challengeType ? common.challengeType = common.challengeType || window.challengeType || 0;
window.challengeType :
0;
common.challengeId = common.challengeId || window.challenge_Id; common.challengeId = common.challengeId || window.challenge_Id;
common.challengeSeed = common.challengeSeed || window.challengeSeed ? common.challengeSeed = common.challengeSeed || window.challengeSeed || [];
window.challengeSeed :
[];
common.seed = common.challengeSeed.reduce(function(seed, line) { common.head = common.head || '';
return seed + line + '\n'; common.tail = common.tail || '';
}, '');
common.convertSeed = function(seedData) {
seedData = seedData || [];
return seedData.reduce(function(seed, line) {
return seed + line + '\n';
}, '');
};
common.seed = common.convertSeed(common.challengeSeed);
common.replaceScriptTags = function replaceScriptTags(value) { common.replaceScriptTags = function replaceScriptTags(value) {
return value return value
@ -482,7 +484,7 @@ var editor = (function(CodeMirror, emmetCodeMirror, common) {
}(window.CodeMirror, window.emmetCodeMirror, common)); }(window.CodeMirror, window.emmetCodeMirror, common));
var tests = tests || []; var tests = common.tests || [];
var libraryIncludes = var libraryIncludes =
"<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'>" + "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'>" +
@ -873,17 +875,8 @@ function updatePreview() {
} }
} }
if (typeof prodOrDev !== 'undefined') { if (common.challengeType === '0') {
setTimeout(updatePreview, 300);
/* 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);
}
} }
/** /**
@ -1119,7 +1112,10 @@ var reassembleTest = function(test, data) {
}; };
var runTests = function(err, data) { var runTests = function(err, data) {
var editorValue = editor.getValue(); var head = common.convertSeed(common.head);
var tail = common.convertSeed(common.tail);
var editorValue = head + editor.getValue() + tail;
// userTests = userTests ? null : []; // userTests = userTests ? null : [];
var allTestsPassed = true; var allTestsPassed = true;
pushed = false; pushed = false;
@ -1371,6 +1367,8 @@ common.init.push((function() {
}(window.$))); }(window.$)));
function bonfireExecute(shouldTest) { function bonfireExecute(shouldTest) {
var head = common.convertSeed(common.head);
var tail = common.convertSeed(common.tail);
var codeOutput = common.codeOutput; var codeOutput = common.codeOutput;
initPreview = false; initPreview = false;
goodTests = 0; goodTests = 0;
@ -1383,7 +1381,7 @@ function bonfireExecute(shouldTest) {
common.challengeType !== '0' && common.challengeType !== '0' &&
!editor.getValue().match(/\$\s*?\(\s*?\$\s*?\)/gi) !editor.getValue().match(/\$\s*?\(\s*?\$\s*?\)/gi)
) { ) {
var userJavaScript = editor.getValue(); var userJavaScript = head + editor.getValue() + tail;
var failedCommentTest = false; var failedCommentTest = false;
var openingComments = userJavaScript.match(/\/\*/gi); var openingComments = userJavaScript.match(/\/\*/gi);
@ -1502,7 +1500,7 @@ $(document).ready(function() {
bonfireExecute(true); bonfireExecute(true);
} }
}); });
} else if (common.challengeType !== 7) { } else if (common.challengeType !== '7' && common.challengeType !== '2') {
bonfireExecute(true); bonfireExecute(true);
} }

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,16 @@
"tests": { "tests": {
"type": "array" "type": "array"
}, },
"head": {
"type": "array",
"default": [],
"description": "appended to user code"
},
"tail": {
"type": "array",
"default": [],
"description": "prepended to user code"
},
"challengeSeed": { "challengeSeed": {
"type": "array" "type": "array"
}, },

View File

@ -44,8 +44,9 @@
" return false;", " return false;",
"", "",
"// Only change code above this line.", "// Only change code above this line.",
"}", "}"
"", ],
"tail": [
"welcomeToBooleans();" "welcomeToBooleans();"
], ],
"type": "waypoint", "type": "waypoint",
@ -67,9 +68,9 @@
"challengeSeed": [ "challengeSeed": [
"var ourName = \"Free Code Camp\";", "var ourName = \"Free Code Camp\";",
"", "",
"", ""
"// Only change code above this line.", ],
"", "tail": [
"if(typeof(myName) !== \"undefined\"){(function(v){return v;})(myName);}" "if(typeof(myName) !== \"undefined\"){(function(v){return v;})(myName);}"
], ],
"type": "waypoint", "type": "waypoint",

View File

@ -288,27 +288,34 @@ module.exports = function(app) {
// save user does nothing if user does not exist // save user does nothing if user does not exist
return Observable.just({ return Observable.just({
title: challenge.name, title: challenge.name,
dashedName: origChallengeName,
name: challenge.name, name: challenge.name,
details: challenge.description, details: challenge.description,
description: challenge.description, description: challenge.description,
tests: challenge.tests,
challengeSeed: challenge.challengeSeed,
verb: utils.randomVerb(),
phrase: utils.randomPhrase(),
compliment: utils.randomCompliment(),
challengeId: challenge.id, challengeId: challenge.id,
challengeType: challenge.challengeType, challengeType: challenge.challengeType,
dashedName: origChallengeName,
challengeSeed: challenge.challengeSeed,
head: challenge.head,
tail: challenge.tail,
tests: challenge.tests,
// video challenges // video challenges
video: challenge.challengeSeed[0], video: challenge.challengeSeed[0],
// bonfires specific // bonfires specific
difficulty: Math.floor(+challenge.difficulty),
bonfires: challenge, bonfires: challenge,
MDNkeys: challenge.MDNlinks, MDNkeys: challenge.MDNlinks,
MDNlinks: getMDNLinks(challenge.MDNlinks), MDNlinks: getMDNLinks(challenge.MDNlinks),
// htmls specific // htmls specific
environment: utils.whichEnvironment() environment: utils.whichEnvironment(),
verb: utils.randomVerb(),
phrase: utils.randomPhrase(),
compliment: utils.randomCompliment()
}); });
}) })
.subscribe( .subscribe(

View File

@ -70,20 +70,6 @@ block content
br br
#testSuite.negative-10 #testSuite.negative-10
br 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 .col-md-8.col-lg-9
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;") .editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
@ -91,7 +77,7 @@ block content
form.code form.code
.form-group.codeMirrorView .form-group.codeMirrorView
textarea#codeEditor(autofocus=true, style='display: none;') textarea#codeEditor(autofocus=true, style='display: none;')
script(src=rev('/js', 'commonFramework.js'))
#complete-courseware-dialog.modal(tabindex='-1') #complete-courseware-dialog.modal(tabindex='-1')
.modal-dialog.animated.fadeIn.fast-animation .modal-dialog.animated.fadeIn.fast-animation
@ -125,15 +111,32 @@ 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-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 a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
include ../partials/challenge-modals 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());
if (user) {
common.username = !{JSON.stringify(user.username)};
}
include ../partials/challenge-footer
script.
document.addEventListener('gitter-sidecar-ready', function(e) { document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) { if (window.main) {
window.main.chat.createHelpChat('freecodecamp/helpbonfires', '#challenge-help-btn', 'Bonfires Help'); window.main.chat.createHelpChat('freecodecamp/helpbonfires', '#challenge-help-btn', 'Bonfires Help');
} }
}); });
var MDNlinks = !{JSON.stringify(MDNlinks)}; if (!{JSON.stringify(MDNlinks.length)}) {
if (!MDNlinks.length) {
$('#MDN-links').addClass('collapse'); $('#MDN-links').addClass('collapse');
} }

View File

@ -58,26 +58,12 @@ block content
.button-spacer .button-spacer
#testSuite #testSuite
br 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 .col-md-5.col-lg-6
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;") .editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
#mainEditorPanel #mainEditorPanel
form.code form.code
.codeMirrorView .codeMirrorView
textarea#codeEditor(autofocus=true, style='display: none;') 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 .col-md-4.col-lg-3
.hidden-xs.hidden-sm .hidden-xs.hidden-sm
img.iphone-position.iframe-scroll(src="https://s3.amazonaws.com/freecodecamp/iphone6-frame.png", style = "z-index: -2;") 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 else
#next-challenge.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter) #next-challenge.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter)
include ../partials/challenge-modals 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. script.
document.addEventListener('gitter-sidecar-ready', function(e) { document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) { if (window.main) {
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn'); window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
} }
}); });
editor.setOption('lint', false);
editor.setOption("mode", "text/html");

View File

@ -61,25 +61,12 @@ block content
br br
#testSuite.negative-10 #testSuite.negative-10
br 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 .col-md-8.col-lg-9
.editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;") .editorScrollDiv(style = "overflow-y: auto; overflow-x: hidden;")
#mainEditorPanel #mainEditorPanel
form.code form.code
.codeMirrorView .codeMirrorView
textarea#codeEditor(autofocus=true, style='display: none;') textarea#codeEditor(autofocus=true, style='display: none;')
script(src=rev('/js', 'commonFramework.js'))
script.
editor.setOption("mode", "javascript");
#complete-courseware-dialog.modal(tabindex='-1') #complete-courseware-dialog.modal(tabindex='-1')
.modal-dialog.animated.fadeIn.fast-animation .modal-dialog.animated.fadeIn.fast-animation
.modal-content .modal-content
@ -97,9 +84,24 @@ block content
else else
#next-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter) #next-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Go to my next challenge (ctrl + enter)
include ../partials/challenge-modals 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. script.
var MDNlinks = !{JSON.stringify(MDNlinks)}; if (!{JSON.stringify(MDNlinks.length)}) {
if (!MDNlinks.length) {
$('#MDN-links').addClass('collapse'); $('#MDN-links').addClass('collapse');
} }
document.addEventListener('gitter-sidecar-ready', function(e) { document.addEventListener('gitter-sidecar-ready', function(e) {
@ -107,3 +109,4 @@ block content
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn'); window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
} }
}); });
editor.setOption("mode", "javascript");

View File

@ -34,9 +34,9 @@ block content
#challenge-step-btn-submit.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge #challenge-step-btn-submit.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge
else else
a.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge 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. script.
var common = window.common || { init: [] }; var common = window.common || { init: [] };
common.challengeId = !{JSON.stringify(challengeId)}; common.challengeId = !{JSON.stringify(challengeId)};
common.challengeName = !{JSON.stringify(name)}; common.challengeName = !{JSON.stringify(name)};
common.challengeType = 7; common.challengeType = 7;
@ -45,3 +45,4 @@ block content
common.isFrontEndCert = !{JSON.stringify(isFrontEndCert || false)}; common.isFrontEndCert = !{JSON.stringify(isFrontEndCert || false)};
common.isFullStackCert = !{JSON.stringify(isFullStackCert || false)}; common.isFullStackCert = !{JSON.stringify(isFullStackCert || false)};
common.challengeSeed = !{JSON.stringify(challengeSeed || [])}; common.challengeSeed = !{JSON.stringify(challengeSeed || [])};
script(src=rev('/js', 'commonFramework.js'))

View File

@ -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) a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter)
script. script.
$('body').bind('keydown', controlEnterHandler); $('body').bind('keydown', controlEnterHandler);
include ../partials/challenge-modals
script. script.
var challenge_Id = !{JSON.stringify(challengeId)}; var common = window.common = { init: [] };
var challenge_Name = !{JSON.stringify(name)};
var challengeType = !{JSON.stringify(challengeType)}; common.challengeId = !{JSON.stringify(challengeId)};
var dashedName = !{JSON.stringify(dashedName)}; common.challengeName = !{JSON.stringify(name)};
common.challengeType = !{JSON.stringify(challengeType)};
common.dashedName = !{JSON.stringify(dashedName)};
document.addEventListener('gitter-sidecar-ready', function(e) { document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) { if (window.main) {
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn'); window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
} }
}); });
include ../partials/challenge-modals include ../partials/challenge-footer

View File

@ -0,0 +1,5 @@
script(src=rev('/js', 'commonFramework.js'))
script.
if (typeof localStorage !== 'undefined') {
localStorage.setItem('currentDashedName', typeof common !== 'undefined' && common.dashedName || '');
}

View File

@ -19,7 +19,3 @@
h3 This will restore your code editor to its original state. 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-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 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 || '');
}

View File

@ -35,5 +35,4 @@ script.
// Leave the below lines alone! // Leave the below lines alone!
script(src=rev('/js', 'main.js')) script(src=rev('/js', 'main.js'))
script(src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.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') script(src='/bower_components/lightbox2/dist/js/lightbox.min.js')

View File

@ -1,10 +1,7 @@
.spacer .spacer
.spacer .spacer
#story-list.story-list #story-list.story-list
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
script. script.
var getLinkedName = function getLinkedName(name) { var getLinkedName = function getLinkedName(name) {
return name.trim().toLowerCase().replace(/\s/g, '-'); return name.trim().toLowerCase().replace(/\s/g, '-');
} }

View File

@ -1,10 +1,12 @@
.spacer .spacer
.col-xs-12 .col-xs-12
script. script.
var storyURL = !{JSON.stringify(storyURL)}; var main = window.main || { init: [] };
var storyTitle = !{JSON.stringify(storyTitle)}; main.storyURL = !{JSON.stringify(storyURL)};
var storyImage = !{JSON.stringify(storyImage)}; main.storyTitle = !{JSON.stringify(storyTitle)};
var storyMetaDescription = !{JSON.stringify(storyMetaDescription)}; main.storyImage = !{JSON.stringify(storyImage)};
main.storyMetaDescription = !{JSON.stringify(storyMetaDescription)};
form.form-horizontal.control-label-story-submission#story-submission-form(name="submitStory") form.form-horizontal.control-label-story-submission#story-submission-form(name="submitStory")
.col-xs-12 .col-xs-12
.form-group .form-group