fix case when no tripple curly vars are present

This commit is contained in:
Philipp Kunz 2017-05-02 00:19:52 +02:00
parent cacb7eff6c
commit 32941d5949
5 changed files with 18 additions and 14 deletions

View File

@ -7,5 +7,6 @@ export declare let findVarsInHbsString: (hbsStringArg: string) => Promise<string
* checks if supplied variables satisfy an handlebars template * checks if supplied variables satisfy an handlebars template
* @param hbsStringArg * @param hbsStringArg
* @param varObjectArg * @param varObjectArg
* @return string array with missing variable names
*/ */
export declare let checkVarsSatisfaction: (hbsStringArg: string, varObjectArg: any) => Promise<string[]>; export declare let checkVarsSatisfaction: (hbsStringArg: string, varObjectArg: any) => Promise<string[]>;

View File

@ -23,9 +23,10 @@ exports.findVarsInHbsString = (hbsStringArg) => __awaiter(this, void 0, void 0,
let hbsString = hbsStringArg; // make sure we have a new string object that we may destroy let hbsString = hbsStringArg; // make sure we have a new string object that we may destroy
let varNameArray = []; let varNameArray = [];
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex); let tripleCurlyMatches = hbsString.match(tripleCurlyRegex);
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]'); if (tripleCurlyMatches.length > 0) {
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]');
}
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex); let doubleCurlyMatches = hbsString.match(doubleCurlyRegex);
hbsString = hbsString.replace(doubleCurlyRegex, '[[[replaced]]]');
varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches, doubleCurlyMatches) varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches, doubleCurlyMatches)
.map((x) => { .map((x) => {
return x.match(nameInCurlsRegex)[0]; return x.match(nameInCurlsRegex)[0];
@ -37,6 +38,7 @@ exports.findVarsInHbsString = (hbsStringArg) => __awaiter(this, void 0, void 0,
* checks if supplied variables satisfy an handlebars template * checks if supplied variables satisfy an handlebars template
* @param hbsStringArg * @param hbsStringArg
* @param varObjectArg * @param varObjectArg
* @return string array with missing variable names
*/ */
exports.checkVarsSatisfaction = (hbsStringArg, varObjectArg) => __awaiter(this, void 0, void 0, function* () { exports.checkVarsSatisfaction = (hbsStringArg, varObjectArg) => __awaiter(this, void 0, void 0, function* () {
// required vars as combined deep string with . notation // required vars as combined deep string with . notation
@ -65,4 +67,4 @@ exports.checkVarsSatisfaction = (hbsStringArg, varObjectArg) => __awaiter(this,
} }
return missingVarsObject; return missingVarsObject;
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudmFyaWFibGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRoYnMudmFyaWFibGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwRkFBMEY7QUFDMUYsOENBQThDOzs7Ozs7Ozs7O0FBRTlDLDhDQUE2QztBQUU3QywwQkFBMEI7QUFDMUIsSUFBSSxnQkFBZ0IsR0FBRyxzQkFBc0IsQ0FBQTtBQUM3QyxJQUFJLGdCQUFnQixHQUFHLG9CQUFvQixDQUFBO0FBQzNDLElBQUksZ0JBQWdCLEdBQUcsU0FBUyxDQUFBO0FBRWhDOzs7R0FHRztBQUNRLFFBQUEsbUJBQW1CLEdBQUcsQ0FBTyxZQUFvQjtJQUMxRCxJQUFJLFNBQVMsR0FBRyxZQUFZLENBQUEsQ0FBQyw0REFBNEQ7SUFDekYsSUFBSSxZQUFZLEdBQWEsRUFBRSxDQUFBO0lBQy9CLElBQUksa0JBQWtCLEdBQUcsU0FBUyxDQUFDLEtBQUssQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO0lBQzFELFNBQVMsR0FBRyxTQUFTLENBQUMsT0FBTyxDQUFDLGdCQUFnQixFQUFFLGdCQUFnQixDQUFDLENBQUE7SUFDakUsSUFBSSxrQkFBa0IsR0FBRyxTQUFTLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUE7SUFDMUQsU0FBUyxHQUFHLFNBQVMs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ixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtnQkFDakMsQ0FBQyxHQUFHLFlBQVksQ0FBQyxNQUFNLENBQUE7WUFDekIsQ0FBQztRQUNILENBQUM7SUFDSCxDQUFDO0lBQ0QsTUFBTSxDQUFDLGlCQUFpQixDQUFBO0FBQzFCLENBQUMsQ0FBQSxDQUFBIn0=

View File

@ -25,7 +25,7 @@
"@types/lodash": "^4.14.63", "@types/lodash": "^4.14.63",
"handlebars": "^4.0.7", "handlebars": "^4.0.7",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"smartfile": "^4.2.4", "smartfile": "^4.2.9",
"smartq": "^1.1.1", "smartq": "^1.1.1",
"typings-global": "^1.0.16" "typings-global": "^1.0.16"
}, },

View File

@ -16,9 +16,10 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
let hbsString = hbsStringArg // make sure we have a new string object that we may destroy let hbsString = hbsStringArg // make sure we have a new string object that we may destroy
let varNameArray: string[] = [] let varNameArray: string[] = []
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex) let tripleCurlyMatches = hbsString.match(tripleCurlyRegex)
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]') if (tripleCurlyMatches.length > 0) {
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]')
}
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex) let doubleCurlyMatches = hbsString.match(doubleCurlyRegex)
hbsString = hbsString.replace(doubleCurlyRegex, '[[[replaced]]]')
varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches, doubleCurlyMatches) varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches, doubleCurlyMatches)
.map((x) => { .map((x) => {
return x.match(nameInCurlsRegex)[ 0 ] return x.match(nameInCurlsRegex)[ 0 ]
@ -46,12 +47,12 @@ export let checkVarsSatisfaction = async (hbsStringArg: string, varObjectArg: an
let splittedVars = stringVar.split('.') let splittedVars = stringVar.split('.')
let requiredPointer = suppliedVarsObject let requiredPointer = suppliedVarsObject
for (let i = 0; i < splittedVars.length; i++) { for (let i = 0; i < splittedVars.length; i++) {
let splitVar = splittedVars[i] let splitVar = splittedVars[ i ]
let varAvailable = (requiredPointer[splitVar] !== undefined) let varAvailable = (requiredPointer[ splitVar ] !== undefined)
if (varAvailable && splittedVars.length === (i + 1)) { if (varAvailable && splittedVars.length === (i + 1)) {
// ok // ok
} else if (varAvailable) { } else if (varAvailable) {
requiredPointer = requiredPointer[splitVar] requiredPointer = requiredPointer[ splitVar ]
} else { } else {
missingVarsObject.push(stringVar) missingVarsObject.push(stringVar)
i = splittedVars.length i = splittedVars.length

View File

@ -34,8 +34,8 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.63.tgz#5ac475f55bfdc62bc88c4239dbc482f2f3bead93" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.63.tgz#5ac475f55bfdc62bc88c4239dbc482f2f3bead93"
"@types/node@*": "@types/node@*":
version "7.0.14" version "7.0.15"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.14.tgz#1470fa002a113316ac9d9ad163fc738c7a0de2a4" resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.15.tgz#628429289604c5f7e56c13f3a0422f3e59df1a17"
"@types/promises-a-plus@*": "@types/promises-a-plus@*":
version "0.0.27" version "0.0.27"
@ -455,9 +455,9 @@ smartdelay@^1.0.1:
dependencies: dependencies:
typings-global "^1.0.14" typings-global "^1.0.14"
smartfile@^4.2.4: smartfile@^4.2.9:
version "4.2.4" version "4.2.9"
resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.2.4.tgz#5b53324f3d7f0b3fb2dffb134b32808da89b4dee" resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.2.9.tgz#afcd1160049cbe26a86e42e842c86e8b748e69e7"
dependencies: dependencies:
"@types/fs-extra" "2.x.x" "@types/fs-extra" "2.x.x"
"@types/vinyl" "^2.0.0" "@types/vinyl" "^2.0.0"