This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dom Harrington
committed
Mar 14, 2018
1 parent
5f19a79
commit 098ae59
Showing
1 changed file
with
64 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,78 @@ | ||
// exports.replaceVars = function(out, variables) { | ||
// const varReplacer = function (variables, defaults = [], glossaryTerms) { | ||
// return (match, v) => { | ||
// let isDefault = false; | ||
|
||
// // Handle glossary terms | ||
// if (v.indexOf('glossary:') === 0) { | ||
// const term = v.replace('glossary:', ''); | ||
// const foundTerm = glossaryTerms.filter(gTerm => term === gTerm.term)[0]; | ||
// if (foundTerm) { | ||
// return ( | ||
// ` | ||
// <span class="glossary-tooltip" v=${foundTerm.term}> | ||
// <span class="glossary-item highlight">${foundTerm.term} </span> | ||
// <span class="tooltip-content"> | ||
// <span class="tooltip-content-body"> | ||
// - <strong class="term">${foundTerm.term}</strong> - | ||
// ${foundTerm.definition} | ||
// </span> | ||
// </span> | ||
// </span> | ||
// ` | ||
// ); | ||
// } | ||
// } | ||
|
||
// // Don't break the <<keys:>> syntax | ||
// if (v.indexOf('keys:') === 0) { | ||
// // tombstone('keysVariableFormat', '2-23-2018', { var: v }); | ||
// v = v.split('keys:')[1]; | ||
// } | ||
|
||
// let data = variables && variables[v] ? variables[v] : undefined; | ||
|
||
// const inKeys = variables && variables.keys && variables.keys[0][v]; | ||
// const inVariables = variables && variables[v]; | ||
|
||
// // Use default | ||
// if (!variables || !(inKeys || inVariables)) { | ||
// isDefault = true; | ||
// const userDefault = defaults.find(d => d.name === v); | ||
// data = userDefault ? userDefault.default : v.toUpperCase(); | ||
// } else if (inKeys) { | ||
// // Keys array was passed in | ||
// // We figure out keys in the frontend (so we have selectedApp) | ||
// return `<variable-keys v=${v} data="${v.toUpperCase()}"></variable-keys>`; | ||
// } | ||
|
||
// // Just a signle value | ||
// return `<variable v=${v} data="${data}" isdefault="${isDefault}"></variable>`; | ||
// }; | ||
// }; | ||
|
||
// exports.replaceVars = function (variables, defaults, glossaryTerms, out) { | ||
// // If no variables (either from default or jwt, don't change anything) | ||
// if (!variables) { | ||
// if (!variables && !defaults) { | ||
// return out; | ||
// } | ||
// | ||
|
||
// // Variables will initially be string | ||
// if (typeof variables === 'string') { | ||
// try { | ||
// variables = JSON.parse(variables); | ||
// } catch (e) { | ||
// // TODO-JWT Try to figure out a way to deal with error | ||
// console.log(e); | ||
// return out; | ||
// } | ||
// } | ||
// | ||
// out = out.replace(/<<([-\w:]*?)>>/g, (match, v) => { | ||
// const type = v.indexOf('keys:') >= 0 ? 'keys' : 'user'; | ||
// | ||
// if (type === 'keys') { | ||
// const vName = v.split(':')[1]; | ||
// if (variables.default) { | ||
// for (const keyVar of variables.keys) { | ||
// if (keyVar.name === vName) { | ||
// return `<variable-keys v=${v} data="${keyVar.default}" isdefault='true'></variable-keys>`; | ||
// } | ||
// } | ||
// } else if (variables.fromReadmeKey) { | ||
// return `<variable-keys v=${v} data="${vName.toUpperCase()}" isdefault='true'></variable-keys>`; | ||
// } | ||
// | ||
// // Directive handles replacing key variables and showing switcher ui | ||
// return `<variable-keys v=${v} data="${vName.toUpperCase()}"></variable-keys>`; | ||
// } else if (variables.default) { | ||
// for (const userVar of variables.user) { | ||
// if (userVar.name === v) { | ||
// return `<variable v=${v} data="${userVar.default}" isdefault='true'></variable>`; | ||
// } | ||
// } | ||
// | ||
// // Fallback to uppercase if there is no default | ||
// return `<variable v=${v} data="${v.toUpperCase()}" isdefault='true'></variable>`; | ||
// } else if (variables[v]) { | ||
// return `<variable v=${v} data="${variables[v]}"></variable>`; | ||
// } | ||
// return `<variable v=${v}></variable>`; | ||
// }); | ||
// | ||
|
||
// const replacer = varReplacer(variables, defaults, glossaryTerms); | ||
|
||
// out = out.replace(/<<([-\w:]*?)>>/g, replacer); | ||
// out = out.replace(/<<([-\w:]*?)>>/g, replacer); | ||
|
||
// // Makes \<<variable\>> display as <<variable>> in the frontend | ||
// out = out.replace(/\\<<([-\w:]*?)\\>>/g, (match, v) => `<<${v}>>`); | ||
// | ||
|
||
// return out; | ||
// }; | ||
// } |