fable 3.0.21 → 3.0.23

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.0.21",
3
+ "version": "3.0.23",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -66,6 +66,7 @@
66
66
  "data-arithmatic": "^1.0.3",
67
67
  "fable-log": "^3.0.6",
68
68
  "fable-settings": "^3.0.3",
69
- "fable-uuid": "^3.0.2"
69
+ "fable-uuid": "^3.0.2",
70
+ "precedent": "^1.0.10"
70
71
  }
71
72
  }
@@ -0,0 +1,41 @@
1
+ const libFableServiceBase = require('./Fable-ServiceProviderBase.js');
2
+
3
+ const libPrecedent = require('precedent');
4
+
5
+ class FableServiceMetaTemplate extends libFableServiceBase
6
+ {
7
+ constructor(pFable, pOptions, pServiceHash)
8
+ {
9
+ super(pFable, pOptions, pServiceHash);
10
+
11
+ this.serviceType = 'MetaTemplate';
12
+
13
+ this._MetaTemplateLibrary = new libPrecedent(this.options);
14
+ }
15
+
16
+ /**
17
+ * Add a Pattern to the Parse Tree
18
+ * @method addPattern
19
+ * @param {Object} pTree - A node on the parse tree to push the characters into
20
+ * @param {string} pPattern - The string to add to the tree
21
+ * @param {number} pIndex - callback function
22
+ * @return {bool} True if adding the pattern was successful
23
+ */
24
+ addPattern(pPatternStart, pPatternEnd, pParser)
25
+ {
26
+ return this._MetaTemplateLibrary.addPattern(pPatternStart, pPatternEnd, pParser);
27
+ }
28
+
29
+ /**
30
+ * Parse a string with the existing parse tree
31
+ * @method parseString
32
+ * @param {string} pString - The string to parse
33
+ * @return {string} The result from the parser
34
+ */
35
+ parseString(pString)
36
+ {
37
+ return this._MetaTemplateLibrary.parseString(pString, this.ParseTree);
38
+ }
39
+ }
40
+
41
+ module.exports = FableServiceMetaTemplate;
package/source/Fable.js CHANGED
@@ -11,6 +11,7 @@ const libFableServiceManager = require('./Fable-ServiceManager.js');
11
11
 
12
12
  const libFableServiceDataArithmatic = require('./Fable-Service-DataArithmatic.js');
13
13
  const libFableServiceTemplate = require('./Fable-Service-Template.js');
14
+ const libFableServiceMetaTemplate = require('./Fable-Service-MetaTemplate.js');
14
15
  const libFableServiceUtility = require('./Fable-Service-Utility.js');
15
16
 
16
17
  const libFableOperation = require('./Fable-Operation.js');
@@ -49,6 +50,9 @@ class Fable
49
50
  // Initialize the template service
50
51
  this.serviceManager.addServiceType('Template', libFableServiceTemplate);
51
52
 
53
+ // Initialize the metatemplate service
54
+ this.serviceManager.addServiceType('MetaTemplate', libFableServiceMetaTemplate);
55
+
52
56
  // Initialize and instantiate the default baked-in Utility service
53
57
  this.serviceManager.addServiceType('Utility', libFableServiceUtility)
54
58
  this.fable.serviceManager.instantiateServiceProvider('Utility', {}, 'Default-Service-Utility');
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Unit tests for Fable
3
+ *
4
+ * @license MIT
5
+ *
6
+ * @author Steven Velozo <steven@velozo.com>
7
+ */
8
+
9
+ var libFable = require('../source/Fable.js');
10
+
11
+ var Chai = require("chai");
12
+ var Expect = Chai.expect;
13
+
14
+
15
+ var loadPrecedentModule = () =>
16
+ {
17
+ let tmpFable = new libFable();
18
+ return tmpFable.serviceManager.instantiateServiceProviderWithoutRegistration('MetaTemplate', {});
19
+ };
20
+
21
+ var configPrecedent = (pModule) =>
22
+ {
23
+ pModule.addPattern('<%', '%>', 'JUNKED_THIS_DATA');
24
+ // This one gets the count of the inner string...
25
+ pModule.addPattern('<%#', '%>', (pData)=>{return pData.length});
26
+ // Replaces the string with the settings object...
27
+ pModule.addPattern('<%=', '%>', (pData)=>{return JSON.stringify(pModule.settings);});
28
+ // This just escapes out pairs of $
29
+ pModule.addPattern('$');
30
+ };
31
+
32
+ suite
33
+ (
34
+ 'Fable MetaTemplating',
35
+ function()
36
+ {
37
+ var testFable = false;
38
+
39
+ setup
40
+ (
41
+ function()
42
+ {
43
+ }
44
+ );
45
+
46
+ suite
47
+ (
48
+ 'MetaTemplating',
49
+ function()
50
+ {
51
+ test
52
+ (
53
+ 'No Matches...',
54
+ (fDone) =>
55
+ {
56
+ var tmpTestString = 'ABC123';
57
+ var tmpExpectedResult = tmpTestString;
58
+ var testPrecedent = loadPrecedentModule();
59
+ configPrecedent(testPrecedent);
60
+ var tmpResult = testPrecedent.parseString(tmpTestString);
61
+ Expect(tmpResult).to.equal(tmpExpectedResult);
62
+ fDone();
63
+ }
64
+ );
65
+ test
66
+ (
67
+ 'Count function...',
68
+ (fDone) =>
69
+ {
70
+ var tmpTestString = 'There are <%#0123456789%> characters in here';
71
+ var tmpExpectedResult = 'There are 10 characters in here';
72
+ var testPrecedent = loadPrecedentModule();
73
+ configPrecedent(testPrecedent);
74
+ var tmpResult = testPrecedent.parseString(tmpTestString);
75
+ Expect(tmpResult).to.equal(tmpExpectedResult);
76
+ fDone();
77
+ }
78
+ );
79
+ test
80
+ (
81
+ 'Multiple terms...',
82
+ (fDone) =>
83
+ {
84
+ var tmpTestString = 'There are <%#12345%> characters in here and a $comment$ as well. And we <% Some data in here %> right up.';
85
+ var tmpExpectedResult = 'There are 5 characters in here and a comment as well. And we JUNKED_THIS_DATA right up.';
86
+ var testPrecedent = loadPrecedentModule();
87
+ configPrecedent(testPrecedent);
88
+ var tmpResult = testPrecedent.parseString(tmpTestString);
89
+ Expect(tmpResult).to.equal(tmpExpectedResult);
90
+ fDone();
91
+ }
92
+ );
93
+ }
94
+ );
95
+ }
96
+ );
@@ -10,7 +10,6 @@ var libFable = require('../source/Fable.js');
10
10
 
11
11
  var Chai = require("chai");
12
12
  var Expect = Chai.expect;
13
- var Assert = Chai.assert;
14
13
 
15
14
  suite
16
15
  (
@@ -10,7 +10,6 @@ var libFable = require('../source/Fable.js');
10
10
 
11
11
  var Chai = require("chai");
12
12
  var Expect = Chai.expect;
13
- var Assert = Chai.assert;
14
13
 
15
14
  suite
16
15
  (