btrz-liquid-templates 1.0.0 → 1.2.0
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/docs/_config.yml +1 -0
- package/docs/index.md +755 -0
- package/package.json +7 -8
- package/src/escp.js +12 -13
package/docs/_config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
theme: minima
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Purpose
|
|
3
|
+
layout: default
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Create pdf documents from liquid templates.
|
|
7
|
+
|
|
8
|
+
This library uses [LiquidJS](https://liquidjs.com/), [Symbology](https://symbology.dev/), [Bz-Date](https://www.npmjs.com/package/bz-date), [btrz-formatter](https://www.npmjs.com/package/btrz-formatter) and link them together while adding some helpers to easily generate PDFs from templates.
|
|
9
|
+
|
|
10
|
+
The vesion of PDFMake has been inlined and modified to allow for text rotation.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i btrz-pdf
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Restrictions
|
|
19
|
+
|
|
20
|
+
The documents generated only uses Helvetica fonts.
|
|
21
|
+
|
|
22
|
+
## Methods
|
|
23
|
+
|
|
24
|
+
* processToString
|
|
25
|
+
|
|
26
|
+
Async method that returns a string.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
|
|
30
|
+
| name | definition |
|
|
31
|
+
|------|------|
|
|
32
|
+
| liquidTemplate | object representing a document with valid liquidSyntax |
|
|
33
|
+
| data | Object with data needed by the liquid template |
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
* processToEscp(liquidTemplate, data)
|
|
37
|
+
|
|
38
|
+
Async method that returns a string and underastands ESCP language
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
|
|
42
|
+
| name | definition |
|
|
43
|
+
|------|------|
|
|
44
|
+
| liquidTemplate | object representing an ESCP string with valid liquidSyntax |
|
|
45
|
+
| data | Object with data needed by the liquid template |
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
* returnToObj(liquidTemplate, data)
|
|
49
|
+
|
|
50
|
+
Async method that returns an object (the template should be an strinfiable object)
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
|
|
54
|
+
| name | definition |
|
|
55
|
+
|------|------|
|
|
56
|
+
| liquidTemplate | object representing an object document with valid liquidSyntax |
|
|
57
|
+
| data | Object with data needed by the liquid template |
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const tpl = require("btrz-liquid-templates");
|
|
64
|
+
|
|
65
|
+
//Returns a string from the template and the data
|
|
66
|
+
async getLiquid(req, res) {
|
|
67
|
+
try {
|
|
68
|
+
const document = await tpl.processToString(template, data);
|
|
69
|
+
res.send(document);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
res.status(500).send(error.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
const tpl = require("btrz-liquid-templates");
|
|
78
|
+
|
|
79
|
+
//Returns an object from the template and the data
|
|
80
|
+
async getLiquid(req, res) {
|
|
81
|
+
try {
|
|
82
|
+
const document = await tpl.processToObj(template, data);
|
|
83
|
+
res.send(document);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
res.status(500).send(error.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const tpl = require("btrz-liquid-templates");
|
|
92
|
+
|
|
93
|
+
//Returns an ESCP string from the template and the data
|
|
94
|
+
async getLiquid(req, res) {
|
|
95
|
+
try {
|
|
96
|
+
const document = await tpl.processToEscp(template, data);
|
|
97
|
+
res.send(document);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
res.status(500).send(error.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Custom tags
|
|
105
|
+
|
|
106
|
+
## ESCP language for Epson printers
|
|
107
|
+
|
|
108
|
+
* ## escInitQzTray
|
|
109
|
+
|
|
110
|
+
Initialize the printer
|
|
111
|
+
Set printer to ESC/P mode and clear memory buffer.
|
|
112
|
+
|
|
113
|
+
```liquid
|
|
114
|
+
{% escInitQzTray %}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
* ## escBold
|
|
118
|
+
|
|
119
|
+
Start bold font.
|
|
120
|
+
|
|
121
|
+
```liquid
|
|
122
|
+
{% escBold %}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
* ## escCancelBold
|
|
126
|
+
|
|
127
|
+
Ends bold font.
|
|
128
|
+
|
|
129
|
+
```liquid
|
|
130
|
+
{% escCancelBold %}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
* ## fontSelection
|
|
134
|
+
|
|
135
|
+
Starts selected font
|
|
136
|
+
|
|
137
|
+
```liquid
|
|
138
|
+
{% fontSelection %}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
* ## escCondensed
|
|
142
|
+
|
|
143
|
+
Small condensed fonts
|
|
144
|
+
|
|
145
|
+
```liquid
|
|
146
|
+
{% escCondensed %}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
* ## lineSpacing
|
|
150
|
+
|
|
151
|
+
Line spacing to 1/6 of an inch
|
|
152
|
+
|
|
153
|
+
```liquid
|
|
154
|
+
{% lineSpacing %}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
* ## lineSpacing2
|
|
158
|
+
|
|
159
|
+
Line spacing to 1/9 of an inch
|
|
160
|
+
|
|
161
|
+
```liquid
|
|
162
|
+
{% lineSpacing2 %}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
* ## escNewLine
|
|
166
|
+
|
|
167
|
+
New line
|
|
168
|
+
|
|
169
|
+
```liquid
|
|
170
|
+
{% escNewLine %}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
* ## escCut
|
|
174
|
+
|
|
175
|
+
Paper cut
|
|
176
|
+
|
|
177
|
+
```liquid
|
|
178
|
+
{% escCut %}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
* ## escEject
|
|
182
|
+
|
|
183
|
+
Form feed (eject paper)
|
|
184
|
+
|
|
185
|
+
```liquid
|
|
186
|
+
{% escEject %}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
* ## escTab
|
|
190
|
+
|
|
191
|
+
Move to next horizontal tab
|
|
192
|
+
|
|
193
|
+
```liquid
|
|
194
|
+
{% escTab %}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
## Images, barcodes and QR codes
|
|
199
|
+
|
|
200
|
+
* ## barcode
|
|
201
|
+
|
|
202
|
+
Generates a barcode based on some data
|
|
203
|
+
|
|
204
|
+
Parameters
|
|
205
|
+
|
|
206
|
+
| name | definition | required | default |
|
|
207
|
+
|------|------------|----------|---------|
|
|
208
|
+
| data | The string to use to generate the barcode, it can be hardcoded or some of the 'data' given to the template | Y | |
|
|
209
|
+
| type | The barcode type | N | code128
|
|
210
|
+
| height | The barcode height | N | 30
|
|
211
|
+
| width | The barcode width | N | 200
|
|
212
|
+
| margin | A list of 4 values for the margin | N | 0,0,0,0
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
It will use the value of ticket.code to generate the barcode with all the defaults
|
|
216
|
+
|
|
217
|
+
```liquid
|
|
218
|
+
{% raw %} {% barcode ticket.code %} {% endraw %}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
It will use the value given and use generate a 'code11' barcode with a height of 50 and a width of 300
|
|
222
|
+
|
|
223
|
+
```liquid
|
|
224
|
+
{% raw %} {% barcode 1234 code11 50 300 20,20,20,0 %} {% endraw %}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Supported types
|
|
228
|
+
|
|
229
|
+
It supports all types supported by [https://symbology.dev/](Symbology).
|
|
230
|
+
While symbology supports QRCODE PDFMake also had support for QR natively and we recommend it.
|
|
231
|
+
|
|
232
|
+
* ## httpImg
|
|
233
|
+
|
|
234
|
+
Given a URL for an image will encode into base64 and return in a consumable way for makePDF, only supports png and jpeg
|
|
235
|
+
|
|
236
|
+
Parameters
|
|
237
|
+
|
|
238
|
+
| name | definition | required | default |
|
|
239
|
+
|------|------------|----------|---------|
|
|
240
|
+
| object.property | The property should have a fully qualified URL to an image | Y |
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
```liquid
|
|
244
|
+
{% raw %} {%- httpImg brand.logos.default -%} {% endraw %} // data:image/png;base64,77+9UE5HDQoaCgAAAA1JSERSAAA...
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Supported filters
|
|
248
|
+
|
|
249
|
+
* ## qrstr
|
|
250
|
+
|
|
251
|
+
Returns the proper str to transform into a QR code to be able to scan items with the drivers app
|
|
252
|
+
|
|
253
|
+
```liquid
|
|
254
|
+
{% raw %} {%- qrstr reservation -%} {% endraw %} //"https://{{ctx.environments.providerPreferences.domain}}/r/t/{{reservation.urlTicketCode}}"
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```liquid
|
|
258
|
+
{% raw %} {%- qrstr ticket -%} {% endraw %} //"https://{{ctx.environments.providerPreferences.domain}}/r/t/{{ticket.urlTicketCode}}"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
|
|
263
|
+
| name | definition | required | default |
|
|
264
|
+
|------|------------|----------|---------|
|
|
265
|
+
| type | The type of object we will be generating the string for the qrcode | N | ticket
|
|
266
|
+
|
|
267
|
+
### Valid types
|
|
268
|
+
|
|
269
|
+
reservation, ticket, paid_in, parcel, flexpass, ssr, redeemableItem
|
|
270
|
+
|
|
271
|
+
## Date and Time
|
|
272
|
+
|
|
273
|
+
* ## dateTime
|
|
274
|
+
|
|
275
|
+
Returns a date formatted by the given format from a property of an object given to the liquid template data.
|
|
276
|
+
|
|
277
|
+
```liquid
|
|
278
|
+
{% raw %} {%- dateTime ticket createdAt -%} {% endraw %} //"12/21/2021 11:38 AM"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
```liquid
|
|
282
|
+
{% raw %} {%- dateTime ticket createdAt mm/dd/yyyy hh:MM:ss -%} {% endraw %} //"12/21/2021 11:38:00"
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Parameters
|
|
286
|
+
|
|
287
|
+
| name | definition | required | default |
|
|
288
|
+
|------|------------|----------|---------|
|
|
289
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
290
|
+
| propName | The name of the property of the item (it should be a BzDate object) | N | createdAt
|
|
291
|
+
| format | A format object | N | providerPreferences defaults (see prereqs)
|
|
292
|
+
|
|
293
|
+
Prerequisites
|
|
294
|
+
|
|
295
|
+
There are some prerequisites to use any of the Date helpers. The data given to the liquid template requires the following object to be present
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"providerPreferences": {
|
|
300
|
+
"preferences": {
|
|
301
|
+
"dateFormat": "mm/dd/yyyy", //any date format string will do
|
|
302
|
+
"timeFormat": "h:MM TT", //any time format string will do
|
|
303
|
+
"timeZone": {
|
|
304
|
+
"name": "(UTC-5:00) New York (United States), Toronto (Canada)",
|
|
305
|
+
"daylight": true,
|
|
306
|
+
"tz": "America/Toronto"
|
|
307
|
+
} //any timezone as defined in BzDate will do
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
* ## dateF
|
|
315
|
+
|
|
316
|
+
Convenience method that will default format to `providerPreferenes.preferences.dateFormat`
|
|
317
|
+
|
|
318
|
+
Parameters
|
|
319
|
+
|
|
320
|
+
| name | definition | required | default |
|
|
321
|
+
|------|------------|----------|---------|
|
|
322
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
323
|
+
| propName | The name of the property of the item (it should be a BzDate object) | N | createdAt
|
|
324
|
+
| applyTimeZone | If you want to adjust the date with the account timeZone | N | true
|
|
325
|
+
|
|
326
|
+
```liquid
|
|
327
|
+
{% raw %} {%- dateF ticket createdAt -%} {% endraw %} //"12/21/2021"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
* ## timeF
|
|
331
|
+
|
|
332
|
+
Convenience method that will default format to `providerPreferenes.preferences.timeFormat`
|
|
333
|
+
|
|
334
|
+
Parameters
|
|
335
|
+
|
|
336
|
+
| name | definition | required | default |
|
|
337
|
+
|------|------------|----------|---------|
|
|
338
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
339
|
+
| propName | The name of the property of the item (it should be a BzDate object or a time string) | N | createdAt
|
|
340
|
+
| applyTimeZone | If you want to adjust the date with the account timeZone | N | true
|
|
341
|
+
|
|
342
|
+
```liquid
|
|
343
|
+
{% raw %} {%- timeF ticket createdAt -%} {% endraw %} //"11:38 AM"
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
* ## expDate
|
|
347
|
+
|
|
348
|
+
Convenience method that will calculate the expiration date for a reservation
|
|
349
|
+
|
|
350
|
+
Parameters
|
|
351
|
+
|
|
352
|
+
| name | definition | required | default |
|
|
353
|
+
|------|------------|----------|---------|
|
|
354
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
355
|
+
| format | A format object | N | providerPreferences defaults (see prereqs)
|
|
356
|
+
|
|
357
|
+
```liquid
|
|
358
|
+
{% raw %} {%- expDate reservation -%} {% endraw %} //"12/21/2021 11:38 AM"
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
* ## arrivalDate
|
|
362
|
+
|
|
363
|
+
Convenience method that will calculate the arrival date for a reservation and will apply the arrival station timeZone if available
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
|
|
367
|
+
| name | definition | required | default |
|
|
368
|
+
|------|------------|----------|---------|
|
|
369
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
```liquid
|
|
373
|
+
{% raw %} {%- arrivalDate reservation -%} {% endraw %} //"12/21/2021"
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
* ## departureDate
|
|
377
|
+
|
|
378
|
+
Convenience method that will calculate the departure date for a reservation and will apply the departure station timeZone if available
|
|
379
|
+
|
|
380
|
+
Parameters
|
|
381
|
+
|
|
382
|
+
| name | definition | required | default |
|
|
383
|
+
|------|------------|----------|---------|
|
|
384
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
385
|
+
|
|
386
|
+
```liquid
|
|
387
|
+
{% raw %} {%- departureDate reservation -%} {% endraw %} //"12/21/2021"
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
* ## arrivalTime
|
|
391
|
+
|
|
392
|
+
Convenience method that will calculate the arrival time for a reservation and will apply the arrival station timeZone if available
|
|
393
|
+
|
|
394
|
+
Parameters
|
|
395
|
+
|
|
396
|
+
| name | definition | required | default |
|
|
397
|
+
|------|------------|----------|---------|
|
|
398
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
```liquid
|
|
402
|
+
{% raw %} {%- arrivalTime reservation -%} {% endraw %} //"11:38 AM"
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
* ## departureTime
|
|
406
|
+
|
|
407
|
+
Convenience method that will calculate the departure time for a reservation and will apply the departure station timeZone if available
|
|
408
|
+
|
|
409
|
+
Parameters
|
|
410
|
+
|
|
411
|
+
| name | definition | required | default |
|
|
412
|
+
|------|------------|----------|---------|
|
|
413
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
414
|
+
|
|
415
|
+
```liquid
|
|
416
|
+
{% raw %} {%- departureTime reservation -%} {% endraw %} //"11:38 AM"
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
* ## arrivalDateTime
|
|
420
|
+
|
|
421
|
+
Convenience method that will calculate the arrival date for a reservation and will apply the arrival station timeZone if available
|
|
422
|
+
|
|
423
|
+
Parameters
|
|
424
|
+
|
|
425
|
+
| name | definition | required | default |
|
|
426
|
+
|------|------------|----------|---------|
|
|
427
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
```liquid
|
|
431
|
+
{% raw %} {%- arrivalDateTime reservation -%} {% endraw %} //"12/21/2021 11:38 AM"
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
* ## departureDateTime
|
|
435
|
+
|
|
436
|
+
Convenience method that will calculate the departure date for a reservation and will apply the departure station timeZone if available
|
|
437
|
+
|
|
438
|
+
Parameters
|
|
439
|
+
|
|
440
|
+
| name | definition | required | default |
|
|
441
|
+
|------|------------|----------|---------|
|
|
442
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
```liquid
|
|
446
|
+
{% raw %} {%- departureDateTime reservation -%} {% endraw %} //"12/21/2021 11:38 AM"
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
* ## humanArrivalDate
|
|
450
|
+
|
|
451
|
+
Convenience method that will calculate the arrival date for a reservation and will apply the arrival station timeZone if available. It will format the date using the `humanDate` property given to the template. `humanDate` can be either 'mm' or 'dd', default to 'mm'.
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
Parameters
|
|
455
|
+
|
|
456
|
+
| name | definition | required | default |
|
|
457
|
+
|------|------------|----------|---------|
|
|
458
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
```liquid
|
|
462
|
+
{% raw %} {%- humanArrivalDate reservation -%} {% endraw %} //"Tue Dec 21, 2021"
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
* ## humanDepartureDate
|
|
466
|
+
|
|
467
|
+
Convenience method that will calculate the departure date for a reservation and will apply the departure station timeZone if available. It will format the date using the `humanDate` property given to the template. `humanDate` can be either 'mm' or 'dd', default to 'mm'.
|
|
468
|
+
|
|
469
|
+
Parameters
|
|
470
|
+
|
|
471
|
+
| name | definition | required | default |
|
|
472
|
+
|------|------------|----------|---------|
|
|
473
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
```liquid
|
|
477
|
+
{% raw %} {%- humanDepartureDate reservation -%} {% endraw %} //"Tue Dec 21, 2021"
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
* ## humanArrivalDateTime
|
|
481
|
+
|
|
482
|
+
Convenience method that will calculate the arrival date for a reservation and will apply the arrival station timeZone if available. It will format the date using the `humanDate` property given to the template. `humanDate` can be either 'mm' or 'dd', default to 'mm'.
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
Parameters
|
|
486
|
+
|
|
487
|
+
| name | definition | required | default |
|
|
488
|
+
|------|------------|----------|---------|
|
|
489
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
```liquid
|
|
493
|
+
{% raw %} {%- humanArrivalDateTime reservation -%} {% endraw %} //"Tue Dec 21, 2021 11:38 AM"
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
* ## humanDepartureDateTime
|
|
497
|
+
|
|
498
|
+
Convenience method that will calculate the departure date for a reservation and will apply the departure station timeZone if available. It will format the date using the `humanDate` property given to the template. `humanDate` can be either 'mm' or 'dd', default to 'mm'.
|
|
499
|
+
|
|
500
|
+
Parameters
|
|
501
|
+
|
|
502
|
+
| name | definition | required | default |
|
|
503
|
+
|------|------------|----------|---------|
|
|
504
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
```liquid
|
|
508
|
+
{% raw %} {%- humanDepartureDateTime reservation -%} {% endraw %} //"Tue Dec 21, 2021 11:38 AM"
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
* ## humanDate
|
|
512
|
+
|
|
513
|
+
Convenience method that will default format based on the `humanDate` property given to the template as part of the data object. `humanDate` can be either 'mm' or 'dd'
|
|
514
|
+
|
|
515
|
+
```javascript
|
|
516
|
+
(humanDate === "mm") ? "ddd mmm dd, yyyy" : "ddd dd mmm, yyyy"
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Parameters
|
|
520
|
+
|
|
521
|
+
| name | definition | required | default |
|
|
522
|
+
|------|------------|----------|---------|
|
|
523
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
524
|
+
| propName | The name of the property of the item (it should be a BzDate object) | N | createdAt
|
|
525
|
+
| applyTimeZone | If you want to adjust the date with the account timeZone | N | true
|
|
526
|
+
|
|
527
|
+
```liquid
|
|
528
|
+
{% raw %} {%- humanDate ticket createdAt -%} {% endraw %} //"Tue Dec 21, 2021"
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
* ## humanDateTime
|
|
532
|
+
|
|
533
|
+
Convenience method that will default format based on the `humanDate` property given to the template as part of the data object. `humanDate` can be either 'mm' or 'dd' plus the `providerPreferenes.preferences.timeFormat`
|
|
534
|
+
|
|
535
|
+
```javascript
|
|
536
|
+
(humanDate === "mm") ? "ddd mmm dd, yyyy" : "ddd dd mmm, yyyy"
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
Parameters
|
|
540
|
+
|
|
541
|
+
| name | definition | required | default |
|
|
542
|
+
|------|------------|----------|---------|
|
|
543
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
544
|
+
| propName | The name of the property of the item (it should be a BzDate object) | N | createdAt
|
|
545
|
+
| applyTimeZone | If you want to adjust the date with the account timeZone | N | true
|
|
546
|
+
|
|
547
|
+
```liquid
|
|
548
|
+
{% raw %} {%- humanDateTime ticket createdAt -%} {% endraw %} //"Tue Dec 21, 2021 11:38 AM"
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
## Lines, HTML, Lexicons and text
|
|
552
|
+
|
|
553
|
+
* ## keys
|
|
554
|
+
|
|
555
|
+
Given an Object converts it to an array of keys.
|
|
556
|
+
|
|
557
|
+
For this object:
|
|
558
|
+
```json
|
|
559
|
+
{
|
|
560
|
+
"prop1": "value1",
|
|
561
|
+
"prop2": "value2"
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
You can iterate over the object keys
|
|
565
|
+
|
|
566
|
+
```liquid
|
|
567
|
+
{% raw %}
|
|
568
|
+
{%- assign objectKeys = brand.logos.default -%}
|
|
569
|
+
{%- for aKey in objectKeys -%}
|
|
570
|
+
Key number {%forloop.index%} : {{aKey}}
|
|
571
|
+
{%- endfor -%}
|
|
572
|
+
{% endraw %}
|
|
573
|
+
|
|
574
|
+
//"Key number 1: prop1"
|
|
575
|
+
//"Key number 2: prop2"
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
* ## h
|
|
579
|
+
|
|
580
|
+
This tag will parse "some" HTML code and try to generate compatible PDFmake text objects.
|
|
581
|
+
|
|
582
|
+
Parameters
|
|
583
|
+
|
|
584
|
+
| name | definition | required | default |
|
|
585
|
+
|------|------------|----------|---------|
|
|
586
|
+
| property | this will be "evaluated" from the data provided to the liquid template | Y |
|
|
587
|
+
|
|
588
|
+
```javascript
|
|
589
|
+
{% raw %} {% h ticket.lexiconKeys.terms %} {% endraw %} //If will get the string in the property and parse it
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
### Supported html tags
|
|
593
|
+
|
|
594
|
+
**h1** - will generate a text node with "style": "header"
|
|
595
|
+
**h2** - will generate a text node with "style": "subheader"
|
|
596
|
+
**h3** - will generate a text node with "style": "innerheader"
|
|
597
|
+
**b** - will generate a text node with "bold": true
|
|
598
|
+
**i** - will generate a text node with "italics'": true
|
|
599
|
+
|
|
600
|
+
* ## hline
|
|
601
|
+
|
|
602
|
+
This tag generates an horizontal line
|
|
603
|
+
|
|
604
|
+
Parameters
|
|
605
|
+
|
|
606
|
+
| name | definition | required | default |
|
|
607
|
+
|------|------------|----------|---------|
|
|
608
|
+
| width | the width of the line | N | 500
|
|
609
|
+
| weight | the weight of the line | N | 1
|
|
610
|
+
| rgb | the colour of the line, either a rgb or hex value or read from a data property as hex | N | 0,0,0
|
|
611
|
+
|
|
612
|
+
```liquid
|
|
613
|
+
{% raw %} {%- hline 475 2 255,112,0 - %} {% endraw %} //Generates an svg line with the width, weight and colour given
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
```liquid
|
|
617
|
+
{% raw %} {%- hline 475 2 providerPreferences.preferences.colors.brandBackground - %} {% endraw %} //Generates an svg line with the width, weight and colour given
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
```json
|
|
621
|
+
{
|
|
622
|
+
"svg": "<svg height='2' width='100'><line x1='0' y1='0' x2='1000' y2='0' style='stroke:rgb(255,112,0);stroke-width:2' /></svg>",
|
|
623
|
+
"width": 475
|
|
624
|
+
}
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
* ## t
|
|
628
|
+
|
|
629
|
+
Returns a translation based on a key, it can use a string or variables from the data given to the liquid template
|
|
630
|
+
|
|
631
|
+
Prerequisites
|
|
632
|
+
|
|
633
|
+
There are some prerequisites to use the **t** tag. The data given to the liquid template requires a `localizer` object with a `.get(key)` method that can return the translation. The implementation is up to you.
|
|
634
|
+
|
|
635
|
+
Parameters
|
|
636
|
+
|
|
637
|
+
| name | definition | required | default |
|
|
638
|
+
|------|------------|----------|---------|
|
|
639
|
+
| property | the key for the lexicon | Y |
|
|
640
|
+
|
|
641
|
+
```liquid
|
|
642
|
+
{% raw %} {% t 'issued' %} {% endraw %} //Will return the value on the lexicon with the 'issued' key
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
```liquid
|
|
646
|
+
{% raw %} {% t fare.lexiconKeys.description %} {% endraw %} //Will return the value on the lexicon with the key stored in the `data.fare.lexiconKeys.description` property
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
* ## txt
|
|
650
|
+
|
|
651
|
+
Split lines or hardcoded text that may include carriage returns
|
|
652
|
+
|
|
653
|
+
Parameters
|
|
654
|
+
|
|
655
|
+
| name | definition | required | default |
|
|
656
|
+
|------|------------|----------|---------|
|
|
657
|
+
| liquid expression | A liquid expression that will be evaluated and each line will be converted on a text node | Y
|
|
658
|
+
| style | A style defined in the document to apply to the resulted text nodes | N
|
|
659
|
+
|
|
660
|
+
```liquid
|
|
661
|
+
"{% raw %} {% txt operatingCompany.infoOnPrintedTicket small %} {% endraw %}" //Given that ticket.total is 2800000 returns "28.00"
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
## Money and currency
|
|
665
|
+
|
|
666
|
+
* ## money
|
|
667
|
+
|
|
668
|
+
Returns a money value
|
|
669
|
+
|
|
670
|
+
Parameters
|
|
671
|
+
|
|
672
|
+
| name | definition | required | default |
|
|
673
|
+
|------|------------|----------|---------|
|
|
674
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
675
|
+
| propName | The name of the property of the item | N | total
|
|
676
|
+
|
|
677
|
+
```liquid
|
|
678
|
+
"{% raw %} {%- money ticket total -%} {% endraw %}" //Given that ticket.total is 2800000 returns "28.00"
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
* ## moneyReduce
|
|
682
|
+
|
|
683
|
+
Adds the values of a property in objects in a collection and returns the total as a money value
|
|
684
|
+
|
|
685
|
+
Parameters
|
|
686
|
+
|
|
687
|
+
| name | definition | required | default |
|
|
688
|
+
|------|------------|----------|---------|
|
|
689
|
+
| item.propName | An object in the data given to the liquid template | N | ticket.taxes
|
|
690
|
+
| innerPropName | The name of the property in the objects in the collection | N | calculated
|
|
691
|
+
|
|
692
|
+
```liquid
|
|
693
|
+
"{% raw %} {%- moneyReduce ticket.fees subTotal -%} {% endraw %}"
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
* ## curcyName
|
|
697
|
+
|
|
698
|
+
Returns the currency name based on the displayCurrency of the item provided and the account configuration. If the item provided is a currency, it will just use that currency,
|
|
699
|
+
|
|
700
|
+
Parameters
|
|
701
|
+
|
|
702
|
+
| name | definition | required | default |
|
|
703
|
+
|------|------------|----------|---------|
|
|
704
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
705
|
+
|
|
706
|
+
```liquid
|
|
707
|
+
{% raw %} {%- curcyName ticket -%} {% endraw %}",
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
* ## curcySymbol
|
|
711
|
+
|
|
712
|
+
Returns the currency symbol based on the currency used to paid the item or the default currency given in the `providerPreferences.preferences.supportedCurrencies[0]`
|
|
713
|
+
|
|
714
|
+
Parameters
|
|
715
|
+
|
|
716
|
+
| name | definition | required | default |
|
|
717
|
+
|------|------------|----------|---------|
|
|
718
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
719
|
+
|
|
720
|
+
```liquid
|
|
721
|
+
{% raw %} {%- curcySymbol ticket -%} {% endraw %}",
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
* ## curcyIso
|
|
725
|
+
|
|
726
|
+
Returns the currency ISO code based on the currency used to paid the item or the default currency given in the `providerPreferences.preferences.supportedCurrencies[0]`
|
|
727
|
+
|
|
728
|
+
Parameters
|
|
729
|
+
|
|
730
|
+
| name | definition | required | default |
|
|
731
|
+
|------|------------|----------|---------|
|
|
732
|
+
| item | An object in the data given to the liquid template | N | ticket
|
|
733
|
+
|
|
734
|
+
```liquid
|
|
735
|
+
{% raw %} {%- curcyIso ticket -%} {% endraw %}
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
* ## toLetters
|
|
739
|
+
|
|
740
|
+
Returns the amount in letters given in the property (amount should follow US notation, uses "." for cents).
|
|
741
|
+
It can translate values using the `lang` and `localizer`
|
|
742
|
+
|
|
743
|
+
Parameters
|
|
744
|
+
|
|
745
|
+
| name | definition | required | default |
|
|
746
|
+
|------|------------|----------|---------|
|
|
747
|
+
| stringAmount | A string with the amount | Y |
|
|
748
|
+
|
|
749
|
+
```liquid
|
|
750
|
+
{% raw %} {%- toLetters '100.50' -%} {% endraw %} // One hundred with fifty cents
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
```liquid
|
|
754
|
+
{% raw %} {%- toLetters '123' -%} {% endraw %} // One hundred and twenty three
|
|
755
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "btrz-liquid-templates",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,18 +23,17 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"axios": "^0.27.2",
|
|
25
25
|
"btrz-formatter": "1.3.0",
|
|
26
|
-
"bz-date": "
|
|
27
|
-
"liquidjs": "^10.
|
|
28
|
-
"moment": "^2.
|
|
29
|
-
"moment-timezone": "^0.5.
|
|
26
|
+
"bz-date": "2.0.0",
|
|
27
|
+
"liquidjs": "^10.20.2",
|
|
28
|
+
"moment": "^2.30.1",
|
|
29
|
+
"moment-timezone": "^0.5.46",
|
|
30
30
|
"symbology": "^4.0.1",
|
|
31
31
|
"written-number": "^0.11.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"browserify": "^17.0.
|
|
34
|
+
"browserify": "^17.0.1",
|
|
35
35
|
"chai": "4.3.10",
|
|
36
|
-
"mocha": "
|
|
36
|
+
"mocha": "11.1.0",
|
|
37
37
|
"tinyify": "4.0.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
package/src/escp.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
// const escInitQzTray = "\x1B\x69\x61\x00\x1B\x40"; // set printer to ESC/P mode and clear memory buffer ; Inicializa la impresora
|
|
3
|
-
// const lineSpacing = "\x1B\x33\x18"; // Espaciado de línea (1/6 de pulgada)
|
|
4
|
-
// const lineSpacing2 = "\x1B\x33\x24"; // ESC 3 n (1/9 de pulgada)
|
|
5
|
-
// const fontSelection = "\x1B\x4D"; // Fuente pequeña (Condensed)
|
|
6
|
-
// const escBold = "\x1B\x45"; // Activa negrita
|
|
7
|
-
// const escCancelBold = "\x1B\x46"; // Cancela negrita
|
|
8
|
-
// const escNewLine = "\n"; // Nueva línea
|
|
9
|
-
// const escCut = "\x1D\x56\x00"; // Corte de papel
|
|
10
|
-
// const escEject = "\x0C"; // Form Feed (FF) - Expulsa la hoja
|
|
11
|
-
// const escCondensed = "\x1B\x0F"; // Modo comprimido (17 cpi)
|
|
12
|
-
|
|
13
1
|
function escInitQzTray(engine) {
|
|
14
2
|
this.registerTag("escInitQzTray", {
|
|
15
3
|
parse: function(tagToken, remainTokens) {
|
|
@@ -119,6 +107,16 @@ function escCondensed(engine) {
|
|
|
119
107
|
});
|
|
120
108
|
}
|
|
121
109
|
|
|
110
|
+
function escTab(engine) {
|
|
111
|
+
this.registerTag("escTab", {
|
|
112
|
+
parse: function(tagToken, remainTokens) {
|
|
113
|
+
|
|
114
|
+
},
|
|
115
|
+
render: async function(ctx) {
|
|
116
|
+
return "\\x09";
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
122
120
|
module.exports = {
|
|
123
121
|
escInitQzTray,
|
|
124
122
|
lineSpacing,
|
|
@@ -129,5 +127,6 @@ module.exports = {
|
|
|
129
127
|
escNewLine,
|
|
130
128
|
escCut,
|
|
131
129
|
escEject,
|
|
132
|
-
escCondensed
|
|
130
|
+
escCondensed,
|
|
131
|
+
escTab
|
|
133
132
|
}
|