btrz-liquid-templates 1.2.0 → 1.4.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/README.md CHANGED
@@ -1,2 +1,3 @@
1
1
  # btrz-liquid-templates
2
- Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate
2
+
3
+ [Check the documentation](https://betterez.github.io/btrz-liquid-templates/)
package/docs/index.md CHANGED
@@ -12,7 +12,7 @@ The vesion of PDFMake has been inlined and modified to allow for text rotation.
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- npm i btrz-pdf
15
+ npm i btrz-liquid-templates
16
16
  ```
17
17
 
18
18
  ## Restrictions
@@ -111,7 +111,7 @@ Initialize the printer
111
111
  Set printer to ESC/P mode and clear memory buffer.
112
112
 
113
113
  ```liquid
114
- {% escInitQzTray %}
114
+ {% raw%} {% escInitQzTray %} {% endraw %}
115
115
  ```
116
116
 
117
117
  * ## escBold
@@ -119,7 +119,7 @@ Set printer to ESC/P mode and clear memory buffer.
119
119
  Start bold font.
120
120
 
121
121
  ```liquid
122
- {% escBold %}
122
+ {% raw%} {% escBold %} {% endraw %}
123
123
  ```
124
124
 
125
125
  * ## escCancelBold
@@ -127,7 +127,7 @@ Start bold font.
127
127
  Ends bold font.
128
128
 
129
129
  ```liquid
130
- {% escCancelBold %}
130
+ {% raw%} {% escCancelBold %} {% endraw %}
131
131
  ```
132
132
 
133
133
  * ## fontSelection
@@ -135,7 +135,7 @@ Ends bold font.
135
135
  Starts selected font
136
136
 
137
137
  ```liquid
138
- {% fontSelection %}
138
+ {% raw%} {% fontSelection %} {% endraw %}
139
139
  ```
140
140
 
141
141
  * ## escCondensed
@@ -143,7 +143,7 @@ Starts selected font
143
143
  Small condensed fonts
144
144
 
145
145
  ```liquid
146
- {% escCondensed %}
146
+ {% raw%} {% escCondensed %} {% endraw %}
147
147
  ```
148
148
 
149
149
  * ## lineSpacing
@@ -151,7 +151,7 @@ Small condensed fonts
151
151
  Line spacing to 1/6 of an inch
152
152
 
153
153
  ```liquid
154
- {% lineSpacing %}
154
+ {% raw%} {% lineSpacing %} {% endraw %}
155
155
  ```
156
156
 
157
157
  * ## lineSpacing2
@@ -159,7 +159,7 @@ Line spacing to 1/6 of an inch
159
159
  Line spacing to 1/9 of an inch
160
160
 
161
161
  ```liquid
162
- {% lineSpacing2 %}
162
+ {% raw%} {% lineSpacing2 %} {% endraw %}
163
163
  ```
164
164
 
165
165
  * ## escNewLine
@@ -167,7 +167,7 @@ Line spacing to 1/9 of an inch
167
167
  New line
168
168
 
169
169
  ```liquid
170
- {% escNewLine %}
170
+ {% raw%} {% escNewLine %} {% endraw %}
171
171
  ```
172
172
 
173
173
  * ## escCut
@@ -175,7 +175,7 @@ New line
175
175
  Paper cut
176
176
 
177
177
  ```liquid
178
- {% escCut %}
178
+ {% raw%} {% escCut %} {% endraw %}
179
179
  ```
180
180
 
181
181
  * ## escEject
@@ -183,7 +183,7 @@ Paper cut
183
183
  Form feed (eject paper)
184
184
 
185
185
  ```liquid
186
- {% escEject %}
186
+ {% raw%} {% escEject %} {% endraw %}
187
187
  ```
188
188
 
189
189
  * ## escTab
@@ -191,7 +191,7 @@ Form feed (eject paper)
191
191
  Move to next horizontal tab
192
192
 
193
193
  ```liquid
194
- {% escTab %}
194
+ {% raw%} {% escTab %} {% endraw %}
195
195
  ```
196
196
 
197
197
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-liquid-templates",
3
- "version": "1.2.0",
3
+ "version": "1.4.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": {
package/src/escp.js CHANGED
@@ -3,7 +3,7 @@ function escInitQzTray(engine) {
3
3
  parse: function(tagToken, remainTokens) {
4
4
  },
5
5
  render: async function(ctx) {
6
- return "\\x1B\\x69\\x61\\x00\\x1B\\x40";
6
+ return "\x1B\x69\x61\x00\x1B\x40";
7
7
  }
8
8
  });
9
9
  }
@@ -14,7 +14,7 @@ function lineSpacing(engine) {
14
14
 
15
15
  },
16
16
  render: async function(ctx) {
17
- return "\\x1B\\x33\\x18";
17
+ return "\x1B\x33\x18";
18
18
  }
19
19
  });
20
20
  }
@@ -25,7 +25,7 @@ function lineSpacing2(engine) {
25
25
 
26
26
  },
27
27
  render: async function(ctx) {
28
- return "\\x1B\\x33\\x24";
28
+ return "\x1B\x33\x24";
29
29
  }
30
30
  });
31
31
  }
@@ -36,7 +36,7 @@ function fontSelection(engine) {
36
36
 
37
37
  },
38
38
  render: async function(ctx) {
39
- return "\\x1B\\x4D";
39
+ return "\x1B\x4D";
40
40
  }
41
41
  });
42
42
  }
@@ -47,7 +47,7 @@ function escBold(engine) {
47
47
 
48
48
  },
49
49
  render: async function(ctx) {
50
- return "\\x1B\\x45";
50
+ return "\x1B\x45";
51
51
  }
52
52
  });
53
53
  }
@@ -58,7 +58,7 @@ function escCancelBold(engine) {
58
58
 
59
59
  },
60
60
  render: async function(ctx) {
61
- return "\\x1B\\x46";
61
+ return "\x1B\x46";
62
62
  }
63
63
  });
64
64
  }
@@ -80,7 +80,7 @@ function escCut(engine) {
80
80
 
81
81
  },
82
82
  render: async function(ctx) {
83
- return "\\x1D\\x56\\x00";
83
+ return "\x1D\x56\x00";
84
84
  }
85
85
  });
86
86
  }
@@ -102,7 +102,7 @@ function escCondensed(engine) {
102
102
 
103
103
  },
104
104
  render: async function(ctx) {
105
- return "\\x1B\\x0F";
105
+ return "\x1B\x0F";
106
106
  }
107
107
  });
108
108
  }
@@ -113,7 +113,7 @@ function escTab(engine) {
113
113
 
114
114
  },
115
115
  render: async function(ctx) {
116
- return "\\x09";
116
+ return "\x09";
117
117
  }
118
118
  });
119
119
  }
package/src/index.js CHANGED
@@ -34,16 +34,16 @@ function getEngine() {
34
34
  extname: ".liquid",
35
35
  dynamicPartials: false,
36
36
  outputEscape: (val) => {
37
- // if (typeof val === "string") {
38
- // return val.replace(/[\\]/g, '\\\\')
39
- // .replace(/[\"]/g, '\\"')
40
- // .replace(/[\/]/g, '\\/')
41
- // .replace(/[\b]/g, '\\b')
42
- // .replace(/[\f]/g, '\\f')
43
- // .replace(/[\n]/g, '\\n')
44
- // .replace(/[\r]/g, '\\r')
45
- // .replace(/[\t]/g, '\\t');
46
- // }
37
+ if (typeof val === "string") {
38
+ return val.replace(/[\\]/g, '\\\\')
39
+ .replace(/[\"]/g, '\\"')
40
+ .replace(/[\/]/g, '\\/')
41
+ .replace(/[\b]/g, '\\b')
42
+ .replace(/[\f]/g, '\\f')
43
+ .replace(/[\n]/g, '\\n')
44
+ .replace(/[\r]/g, '\\r')
45
+ .replace(/[\t]/g, '\\t');
46
+ }
47
47
  return val;
48
48
  }
49
49
  });
@@ -109,8 +109,9 @@ module.exports = {
109
109
  }).filter((line) => {
110
110
  return line.length > 0;
111
111
  })
112
- .join(",");
112
+ .join("");
113
113
  // console.log(str);
114
+ str = str.replace(/\\n/g, "\n").replace(/\\x0C/g, "\x0C");
114
115
  return str;
115
116
  },
116
117
  async processToString(liquidTemplate, data) {
@@ -724,8 +724,8 @@ and some more here`,
724
724
  {% escNewLine %}
725
725
  {% escCancelBold %}
726
726
  {% escCondensed %}
727
- {% escEject %}`
727
+ {% escEject %}`;
728
728
  const documentDefinition = await tpl.processToEscp(template, data);
729
- expect(documentDefinition).to.be.eql(`\\x1B\\x69\\x61\\x00\\x1B\\x40,\\x1B\\x33\\x24,\\x1B\\x4D,\\x1B\\x45,Shift location closure #: 5c9f8f8f8f8f8f8f8f8f8f8,\\n,\\x1B\\x46,\\x1B\\x0F,\\x0C`);
729
+ expect(documentDefinition).to.be.eql(`\u001bia\u0000\u001b@\u001b3$\u001bM\u001bEShift location closure #: 5c9f8f8f8f8f8f8f8f8f8f8\n\u001bF\u001b\u000f\f`);
730
730
  });
731
731
  });