From 0bf68fea5ffe377d3f196556b4e93f4fccd574a8 Mon Sep 17 00:00:00 2001 From: "A. Drake" Date: Mon, 23 Mar 2015 23:20:19 -0400 Subject: [PATCH] Links from database are being passed to the view. TODO create links --- controllers/bonfire.js | 23 +++++++++++++++++++++-- models/Bonfire.js | 3 ++- seed_data/bonfireMDNlinks.js | 22 ++++++++++++++++++++++ seed_data/bonfires.json | 3 ++- views/bonfire/show.jade | 1 + 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 seed_data/bonfireMDNlinks.js diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 83431a390d..e600375752 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,8 @@ exports.returnIndividualBonfire = function(req, res, next) { phrase: resources.randomPhrase(), compliment: resources.randomCompliment(), bonfires: bonfire, - bonfireHash: bonfire._id + bonfireHash: bonfire._id, + MDNlinks: getMDNlinks(bonfire.MDNlinks) }); }); @@ -147,6 +149,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..9d80585185 --- /dev/null +++ b/seed_data/bonfireMDNlinks.js @@ -0,0 +1,22 @@ +// MDN Links + +/* These links are for Bonfires. Each key/value pair is used to render a Bonfire with approrpiate links. + Making an effort to keep methods in alphabetical order will help others behind you. + +*/ +var links = + { + // ========= GLOBAL OBJECTS + "Array-global" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array", + "Object-global" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object", + "String-global" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String", + + // ======== STRING METHODS + "string-split" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split", + + // ======== ARRAY METHODS + "array-join" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join", + "array-reverse": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse" + }; + +module.exports = links; diff --git a/seed_data/bonfires.json b/seed_data/bonfires.json index c298c97db7..00b9fa10bd 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');", + "links" : ["String-global", "string-methods.split"] }, { "_id": "a302f7aae1aa3152a5b413bc", diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 63e6be052e..007caa6fc5 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -92,6 +92,7 @@ block content var started = Math.floor(Date.now() / 1000); var _ = R; var dashed = !{JSON.stringify(dashedName)}; + var MDNlinks = !{JSON.stringify(MDNlinks)}; .col-xs-12.col-sm-12.col-md-8 #mainEditorPanel form.code