Created
March 22, 2016 14:57
-
-
Save joshskeen/2567f0a9f65668a6c504 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.change_code = 1; | |
var _ = require('lodash'); | |
function MadlibHelper (obj) { | |
this.started = false; | |
this.madlibIndex = 0; | |
this.currentStep = 0; | |
this.madlibs = [ | |
{ | |
title: 'A Cold November Day', | |
template: 'It was a ${adjective_1}, cold November day. I awoke to the ${adjective_2} smell of ${type_of_bird} roasting in the ${room_in_house} downstairs. I ${verb_past_tense} down the stairs to see if I could help ${verb} with dinner. My friend said, "See if ${relative_name}" needs a fresh ${noun_1}." So I carried a tray of glasses full of ${a_liquid} into the ${verb_ending_in_ing} room. When I got there, I couldn\'t believe my ${part_of_body_plural}! There were ${plural_noun} ${verb_ending_in_ing_2} on the ${noun_2}!', | |
steps: [ | |
{ | |
value: null, | |
template_key: 'adjective_1', | |
prompt: 'an Adjective', | |
help: 'Speak an adjective to add it to the madlib. An adjective is a word that modifies a noun (or pronoun) to make it more specific: a rotten egg, a cloudy day, or a tall, cool glass of water. What adjective would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'adjective_2', | |
prompt: 'another Adjective', | |
help: 'Speak an adjective to add it to the madlib. An adjective is a word that modifies a noun (or pronoun) to make it more specific: a rotten egg, a cloudy day, or a tall, cool glass of water. What adjective would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'type_of_bird', | |
prompt: 'a Type of bird', | |
help: 'Speak a type of bird to add it to the madlib. What type of bird would you like?', | |
}, | |
{ | |
value: null, | |
template_key: 'room_in_house', | |
prompt: 'a name of Room in a house', | |
help: 'Speak a name of a room in a house. What room in a house would you like?', | |
}, | |
{ | |
value: null, | |
template_key: 'verb_past_tense', | |
prompt: 'a past tense verb', | |
help: 'Speak a past tense verb to add it to the madlib. A past tense verb expresses activity, action, state, or being in the past. What past tense verb would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'verb', | |
prompt: 'a verb', | |
help: 'speak a verb to add it to the madlib. A verb is a word used to describe an action, state, or occurence and forming the main part of the predicate in a sentence, such as hear, become, happen. What verb would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'relative_name', | |
prompt: 'a relative\'s name', | |
help: 'Speak a relative\'s name to add it to the madlib. What relative\'s name would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'noun_1', | |
prompt: 'a noun', | |
help: 'Speak a noun to add it to the madlib. A noun used to identify any of a class of people, places, or things. What noun would you like?' | |
}, | |
{ | |
value: null, | |
template_key: 'a_liquid', | |
prompt: 'a liquid', | |
help: 'Speak a type of liquid to add it to the madlib. For example, kool-aid, lava, or orange juice are all liquids. What liquid do you want to add?' | |
}, | |
{ | |
value: null, | |
template_key: 'verb_ending_in_ing', | |
prompt: 'a verb ending in ing', | |
help: 'Speak a verb ending in ing to add it to the madlib. Running, living, or singing are all examples. What verb ending in ing do you want to add?' | |
}, | |
{ | |
value: null, | |
template_key: 'part_of_body_plural', | |
prompt: 'a plural part of the body', | |
help: 'Speak a plural part of the body to add it to the madlib. For example, fingers, eyes, or ears. What plural part of the body do you want to add?' | |
}, | |
{ | |
value: null, | |
template_key: 'plural_noun', | |
prompt: 'a plural noun', | |
help: 'Speak a plural noun to add it to the madlib. What plural noun do you want to add?' | |
}, | |
{ | |
value: null, | |
template_key: 'verb_ending_in_ing_2', | |
prompt: 'a verb ending in ing', | |
help: 'Speak a verb ending in ing to add it to the madlib. Running, living, or singing are all examples. What verb ending in ing do you want to add?' | |
}, | |
{ | |
value: null, | |
template_key: 'noun_2', | |
prompt: 'a noun', | |
help: 'Speak a noun to add it to the madlib. A noun used to identify any of a class of people, places, or things. For example, pencil, jelly bean, and Bill Clinton are all nouns. What noun would you like?' | |
} | |
] | |
} | |
]; | |
for (var prop in obj) this[prop] = obj[prop]; | |
} | |
MadlibHelper.prototype.completed = function() { | |
return this.currentStep === (this.currentMadlib().steps.length - 1); | |
}; | |
MadlibHelper.prototype.getPrompt = function() { | |
return this.getStep().prompt; | |
}; | |
MadlibHelper.prototype.getStep = function() { | |
return this.currentMadlib().steps[this.currentStep]; | |
}; | |
MadlibHelper.prototype.buildMadlib = function() { | |
var currentMadlib = this.currentMadlib(); | |
var templateValues = _.reduce(currentMadlib.steps, function(accumulator, step) { | |
accumulator[step.template_key] = step.value; | |
return accumulator; | |
}, {}); | |
var compiledTemplate = _.template(currentMadlib.template); | |
return compiledTemplate(templateValues); | |
}; | |
MadlibHelper.prototype.currentMadlib = function() { | |
return this.madlibs[this.madlibIndex]; | |
}; | |
module.exports = MadlibHelper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment