fable 3.1.13 → 3.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.13",
3
+ "version": "3.1.14",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -83,9 +83,12 @@ class StringParser
83
83
  * @method parseCharacter
84
84
  * @param {string} pCharacter - The character to append
85
85
  * @param {Object} pParserState - The state object for the current parsing task
86
+ * @param {any} pData - The data available to the template
87
+ * @param {any} pDataContext - The history of data objects/context already passed in
88
+ * @param {any} [pScope] - A sticky scope that can be used to carry state and simplify template
86
89
  * @private
87
90
  */
88
- parseCharacter (pCharacter, pParserState, pData, pDataContext)
91
+ parseCharacter (pCharacter, pParserState, pData, pDataContext, pScope)
89
92
  {
90
93
  // If we are already in a pattern match traversal
91
94
  if (pParserState.PatternMatch)
@@ -109,11 +112,11 @@ class StringParser
109
112
  let tmpFunctionContext = ('ParserContext' in pParserState.Pattern) ? pParserState.Pattern.ParserContext : false;
110
113
  if (tmpFunctionContext)
111
114
  {
112
- pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
115
+ pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
113
116
  }
114
117
  else
115
118
  {
116
- pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
119
+ pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
117
120
  }
118
121
  return this.resetOutputBuffer(pParserState);
119
122
  }
@@ -152,11 +155,11 @@ class StringParser
152
155
  let tmpFunctionContext = ('ParserContext' in pParserState.Pattern) ? pParserState.Pattern.ParserContext : false;
153
156
  if (tmpFunctionContext)
154
157
  {
155
- pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
158
+ pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
156
159
  }
157
160
  else
158
161
  {
159
- pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
162
+ pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
160
163
  }
161
164
  return this.resetOutputBuffer(pParserState);
162
165
  }
@@ -189,7 +192,7 @@ class StringParser
189
192
  return false;
190
193
  }
191
194
 
192
- executePatternAsync(pParserState, pData, fCallback, pDataContext)
195
+ executePatternAsync(pParserState, pData, fCallback, pDataContext, pScope)
193
196
  {
194
197
  // ... this is the end of a pattern, cut off the end tag and parse it.
195
198
  // Trim the start and end tags off the output buffer now
@@ -210,7 +213,7 @@ class StringParser
210
213
  pParserState.OutputBuffer = pAsyncOutput;
211
214
  this.resetOutputBuffer(pParserState);
212
215
  return fCallback();
213
- }, pDataContext);
216
+ }, pDataContext, pScope);
214
217
  }
215
218
  else
216
219
  {
@@ -225,7 +228,7 @@ class StringParser
225
228
  pParserState.OutputBuffer = pAsyncOutput;
226
229
  this.resetOutputBuffer(pParserState);
227
230
  return fCallback();
228
- }, pDataContext);
231
+ }, pDataContext, pScope);
229
232
  }
230
233
  }
231
234
  else
@@ -234,11 +237,11 @@ class StringParser
234
237
  let tmpFunctionContext = ('ParserContext' in pParserState.Pattern) ? pParserState.Pattern.ParserContext : false;
235
238
  if (tmpFunctionContext)
236
239
  {
237
- pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
240
+ pParserState.OutputBuffer = pParserState.Pattern.Parse.call(tmpFunctionContext, pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
238
241
  }
239
242
  else
240
243
  {
241
- pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext);
244
+ pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, pDataContext, pScope);
242
245
  }
243
246
  this.resetOutputBuffer(pParserState);
244
247
  return fCallback();
@@ -254,9 +257,10 @@ class StringParser
254
257
  * @param {Object} pData - The data to pass to the function as a second parameter
255
258
  * @param {function} fCallback - The callback function to call when the parse is complete
256
259
  * @param {array} pDataContext - The history of data objects/context already passed in
260
+ * @param {any} [pScope] - A sticky scope that can be used to carry state and simplify template
257
261
  * @private
258
262
  */
259
- parseCharacterAsync (pCharacter, pParserState, pData, fCallback, pDataContext)
263
+ parseCharacterAsync (pCharacter, pParserState, pData, fCallback, pDataContext, pScope)
260
264
  {
261
265
  // If we are already in a pattern match traversal
262
266
  if (pParserState.PatternMatch)
@@ -278,7 +282,7 @@ class StringParser
278
282
  // If this last character is the end of the pattern, parse it.
279
283
  if ('Parse' in pParserState.Pattern)
280
284
  {
281
- return this.executePatternAsync(pParserState, pData, fCallback, pDataContext);
285
+ return this.executePatternAsync(pParserState, pData, fCallback, pDataContext, pScope);
282
286
  }
283
287
  }
284
288
  else if (pCharacter in pParserState.PatternStartNode.PatternEnd)
@@ -312,7 +316,7 @@ class StringParser
312
316
  // If this last character is the end of the pattern, parse it.
313
317
  if ('Parse' in pParserState.Pattern)
314
318
  {
315
- return this.executePatternAsync(pParserState, pData, fCallback, pDataContext);
319
+ return this.executePatternAsync(pParserState, pData, fCallback, pDataContext, pScope);
316
320
  }
317
321
  }
318
322
  }
@@ -352,8 +356,9 @@ class StringParser
352
356
  * @param {Object} pData - The data to pass to the function as a second parameter
353
357
  * @param {function} fCallback - The callback function to call when the parse is complete
354
358
  * @param {array} pDataContext - The history of data objects/context already passed in
359
+ * @param {any} [pScope] - A sticky scope that can be used to carry state and simplify template
355
360
  */
356
- parseString (pString, pParseTree, pData, fCallback, pDataContext)
361
+ parseString (pString, pParseTree, pData, fCallback, pDataContext, pScope)
357
362
  {
358
363
  // TODO: There is danger here if a template function attempts to functionally recurse and doesn't pass this in.
359
364
  let tmpPreviousDataContext = (Array.isArray(pDataContext)) ? pDataContext : [];
@@ -367,7 +372,7 @@ class StringParser
367
372
  for (var i = 0; i < pString.length; i++)
368
373
  {
369
374
  // TODO: This is not fast.
370
- this.parseCharacter(pString[i], tmpParserState, pData, tmpDataContext);
375
+ this.parseCharacter(pString[i], tmpParserState, pData, tmpDataContext, pScope);
371
376
  }
372
377
 
373
378
  this.flushOutputBuffer(tmpParserState);
@@ -387,7 +392,7 @@ class StringParser
387
392
  tmpAnticipate.anticipate(
388
393
  (fCallback) =>
389
394
  {
390
- this.parseCharacterAsync(pString[i], tmpParserState, pData, fCallback, tmpDataContext);
395
+ this.parseCharacterAsync(pString[i], tmpParserState, pData, fCallback, tmpDataContext, pScope);
391
396
  });
392
397
  }
393
398
 
@@ -42,16 +42,17 @@ class FableServiceMetaTemplate extends libFableServiceBase
42
42
  * @param {object} pData - Data to pass in as the second argument
43
43
  * @param {function} fCallback - The callback function to call when a pattern is matched
44
44
  * @param {array} pDataContext - The history of data objects already passed in
45
+ * @param {any} [pScope] - A sticky scope that can be used to carry state and simplify template
45
46
  * @return {string} The result from the parser
46
47
  */
47
- parseString(pString, pData, fCallback, pDataContext)
48
+ parseString(pString, pData, fCallback, pDataContext, pScope)
48
49
  {
49
50
  if (this.LogNoisiness > 4)
50
51
  {
51
52
  this.fable.log.trace(`Metatemplate parsing template string [${pString}] where the callback is a ${typeof(fCallback)}`, {TemplateData:pData});
52
53
  }
53
- return this.StringParser.parseString(pString, this.ParseTree, pData, fCallback, pDataContext);
54
+ return this.StringParser.parseString(pString, this.ParseTree, pData, fCallback, pDataContext, pScope);
54
55
  }
55
56
  }
56
57
 
57
- module.exports = FableServiceMetaTemplate;
58
+ module.exports = FableServiceMetaTemplate;
@@ -53,13 +53,13 @@ const configMetaTemplate = (pModule) =>
53
53
 
