pict 1.0.191 → 1.0.192

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": "pict",
3
- "version": "1.0.191",
3
+ "version": "1.0.192",
4
4
  "description": "Pict browser library.",
5
5
  "main": "source/Pict.js",
6
6
  "scripts": {
package/source/Pict.js CHANGED
@@ -326,6 +326,7 @@ class Pict extends libFable
326
326
  this.addTemplate(require(`./templates/logic/Pict-Template-NotEmpty.js`));
327
327
 
328
328
  // Data Manipulation Templates
329
+ this.addTemplate(require(`./templates/data/Pict-Template-DataJson.js`));
329
330
  this.addTemplate(require(`./templates/data/Pict-Template-PascalCaseIdentifier.js`));
330
331
  this.addTemplate(require(`./templates/data/Pict-Template-DateFormat.js`));
331
332
  this.addTemplate(require(`./templates/data/Pict-Template-DateYMD.js`));
@@ -58,7 +58,7 @@ class PictTemplateProviderTemplateValueSet extends libPictTemplate
58
58
  {
59
59
  for (let i = 0; i < tmpData.length; i++)
60
60
  {
61
- tmpDataValueSet.push({ Value: tmpData[i] });
61
+ tmpDataValueSet.push({ Value: tmpData[i], Key: i });
62
62
  }
63
63
  }
64
64
  else if (typeof (tmpData) === 'object')
@@ -66,7 +66,7 @@ class PictTemplateProviderTemplateValueSet extends libPictTemplate
66
66
  let tmpValueKeys = Object.keys(tmpData);
67
67
  for (let i = 0; i < tmpValueKeys.length; i++)
68
68
  {
69
- tmpDataValueSet.push({ Value: tmpData[tmpValueKeys[i]] });
69
+ tmpDataValueSet.push({ Value: tmpData[tmpValueKeys[i]], Key: tmpValueKeys[i] });
70
70
  }
71
71
  }
72
72
  else
@@ -0,0 +1,43 @@
1
+ const libPictTemplate = require('../../Pict-Template.js');
2
+
3
+ class PictTemplateProviderDollars extends libPictTemplate
4
+ {
5
+ /**
6
+ * @param {Object} pFable - The Fable Framework instance
7
+ * @param {Object} pOptions - The options for the service
8
+ * @param {String} pServiceHash - The hash of the service
9
+ */
10
+ constructor(pFable, pOptions, pServiceHash)
11
+ {
12
+ super(pFable, pOptions, pServiceHash);
13
+
14
+ this.addPattern('{~DataJson:', '~}');
15
+ this.addPattern('{~DJ:', '~}');
16
+ }
17
+
18
+ render(pTemplateHash, pRecord, pContextArray)
19
+ {
20
+ let tmpHash = pTemplateHash.trim();
21
+ let tmpData = (typeof (pRecord) === 'object') ? pRecord : {};
22
+
23
+ if (this.pict.LogNoisiness > 4)
24
+ {
25
+ this.log.trace(`PICT Template [fDataJson]::[${tmpHash}] with tmpData:`, tmpData);
26
+ }
27
+ else if (this.pict.LogNoisiness > 3)
28
+ {
29
+ this.log.trace(`PICT Template [fDataJson]::[${tmpHash}]`);
30
+ }
31
+
32
+ let tmpDataToStringify = this.resolveStateFromAddress(tmpHash, tmpData, pContextArray);
33
+
34
+ if (!tmpDataToStringify)
35
+ {
36
+ tmpDataToStringify = pRecord;
37
+ }
38
+
39
+ return JSON.stringify(tmpDataToStringify);
40
+ }
41
+ }
42
+
43
+ module.exports = PictTemplateProviderDollars;
@@ -158,10 +158,47 @@ suite
158
158
  Expect(tmpTemplateOutput).to.equal("<div><dog>This was a test... Value? ia600202.us.archive.org 8675309</dog></div>");
159
159
 
160
160
  return fDone();
161
+ }
162
+ );
163
+ test
164
+ (
165
+ 'Template Value Sets with indices',
166
+ function (fDone)
167
+ {
168
+ var testPict = new libPict(_MockSettings);
161
169
 
170
+ testPict.AppData.ChocoData = _SampleChocoData;
171
+
172
+ testPict.TemplateProvider.addTemplate('Container', '{"K":"{~D:Record.Key~}","V":"{~T:ValueTemplate:Record.Value~}"},');
173
+ testPict.TemplateProvider.addTemplate('ValueTemplate', '{~D:Record.format~}-->{~D:Record.size~}');
174
+ let tmpTemplateDataWithKeys = testPict.parseTemplate(`{~TemplateValueSet:Container:AppData.ChocoData.files~}`);
175
+
176
+ Expect(tmpTemplateDataWithKeys).to.equal(`{"K":"0","V":"Thumbnail-->838"},{"K":"1","V":"Thumbnail-->6843"},{"K":"2","V":"Thumbnail-->8388"},{"K":"3","V":"Thumbnail-->5993"},{"K":"4","V":"Thumbnail-->4951"},{"K":"5","V":"Thumbnail-->3383"},{"K":"6","V":"Thumbnail-->3503"},{"K":"7","V":"Archive BitTorrent-->4093"},{"K":"8","V":"Metadata-->"},{"K":"9","V":"Metadata-->1371"},{"K":"10","V":"Metadata-->620"},{"K":"11","V":"Item Tile-->7481"},{"K":"12","V":"Animated GIF-->101114"},{"K":"13","V":"MPEG2-->31625216"},{"K":"14","V":"Video Index-->31141"},{"K":"15","V":"Ogg Video-->2248166"},{"K":"16","V":"512Kb MPEG4-->2378677"},`);
177
+
178
+ return fDone();
179
+ }
180
+ );
181
+ test
182
+ (
183
+ 'Template JSON Record',
184
+ function (fDone)
185
+ {
186
+ var testPict = new libPict(_MockSettings);
187
+
188
+ testPict.AppData.ChocoData = _SampleChocoData;
189
+
190
+ let tmpTemplateDataWithKeys = testPict.parseTemplate(`{~DataJson:AppData.ChocoData.files[1]~}`);
191
+ let tmpTemplateDataWithKeysShorthand = testPict.parseTemplate(`{~DJ:AppData.ChocoData.files[1]~}`);
192
+
193
+ Expect(tmpTemplateDataWithKeys).to.equal(`{"name":"FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000004.jpg","source":"derivative","format":"Thumbnail","original":"frankerberry_countchockula_1971.0001.mpg","mtime":"1296336957","size":"6843","md5":"c93fa52000ab4665e69b25c403e11aff","crc32":"9444e6f6","sha1":"716b4f9950b8147f51d3265f9c62ff86451308d5"}`);
194
+ Expect(tmpTemplateDataWithKeys).to.equal(tmpTemplateDataWithKeysShorthand);
195
+
196
+ return fDone();
162
197
  }
163
198
  );
164
199
  }
165
200
  );
166
201
  }
167
202
  );
203
+
204
+