Links from database are being passed to the view. TODO create links

This commit is contained in:
A. Drake
2015-03-23 23:20:19 -04:00
parent 5bfd8a8d54
commit 0bf68fea5f
5 changed files with 48 additions and 4 deletions

View File

@ -2,7 +2,8 @@ var _ = require('lodash'),
debug = require('debug')('freecc:cntr:bonfires'), debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire'), Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'), User = require('./../models/User'),
resources = require('./resources'); resources = require('./resources')
MDNlinks = require('./../seed_data/bonfireMDNlinks');
/** /**
* Bonfire controller * Bonfire controller
@ -110,7 +111,8 @@ exports.returnIndividualBonfire = function(req, res, next) {
phrase: resources.randomPhrase(), phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(), compliment: resources.randomCompliment(),
bonfires: bonfire, bonfires: bonfire,
bonfireHash: bonfire._id bonfireHash: bonfire._id,
MDNlinks: getMDNlinks(bonfire.MDNlinks)
}); });
}); });
@ -147,6 +149,23 @@ function randomString() {
return 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;
};
/** /**
* *
*/ */

View File

@ -15,7 +15,8 @@ var bonfireSchema = new mongoose.Schema({
difficulty: String, difficulty: String,
description: Array, description: Array,
tests: Array, tests: Array,
challengeSeed: String challengeSeed: String,
MDNlinks: [String]
}); });
module.exports = mongoose.model('Bonfire', bonfireSchema); module.exports = mongoose.model('Bonfire', bonfireSchema);

View File

@ -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;

View File

@ -31,7 +31,8 @@
"You may need to turn the string into an array before you can reverse it.", "You may need to turn the string into an array before you can reverse it.",
"Your result must be a string." "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", "_id": "a302f7aae1aa3152a5b413bc",

View File

@ -92,6 +92,7 @@ block content
var started = Math.floor(Date.now() / 1000); var started = Math.floor(Date.now() / 1000);
var _ = R; var _ = R;
var dashed = !{JSON.stringify(dashedName)}; var dashed = !{JSON.stringify(dashedName)};
var MDNlinks = !{JSON.stringify(MDNlinks)};
.col-xs-12.col-sm-12.col-md-8 .col-xs-12.col-sm-12.col-md-8
#mainEditorPanel #mainEditorPanel
form.code form.code