diff --git a/dist/cmd-resume.js b/dist/cmd-resume.js index 8bf250a..acea5f0 100644 --- a/dist/cmd-resume.js +++ b/dist/cmd-resume.js @@ -1,4 +1,4 @@ -/* v4.4.4 of CMD Resume by Brendon Body(https://github.com/bbody/CMD-Resume.git) */ +/* v5.0.0 of CMD Resume by Brendon Body(https://github.com/bbody/CMD-Resume.git) */ ;(function($){ "use strict"; @@ -34,7 +34,7 @@ NEW_LINE: "\n", SEMI_COLON: ";", EMPTY: "", - TAB: "\t", + TAB: " ", COLON: ":", COMA: ", ", DASH: " - ", @@ -88,9 +88,40 @@ } }; + // Get value + var getDataFromArrayKey = function(data, keys) { + keys = getKeyArray(keys); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + + if (typeof data[key] === "undefined") { + return false; + } + + data = data[key]; + } + + return data; + }; + + // Get key array + var getKeyArray = function(key) { + if (Array.isArray(key)) { + return key; + } else { + return [key]; + } + }; + // Check if an object has key and has length - var isDefinedNotEmpty = function(object, key) { - return key && typeof object[key] !== "undefined" && object[key].length; + var isDefinedNotEmpty = function(object, key, isObject) { + if (!key || !object) { + return false; + } + + var data = getDataFromArrayKey(object, getKeyArray(key)); + + return data && (!!isObject || data.length); }; // Calculate the formatting @@ -463,6 +494,323 @@ system: systemHandlerFunction }; + self.CMD = { + BASIC: "basic", + ARRAY: "array", + CALCULATED: "calculated", + SYSTEM: "system", + getCommand: function(cmd) { + return self.commandProcessor[cmd]; + } + }; + + self.allCommands = [ + { + name: "man", + title: "man".setCommand(), + description: "describes what each command does", + type: self.CMD.SYSTEM, + handler: function(command) { + if (!command) { + return "man:".setCommand() + " No command entered."; + } else if (self.hasCommand(command)) { + return command.setCommand() + CONSTANTS.DASH + + self.commands[command].description; + } else { + return "man".setCommand() + + ": " + command.setCommand() + + " is an unknown command."; + } + } + }, + { + name: "Help", + description: "lists help for all the commands", + type: self.CMD.SYSTEM, + handler: function() { + var commands = "Available Commands:".setTitle(); + $.map(self.commands, function(value, key) { + commands += CONSTANTS.NEW_LINE; + commands += key.setCommand(); + commands += CONSTANTS.DASH; + commands += value.description; + }); + return commands; + } + }, + { + name: "Name", + description: "owner of the résumé", + data: ["basics", "name"], + type: self.CMD.BASIC + }, + { + name: "About", + description: "about me", + data: ["basics", "summary"], + type: self.CMD.BASIC + }, + { + name: "pdf", + title: "Résumé PDF", + description: "pdf version of the résumé", + data: ["basics", "pdfLink"], + type: self.CMD.CALCULATED, + handler: function(data) { + window.open(data); + return decodeURIComponent(escape(data)) + CONSTANTS.NEW_LINE + + "Hint: May need to allow pop-ups."; + } + }, + { + name: "Location", + description: "current location", + data: ["basics", "location"], + dataIsObject: true, + type: self.CMD.CALCULATED, + handler: function(data) { + var results = []; + + if (data.city) { + results.push(data.city); + } + + if (data.region) { + results.push(data.region); + } + + if (data.countryCode) { + results.push(data.countryCode); + } + + return results.join(CONSTANTS.COMA); + } + }, + { + name: "Label", + description: "title", + data: ["basics", "label"], + type: self.CMD.BASIC + }, + { + name: "Education", + description: "education history", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.institution; + }, + title: function(value) { + return getFullDegree(value.studyType, value.area); + }, + date: function(value) { + return getDate(value.startDate, value.endDate); + } + } + }, + { + name: "Employment", + description: "employment history", + data: "work", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.company; + }, + title: function(value) { + return value.position; + }, + date: function(value) { + return getDate(value.startDate, value.endDate); + } + } + }, + { + name: "Volunteering", + description: "volunteering history", + data: "volunteer", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.organization; + }, + title: function(value) { + return value.position; + }, + date: function(value) { + return getDate(value.startDate, value.endDate); + } + } + }, + { + name: "socialmedia", + title: "Social Media", + description: "social media profiles", + data: ["basics", "profiles"], + dataIsObject: true, + type: self.CMD.CALCULATED, + handler: function(data) { + var resultArray = []; + + data.forEach(function(value) { + var socialMediaProfile = buildSocialNetwork(value); + if (!socialMediaProfile) { + return true; + } + + resultArray.push(socialMediaProfile); + }); + + return resultArray.join(CONSTANTS.NEW_LINE); + } + }, + { + name: "Skills", + description: "skills obtained", + type: self.CMD.CALCULATED, + handler: function(data) { + var result = CONSTANTS.EMPTY; + + data.forEach(function(value, index) { + if (value.level) { + result += value.level; + if (value.name) { + result += " in "; + } + } + + if (value.name) { + result += value.name; + } + + // Make sure not the last entry + if (index !== data.length - 1) { + result += CONSTANTS.NEW_LINE; + } + }); + return result; + } + }, + { + name: "Awards", + description: "awards obtained", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.awarder; + }, + title: function(value) { + return value.title; + }, + date: function(value) { + return value.date; + } + } + }, + { + name: "Publications", + description: "publications produced", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.publisher; + }, + title: function(value) { + return value.name; + }, + date: function(value) { + return value.releaseDate; + } + } + }, + { + name: "Languages", + description: "languages", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.language; + }, + title: function(value) { + return value.fluency; + } + } + }, + { + name: "Interests", + description: "interests", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.name ? value.name.setName() : ""; + }, + title: function(value) { + return value.keywords ? value.keywords.join(CONSTANTS.COMA) : ""; + } + } + }, + { + name: "References", + description: "references", + type: self.CMD.ARRAY, + handlers: { + organisation: function(value) { + return value.name ? value.name.setName() : ""; + }, + title: function(value) { + return value.reference; + } + } + }, + { + name: "splash", + title: "Splash Screen", + description: "print the welcome screen", + type: self.CMD.SYSTEM, + handler: function() { + var results = CONSTANTS.EMPTY; + + // Return custom splash if it exists + if (self.data.customSplash) { + results += self.data.customSplash; + } else { + if (self.data.basics.name) { + results += "Welcome to " + + self.data.basics.name.setName() + + "'s résumé."; + } else { + results += "Welcome to my résumé."; + } + } + + results += CONSTANTS.NEW_LINE; + results += CONSTANTS.NEW_LINE; + results += "Type "; + results += "help".setCommand(); + results += " for commands"; + + return results; + } + }, + { + name: "pgpkey", + title: "PGP Key", + description: "public PGP key", + type: self.CMD.CALCULATED, + handler: function() { + var results = CONSTANTS.EMPTY; + + for (var i = 0; i < self.data.pgpkey.length; i++) { + results += self.data.pgpkey[i]; + if (i !== self.data.pgpkey.length - 1) { + results += CONSTANTS.NEW_LINE; + } + } + return results.setPGP(); + } + } + ]; + self.initTerminal = function() { self.term = element.terminal(function(command, term) { // jscs:disable requireCamelCaseOrUpperCaseIdentifiers @@ -506,9 +854,9 @@ }; self.showTitle = function(commandType, top) { - if (commandType === self.commandProcessor.system) { + if (commandType === self.CMD.SYSTEM) { return false; - } else if (top && (commandType === self.commandProcessor.array)) { + } else if (top && (commandType === self.CMD.ARRAY)) { return false; } @@ -523,7 +871,7 @@ result += command.title.setTitle(); } - result += command.type(command, top); + result += self.CMD.getCommand(command.type)(command, top); return result; }; @@ -543,405 +891,49 @@ return self.commandList.indexOf(command) >= 0; }; - self.initMan = function() { - self.commands.man = { - title: "man".setCommand(), - description: "describes what each command does", - type: self.commandProcessor.system, - handler: function(command) { - if (!command) { - return "man:".setCommand() + " No command entered."; - } else if (self.hasCommand(command)) { - return command.setCommand() + CONSTANTS.DASH + - self.commands[command].description; - } else { - return "man".setCommand() + - ": " + command.setCommand() + - " is an unknown command."; - } - } - }; - }; - - self.initHelp = function() { - self.commands.help = { - title: "Help", - description: "lists help for all the commands", - type: self.commandProcessor.system, - handler: function() { - var commands = "Available Commands:".setTitle(); - $.map(self.commands, function(value, key) { - commands += CONSTANTS.NEW_LINE; - commands += key.setCommand(); - commands += CONSTANTS.DASH; - commands += value.description; - }); - return commands; - } - }; - }; - self.initClear = function() { self.commands.clear = { description: "clear command history from screen" }; }; - self.initName = function() { - if (isDefinedNotEmpty(self.data.basics, "name")) { - self.commands.name = { - title: "Name", - description: "owner of the résumé", - data: self.data.basics.name, - type: self.commandProcessor.basic - }; - } - }; - - self.initSummary = function() { - if (isDefinedNotEmpty(self.data.basics, "summary")) { - self.commands.about = { - title: "About", - description: "about me", - data: self.data.basics.summary, - type: self.commandProcessor.basic - }; - } - }; - - self.initPdfLink = function() { - if (isDefinedNotEmpty(self.data.basics, "pdfLink")) { - self.commands.pdf = { - title: "Résumé PDF", - description: "pdf version of the résumé", - data: self.data.basics.pdfLink, - type: self.commandProcessor.calculated, - handler: function(data) { - window.open(data); - return decodeURIComponent(escape(data)) + CONSTANTS.NEW_LINE + - "Hint: May need to allow pop-ups."; - } - }; - } - }; - - self.initLocation = function() { - // Is an object, so don't need to check length - if (self.data.basics.location) { - self.commands.location = { - title: "Location", - description: "current location", - data: self.data.basics.location, - type: self.commandProcessor.calculated, - handler: function(data) { - var results = []; - - if (data.city) { - results.push(data.city); - } - - if (data.region) { - results.push(data.region); - } - - if (data.countryCode) { - results.push(data.countryCode); - } - - return results.join(CONSTANTS.COMA); - } - }; - } - }; - - self.initLabel = function() { - if (isDefinedNotEmpty(self.data.basics, "label")) { - self.commands.lookingfor = { - title: "Looking For", - description: "looking for what kind of position", - data: self.data.basics.label, - type: self.commandProcessor.basic - }; - } - }; - - self.initProfiles = function() { - if (isDefinedNotEmpty(self.data.basics, "profiles")) { - self.commands.socialmedia = { - title: "Social Media", - description: "social media profiles", - data: self.data.basics.profiles, - type: self.commandProcessor.calculated, - handler: function(data) { - var resultArray = []; - - data.forEach(function(value) { - var socialMediaProfile = buildSocialNetwork(value); - if (!socialMediaProfile) { - return true; - } - - resultArray.push(socialMediaProfile); - }); - - return resultArray.join(CONSTANTS.NEW_LINE); - } - }; - } - }; - - self.initSkills = function() { - if (isDefinedNotEmpty(self.data, "skills")) { - self.commands.skills = { - title: "Skills", - description: "skills obtained", - type: self.commandProcessor.calculated, - data: self.data.skills, - handler: function(data) { - var result = CONSTANTS.EMPTY; - - data.forEach(function(value, index) { - if (value.level) { - result += value.level; - if (value.name) { - result += " in "; - } - } - - if (value.name) { - result += value.name; - } - - // Make sure not the last entry - if (index !== data.length - 1) { - result += CONSTANTS.NEW_LINE; - } - }); - return result; - } + self.addCommand = function(command) { + if (command.type === self.CMD.SYSTEM || + isDefinedNotEmpty(self.data, + command.data ? command.data : command.name.toLowerCase(), + !!command.dataIsObject)) { + var tempCommand = { + title: command.title ? command.title : command.name, + description: command.description, + type: command.type }; - } - }; - self.initSplash = function() { - self.commands.splash = { - title: "Splash Screen", - description: "print the welcome screen", - type: self.commandProcessor.system, - handler: function() { - var results = CONSTANTS.EMPTY; - - // Return custom splash if it exists - if (self.data.customSplash) { - results += self.data.customSplash; - } else { - if (self.data.basics.name) { - results += "Welcome to " + - self.data.basics.name.setName() + - "'s résumé."; - } else { - results += "Welcome to my résumé."; - } - } - - results += CONSTANTS.NEW_LINE; - results += CONSTANTS.NEW_LINE; - results += "Type "; - results += "help".setCommand(); - results += " for commands"; - - return results; + if (command.type !== self.CMD.SYSTEM) { + tempCommand.data = getDataFromArrayKey(self.data, + command.data ? command.data : command.name.toLowerCase()); } - }; - }; - self.initEducation = function() { - if (isDefinedNotEmpty(self.data, "education")) { - self.commands.education = { - title: "Education", - description: "education history", - data: self.data.education, - type: self.commandProcessor.array, - handlers: { - organisation: function(value) { - return value.institution; - }, - title: function(value) { - return getFullDegree(value.studyType, value.area); - }, - date: function(value) { - return getDate(value.startDate, value.endDate); - } - } - }; - } - }; - - self.initWork = function() { - if (isDefinedNotEmpty(self.data, "work")) { - self.commands.employment = { - title: "Employment", - description: "employment history", - data: self.data.work, - type: self.commandProcessor.array, - handlers: { - organisation: function(value) { - return value.company; - }, - title: function(value) { - return value.position; - }, - date: function(value) { - return getDate(value.startDate, value.endDate); - } - } - }; - } - }; - - self.initVolunteer = function() { - if (isDefinedNotEmpty(self.data, "volunteer")) { - self.commands.volunteering = { - title: "Volunteering", - description: "volunteering history", - type: self.commandProcessor.array, - data: self.data.volunteer, - handlers: { - organisation: function(value) { - return value.organization; - }, - title: function(value) { - return value.position; - }, - date: function(value) { - return getDate(value.startDate, value.endDate); - } - } - }; - } - }; - - self.initAwards = function() { - if (isDefinedNotEmpty(self.data, "awards")) { - self.commands.awards = { - title: "Awards", - description: "awards obtained", - type: self.commandProcessor.array, - data: self.data.awards, - handlers: { - organisation: function(value) { - return value.awarder; - }, - title: function(value) { - return value.title; - }, - date: function(value) { - return value.date; - } - } - }; - } - }; - - self.initPublications = function() { - if (isDefinedNotEmpty(self.data, "publications")) { - self.commands.publications = { - title: "Publications", - description: "publications produced", - type: self.commandProcessor.array, - data: self.data.publications, - handlers: { - organisation: function(value) { - return value.publisher; - }, - title: function(value) { - return value.name; - }, - date: function(value) { - return value.releaseDate; - } - } - }; - } - }; + if (command.handlers) { + tempCommand.handlers = command.handlers; + } - self.initLanguages = function() { - if (isDefinedNotEmpty(self.data, "languages")) { - self.commands.languages = { - title: "Languages", - description: "languages", - type: self.commandProcessor.array, - data: self.data.languages, - handlers: { - organisation: function(value) { - return value.language; - }, - title: function(value) { - return value.fluency; - } - } - }; - } - }; + if (command.handler) { + tempCommand.handler = command.handler; + } - self.initInterests = function() { - if (isDefinedNotEmpty(self.data, "interests")) { - self.commands.interests = { - title: "Interests", - description: "interests", - type: self.commandProcessor.array, - data: self.data.interests, - handlers: { - organisation: function(value) { - return value.name ? value.name.setName() : ""; - }, - title: function(value) { - return value.keywords ? value.keywords.join(CONSTANTS.COMA) : ""; - } - } - }; + self.commands[command.name.toLowerCase()] = tempCommand; } }; - self.initReferences = function() { - if (isDefinedNotEmpty(self.data, "references")) { - self.commands.references = { - title: "References", - description: "references", - type: self.commandProcessor.array, - data: self.data.references, - handlers: { - organisation: function(value) { - return value.name ? value.name.setName() : ""; - }, - title: function(value) { - return value.reference; - } - } - }; - } + self.addCommands = function() { + self.allCommands.forEach(function(command) { + self.addCommand(command); + }); }; self.initCommands = function() { - self.initMan(); - self.initHelp(); self.initClear(); - self.initName(); - self.initSummary(); - self.initPdfLink(); - self.initLocation(); - self.initLabel(); - self.initProfiles(); - self.initSkills(); - self.initSplash(); - self.initEducation(); - self.initWork(); - self.initVolunteer(); - self.initAwards(); - self.initPublications(); - self.initLanguages(); - self.initInterests(); - self.initReferences(); + self.addCommands(); }; self.initSocialMedia = function() { @@ -971,14 +963,15 @@ formattedString += formatGithub(value, key === 0); }); - self.commands.github = { + self.data.githubCache = formattedString; + + self.addCommand({ + name: "Github", title: "Github Repositories", description: "list Github repositories", - type: self.commandProcessor.basic, - data: formattedString - }; - - self.commandList.push("github"); + type: self.CMD.BASIC, + data: "githubCache" + }); }); }; @@ -1023,25 +1016,6 @@ $.getJSON(options.extraDetails, function(extraResponse) { self.data.pgpkey = extraResponse.pgpkey; - if (self.data.pgpkey) { - self.commands.pgpkey = { - title: "PGP Key", - description: "public PGP key", - type: self.commandProcessor.calculated, - handler: function() { - var results = CONSTANTS.EMPTY; - - for (var i = 0; i < self.data.pgpkey.length; i++) { - results += self.data.pgpkey[i]; - if (i !== self.data.pgpkey.length - 1) { - results += CONSTANTS.NEW_LINE; - } - } - return results.setPGP(); - } - }; - } - if (extraResponse.github) { self.data.basics.githubUsername = extraResponse.github; self.data.githubCache = CONSTANTS.EMPTY; diff --git a/dist/cmd-resume.min.js b/dist/cmd-resume.min.js index 05b3185..8fa063a 100644 --- a/dist/cmd-resume.min.js +++ b/dist/cmd-resume.min.js @@ -1,2 +1,2 @@ -/* v4.4.4 of CMD Resume by Brendon Body(https://github.com/bbody/CMD-Resume.git) */ -!function(c){"use strict";var d={standard:{color:"white",bold:!1,italic:!1,backgroundColor:"#000"},title:{color:"red",bold:!0},command:{color:"white",bold:!1,italic:!0},pgp:{color:"white",bold:!1,italic:!0},name:{color:"green",bold:!0}},u="\n",m=";",l="",p="\t",r=", ",f=" - ",h={STANDARD:0,TITLE:1,COMMAND:2,NAME:3,PGP:4,toString:function(t){switch(t){case h.TITLE:return"title";case h.COMMAND:return"command";case h.NAME:return"name";case h.PGP:return"pgp";case h.STANDARD:return"standard";default:return!1}}},g=function(t){return null==t},b=function(t){return!!t&&c.terminal.valid_color(t)},y=function(t,n){return n&&void 0!==t[n]&&t[n].length};String.prototype.setFormat=function(t){var n=l;if(0===this.length)return n;var a,e,i,o,r=h.toString(t),s=c.extend({},d.standard);return r&&t!==h.STANDARD&&(a=s,(e=d[r]).color&&b(e.color)&&(a.color=e.color),e.bold&&(a.bold=e.bold),e.italic&&(a.italic=e.italic),e.backgroundColor&&b(e.backgroundColor)&&(a.backgroundColor=e.backgroundColor),s=a),s.bold&&(n+="b"),s.italic&&(n+="i"),n+=m,n+=s.color,n+=m,n+=s.backgroundColor,i=n,(o=this)?"[["+(i=i||l)+"]"+o+"]":l},String.prototype.setTitle=function(){return this.setFormat(h.TITLE)},String.prototype.setCommand=function(){return this.setFormat(h.COMMAND)},String.prototype.setName=function(){return this.setFormat(h.NAME)},String.prototype.setPGP=function(){return this.setFormat(h.PGP)};var w=function(t){var n=u;return n+=t&&t.data?t.data:l},k=function(t){if(t){if(t.handler)return t.handler(t.data);if(t.data)return t.data}return l},P=function(t){return u+k(t)},C=function(o,r){var s=l;return o.handlers&&o.data.some(function(t){var n=[];if(o.handlers.organisation){var a=o.handlers.organisation(t);a&&n.push(a)}if(o.handlers.title){var e=o.handlers.title(t);e&&n.push(e)}if(o.handlers.date){var i=o.handlers.date(t);i&&n.push(i)}return!r&&n.length&&(s+=u),s+=n.join(p),r}),s},v=function(t,n){return n||t?n?t?t+f+n:"Until "+n:t+" - Present":l},s=function(t){return t.replace("mailto:","")},L=function(t,n,a){return"email"===t.toLowerCase()?(i=a,o="",(e=n)?o=s(e):i&&(o=s(i)),o||!1):n||!(!a||!(n=function(t,n){if(!t||!n)return l;switch(t.toLowerCase()){case"twitter":return"https://www.twitter.com/"+n;case"github":return"https://www.github.com/"+n;case"linkedin":return"https://www.linkedin.com/in/"+n;case"facebook":return"https://www.facebook.com/"+n;case"reddit":return"https://www.reddit.com/user/"+n;case"hackernews":return"https://news.ycombinator.com/user?id="+n;default:return l}}(t,a)))&&n;var e,i,o};String.prototype.upperCaseFirstLetter=function(){return this&&this.length?this.charAt(0).toUpperCase()+this.slice(1):""};c.fn.CMDResume=function(t,n){var a,e,i,o=this;a=d,e=n=n||{},i=c.extend(!0,{},a),c.each(e,function(t,n){a[t]&&(n.color&&(i[t].color=n.color),g(n.bold)||(i[t].bold=n.bold),g(n.italic)||(i[t].italic=n.italic),n.backgroundColor&&(i[t].backgroundColor=n.backgroundColor))}),d=i;var s={commands:{}};return s.commandProcessor={basic:w,array:C,calculated:P,system:k},s.initTerminal=function(){s.term=o.terminal(function(t,n){var a=c.terminal.split_command(t);n.echo(s.commandLineParse(a.name,a.args)+u)},s.settings)},s.initGithubForks=function(t){s.showForks=t.showForks||"true"===t.showForks},s.init=function(t){s.initGithubForks(t),s.initVariables(),s.initCommands(),s.initSettings(),s.initHTMLTitle(),s.initTerminal()},s.commandLineParse=function(t,n){var a=!g(n[0])&&0