54
54
  // Exercise the history a bit
55
55
  pModule.addPatternBoth('{~', '~}',
56
- (pHash, pData, pContext) =>
56
+ (pHash, pData, pContext, pScope) =>
57
57
  {
58
- return `Non-AsyncJF with a hash of [${pHash}] with a Context size of [${pContext.length}] and a Context[0] of [${JSON.stringify(pContext[0])}]`
58
+ return `Non-AsyncJF with a hash of [${pHash}] with a Context size of [${pContext.length}] and a Context[0] of [${JSON.stringify(pContext[0])}] with scope of [${JSON.stringify(pScope)}]`;
59
59
  },
60
- (pHash, pData, fCallback, pContext)=>
60
+ (pHash, pData, fCallback, pContext, pScope)=>
61
61
  {
62
- return fCallback(null, `AsyncJF with a hash of [${pHash}] with a Context size of [${pContext.length}] and a Context[0] of [${JSON.stringify(pContext[0])}]`);
62
+ return fCallback(null, `AsyncJF with a hash of [${pHash}] with a Context size of [${pContext.length}] and a Context[0] of [${JSON.stringify(pContext[0])}] with scope of [${JSON.stringify(pScope)}]`);
63
63
  });
64
64
 
65
65
  };
@@ -369,19 +369,19 @@ suite
369
369
  (fDone) =>
370
370
  {
371
371
  let tmpTestString = 'A {~SomeValue~} B';
372
- let tmpExpectedResultAsync = 'A AsyncJF with a hash of [SomeValue] with a Context size of [1] and a Context[0] of [{\"SomeValue\":\"AirbornLight\"}] B';
373
- let tmpExpectedResult = 'A Non-AsyncJF with a hash of [SomeValue] with a Context size of [1] and a Context[0] of [{\"SomeValue\":\"AirbornLight\"}] B';
372
+ let tmpExpectedResultAsync = 'A AsyncJF with a hash of [SomeValue] with a Context size of [1] and a Context[0] of [{\"SomeValue\":\"AirbornLight\"}] with scope of [{"ScopeValue":1}] B';
373
+ let tmpExpectedResult = 'A Non-AsyncJF with a hash of [SomeValue] with a Context size of [1] and a Context[0] of [{\"SomeValue\":\"AirbornLight\"}] with scope of [{"ScopeValue":1}] B';
374
374
 
375
375
  let tmpCustomHistory = [{YouTheMan:'NowDog'}];
376
- let tmpExpectedResultCustomHistory = 'A Non-AsyncJF with a hash of [SomeValue] with a Context size of [2] and a Context[0] of [{\"YouTheMan\":\"NowDog\"}] B';
376
+ let tmpExpectedResultCustomHistory = 'A Non-AsyncJF with a hash of [SomeValue] with a Context size of [2] and a Context[0] of [{\"YouTheMan\":\"NowDog\"}] with scope of [{"ScopeValue":1}] B';
377
377
 
378
378
  let testMetaTemplate = loadMetaTemplateModule();
379
379
  configMetaTemplate(testMetaTemplate);
380
380
 
381
- let tmpNonAsyncResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'});
381
+ let tmpNonAsyncResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'}, null, null, { ScopeValue: 1 });
382
382
  Expect(tmpNonAsyncResult).to.equal(tmpExpectedResult);
383
383
 
384
- let tmpNonAsyncCustomResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'}, null, tmpCustomHistory);
384
+ let tmpNonAsyncCustomResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'}, null, tmpCustomHistory, { ScopeValue: 1 });
385
385
  Expect(tmpNonAsyncCustomResult).to.equal(tmpExpectedResultCustomHistory);
386
386
 
387
387
  let tmpResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'},
@@ -389,7 +389,7 @@ suite
389
389
  {
390
390
  Expect(pValue).to.equal(tmpExpectedResultAsync);
391
391
  return fDone();
392
- });
392
+ }, null, { ScopeValue: 1 });
393
393
  }
394
394
  );
395
395
  }