diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 83431a390d..6df65368e8 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -2,7 +2,8 @@ var _ = require('lodash'), debug = require('debug')('freecc:cntr:bonfires'), Bonfire = require('./../models/Bonfire'), User = require('./../models/User'), - resources = require('./resources'); + resources = require('./resources'), + MDNlinks = require('./../seed_data/bonfireMDNlinks'); /** * Bonfire controller @@ -110,7 +111,9 @@ exports.returnIndividualBonfire = function(req, res, next) { phrase: resources.randomPhrase(), compliment: resources.randomCompliment(), bonfires: bonfire, - bonfireHash: bonfire._id + bonfireHash: bonfire._id, + MDNkeys: bonfire.MDNlinks, + MDNlinks: getMDNlinks(bonfire.MDNlinks) }); }); @@ -147,6 +150,23 @@ function randomString() { return randomstring; }; +/** + * Helper function to populate the MDN links array. +*/ + +function getMDNlinks(links) { + // takes in an array of links, which are strings + var populatedLinks = []; + + // for each key value, push the corresponding link from the MDNlinks object into a new array + links.forEach(function(value, index) { + populatedLinks.push(MDNlinks[value]); + }); + + return populatedLinks; + +}; + /** * */ diff --git a/models/Bonfire.js b/models/Bonfire.js index cee4c8413a..8c0c4599ed 100644 --- a/models/Bonfire.js +++ b/models/Bonfire.js @@ -15,7 +15,8 @@ var bonfireSchema = new mongoose.Schema({ difficulty: String, description: Array, tests: Array, - challengeSeed: String + challengeSeed: String, + MDNlinks: [String] }); module.exports = mongoose.model('Bonfire', bonfireSchema); diff --git a/seed_data/bonfireMDNlinks.js b/seed_data/bonfireMDNlinks.js new file mode 100644 index 0000000000..e604b63919 --- /dev/null +++ b/seed_data/bonfireMDNlinks.js @@ -0,0 +1,66 @@ +// MDN Links + +/* These links are for Bonfires. Each key/value pair is used to render a Bonfire with approrpiate links. + + + The text of the key is what the link text will be, e.g. Global Array Object + General convention is to use the page title of the MDN reference page. +*/ +var links = + { + // ========= GLOBAL OBJECTS + "Global Array Object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array", + "Global Object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object", + "Global String Object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String", + "Boolean Objects" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean", + + // ========= PROPERTIES/MISC + "String.length" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length", + "Arguments object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments", + + // ========== OBJECT METHODS + "Object.getOwnPropertyNames()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames", + "Object.keys()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys", + "Object.hasOwnProperty()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty", + + + // ======== STRING METHODS + "String.charAt()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt", + "String.charCodeAt()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt", + "String.concat()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat", + "String.indexOf()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf", + "String.lastIndexOf()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf", + "String.match()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match", + "String.replace()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace", + "String.slice()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice", + "String.split()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split", + "String.substring()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring", + "String.substr()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr", + "String.toLowerCase()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase", + "String.toString()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString", + "String.toUpperCase()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase", + // ======== ARRAY METHODS + "Array.concat()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat", + "Array.every()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every", + "Array.filter()": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter", + "Array.forEach()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach", + "Array.indexOf()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf", + "Array.join()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join", + "Array.lastIndexOf()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf", + "Array.map()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map", + "Array.pop()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop", + "Array.push()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push", + "Array.reduce()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce", + "Array.reverse()": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse", + "Array.slice()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice", + "Array.some()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some", + "Array.sort()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort", + "Array.splice()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice", + "Array.toString()" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString", + + // ======== GENERAL JAVASCRIPT REFERENCES + "Arithmetic Operators" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators", + "Comparison Operators" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators" + }; + +module.exports = links; diff --git a/seed_data/bonfires.json b/seed_data/bonfires.json index a686f7e7f7..cb0c3585cf 100644 --- a/seed_data/bonfires.json +++ b/seed_data/bonfires.json @@ -31,7 +31,8 @@ "You may need to turn the string into an array before you can reverse it.", "Your result must be a string." ], - "challengeSeed": "function reverseString(str) {\n return str;\r\n}\n\nreverseString('hello');" + "challengeSeed": "function reverseString(str) {\n return str;\r\n}\n\nreverseString('hello');", + "MDNlinks" : ["Global String Object", "String.split()", "Array.reverse()", "Array.join()"] }, { "_id": "a302f7aae1aa3152a5b413bc", @@ -49,7 +50,8 @@ "Factorials are often represented with the shorthand notation n!", "For example: 5! = 1 * 2 * 3 * 4 * 5 = 120f" ], - "challengeSeed": "function factorialize(num) {\n return num;\r\n}\n\nfactorialize(5);" + "challengeSeed": "function factorialize(num) {\n return num;\r\n}\n\nfactorialize(5);", + "MDNlinks" : ["Arithmetic Operators"] }, { "_id": "aaa48de84e1ecc7c742e1124", @@ -70,7 +72,8 @@ "assert.deepEqual(palindrome(\"never odd or even\"), true);", "assert.deepEqual(palindrome(\"nope\"), false);" ], - "challengeSeed": "function palindrome(str) {\n // Good luck!\n return true;\n}\n\n\n\npalindrome(\"eye\");" + "challengeSeed": "function palindrome(str) {\n // Good luck!\n return true;\n}\n\n\n\npalindrome(\"eye\");", + "MDNlinks" : ["String.replace()", "String.toLowerCase()"] }, { "_id": "a26cbbe9ad8655a977e1ceb5", @@ -87,7 +90,8 @@ "expect(findLongestWord('May the force be with you')).to.equal(5);", "expect(findLongestWord('Google do a barrel roll')).to.equal(6);", "expect(findLongestWord('What is the average airspeed velocity of an unladen swallow')).to.equal(8);" - ] + ], + "MDNlinks" : ["String.split()", "String.length"] }, { "_id": "ab6137d4e35944e21037b769", @@ -103,7 +107,8 @@ "expect(titleCase(\"I'm a little tea pot\")).to.equal(\"I'm A Little Tea Pot\");", "expect(titleCase(\"sHoRt AnD sToUt\")).to.equal(\"Short And Stout\");", "expect(titleCase(\"HERE IS MY HANDLE HERE IS MY SPOUT\")).to.equal(\"Here Is My Handle Here Is My Spout\");" - ] + ], + "MDNlinks" : ["String.charAt()"] }, { "_id": "a789b3483989747d63b0e427", @@ -119,7 +124,8 @@ "expect(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])).to.be.a('array');", "(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])).should.eql([5,27,39,1001]);", "assert(largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]).should.eql([9,35,97,1000000]));" - ] + ], + "MDNlinks" : ["Comparison Operators"] }, { "_id": "acda2fb1324d9b0fa741e6b5", @@ -134,7 +140,8 @@ "assert.strictEqual(end('Bastian', 'n'), true, 'should equal true if target equals end of string');", "assert.strictEqual(end('He has to give me a new name', 'name'), true, 'should equal true if target equals end of string');", "assert.strictEqual(end('If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing', 'mountain'), false, 'should equal false if target does not equal end of string');" - ] + ], + "MDNlinks" : ["String.substr()"] }, { "_id": "afcc8d540bea9ea2669306b6", @@ -148,7 +155,8 @@ "assert.strictEqual(repeat('*', 3), '***', 'should repeat a string n times');", "assert.strictEqual(repeat('abc', 3), 'abcabcabc', 'should repeat a string n times');", "assert.strictEqual(repeat('abc', -2), '', 'should return an empty string for negative numbers');" - ] + ], + "MDNlinks" : ["Global String Object"] }, { "_id": "ac6993d51946422351508a41", @@ -163,7 +171,8 @@ "expect(truncate('A-tisket a-tasket A green and yellow basket', 11)).to.eqls('A-tisket...');", "assert(truncate('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length) === 'A-tisket a-tasket A green and yellow basket', 'should not truncate if string is = length');", "assert.strictEqual(truncate('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length + 2), 'A-tisket a-tasket A green and yellow basket', 'should not truncate if string is < length');" - ] + ], + "MDNlinks" : ["String.slice()"] }, { "_id": "a9bd25c716030ec90084d8a1", @@ -177,7 +186,8 @@ "assert.deepEqual(chunk(['a', 'b', 'c', 'd'], 2), [['a', 'b'], ['c', 'd']], 'should return chunked arrays');", "assert.deepEqual(chunk([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]], 'should return chunked arrays');", "assert.deepEqual(chunk([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]], 'should return the last chunk as remaining elements');" - ] + ], + "MDNlinks" : ["Array.push()"] }, { "_id": "ab31c21b530c0dafa9e241ee", @@ -191,7 +201,8 @@ "assert.deepEqual(slasher([1, 2, 3], 2), [3], 'should drop the first two elements');", "assert.deepEqual(slasher([1, 2, 3], 0), [1, 2, 3], 'should return all elements when n < 1');", "assert.deepEqual(slasher([1, 2, 3], 9), [], 'should return an empty array when n >= array.length');" - ] + ], + "MDNlinks" : ["Array.slice()", "Array.splice()"] }, { "_id": "af2170cad53daa0770fabdea", @@ -210,7 +221,8 @@ "expect(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu'])).to.be.true;", "expect(mutation(['Mary', 'Army'])).to.be.true;", "expect(mutation(['Alien', 'line'])).to.be.true;" - ] + ], + "MDNlinks" : ["Array.sort()"] }, { "_id": "adf08ec01beb4f99fc7a68f2", @@ -225,7 +237,8 @@ "assert.deepEqual(bouncer([7, 'ate', '', false, 9]), [7, 'ate', 9], 'should remove falsey values');", "assert.deepEqual(bouncer(['a', 'b', 'c']), ['a', 'b', 'c'], 'should return full array if no falsey elements');", "assert.deepEqual(bouncer([false, null, 0]), [], 'should return empty array if all elements are falsey');" - ] + ], + "MDNlinks" : ["Boolean Objects", "Array.filter()"] }, { "_id":"a8e512fbe388ac2f9198f0fa", @@ -238,7 +251,8 @@ "tests":[ "assert.deepEqual(where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' }), [{ first: 'Tybalt', last: 'Capulet' }], 'should return an array of objects');", "assert.deepEqual(where([{ 'a': 1 }, { 'a': 1 }, { 'a': 1, 'b': 2 }], { 'a': 1 }), [{ 'a': 1 }, { 'a': 1 }, { 'a': 1, 'b': 2 }], 'should return with multiples');" - ] + ], + "MDNlinks" : ["Global Object", "Object.hasOwnProperty()", "Object.keys()"] }, { "_id":"a39963a4c10bc8b4d4f06d7e", @@ -251,7 +265,8 @@ "tests": [ "assert.deepEqual(destroyer([1, 2, 3, 1, 2, 3], 2, 3), [1, 1], 'should remove correct values from an array');", "assert.deepEqual(destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3), [1, 5, 1], 'should remove correct values from an array');" - ] + ], + "MDNlinks" : ["Array.filter()"] }, { "_id": "a24c1a4622e3c05097f71d67", diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 63e6be052e..aed449bdb5 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -73,9 +73,14 @@ block content .col-xs-12 for sentence in details p!= sentence + #MDN-links + h4 Here are some helpful links. + for link, index in MDNlinks + ul: li: a(href=""+link, target="_blank") !{MDNkeys[index]} #less-info.btn.btn-primary.btn-block.btn-primary-ghost span.ion-arrow-up-b | Less information + #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) br form.code @@ -92,6 +97,7 @@ block content var started = Math.floor(Date.now() / 1000); var _ = R; var dashed = !{JSON.stringify(dashedName)}; + .col-xs-12.col-sm-12.col-md-8 #mainEditorPanel form.code @@ -143,5 +149,9 @@ block content $('.btn-twitter').attr('href', url); } ); + var MDNlinks = !{JSON.stringify(MDNlinks)}; + if (!MDNlinks.length) { + $('#MDN-links').addClass('collapse'); + }