@itrocks/template 0.0.33 → 0.0.35

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/cjs/template.d.ts CHANGED
@@ -28,6 +28,7 @@ export declare class Template {
28
28
  inLiteral: boolean;
29
29
  }[];
30
30
  target: string;
31
+ targetReplace: string;
31
32
  targetStack: string[];
32
33
  doLiteral: boolean;
33
34
  inLiteral: boolean;
@@ -92,7 +93,7 @@ export declare class Template {
92
93
  target: string;
93
94
  targetStack: string[];
94
95
  };
95
- include(path: string, data: any): Promise<any>;
96
+ include(path: string, data: any): Promise<string>;
96
97
  isContextClean(): boolean;
97
98
  literalTarget(index: number, isTitle?: boolean): void;
98
99
  parseBuffer(buffer: string): Promise<string>;
package/cjs/template.js CHANGED
@@ -23,6 +23,7 @@ class Template {
23
23
  tagName = '';
24
24
  tagStack = [];
25
25
  target = '';
26
+ targetReplace = '';
26
27
  targetStack = [];
27
28
  // literal
28
29
  doLiteral = false;
@@ -174,6 +175,12 @@ class Template {
174
175
  this.headLinks.push(...template.headLinks);
175
176
  const beginPosition = parsed.indexOf('<!--BEGIN-->');
176
177
  const endPosition = parsed.indexOf('<!--END-->');
178
+ if ((beginPosition === -1) && (parsed[1] === '!') && parsed.startsWith('<!DOCTYPE html>')) {
179
+ if (this.targetReplace === '') {
180
+ this.targetReplace = parsed;
181
+ }
182
+ return '';
183
+ }
177
184
  return (beginPosition > -1)
178
185
  ? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
179
186
  : parsed;
@@ -230,7 +237,7 @@ class Template {
230
237
  + this.headTitle
231
238
  + this.target.slice(this.target.indexOf('</title>', position));
232
239
  }
233
- return this.target;
240
+ return (this.targetReplace !== '') ? this.targetReplace : this.target;
234
241
  }
235
242
  async parseExpression(data, open, close, finalClose = '') {
236
243
  const indexOut = this.index;
@@ -718,9 +725,7 @@ class Template {
718
725
  if (targetTagIndex > -1) {
719
726
  this.sourceToTarget();
720
727
  const headLink = this.target.substring(targetTagIndex);
721
- if (!this.doneLinks.includes(headLink)) {
722
- this.headLinks.insert(headLink);
723
- }
728
+ this.headLinks.insert(headLink);
724
729
  }
725
730
  if (inScript) {
726
731
  continue;
@@ -815,7 +820,7 @@ class Template {
815
820
  this.start = this.index;
816
821
  }
817
822
  startsExpression(char, open = '{', close = '}') {
818
- return RegExp('[a-z0-9"*.?\'' + open + close + this.prefixes + ']', 'i').test(char);
823
+ return RegExp(`[a-z0-9"'*./?` + open + close + this.prefixes + ']', 'i').test(char);
819
824
  }
820
825
  trimEndLine(string) {
821
826
  let index = string.length;
package/esm/template.d.ts CHANGED
@@ -28,6 +28,7 @@ export declare class Template {
28
28
  inLiteral: boolean;
29
29
  }[];
30
30
  target: string;
31
+ targetReplace: string;
31
32
  targetStack: string[];
32
33
  doLiteral: boolean;
33
34
  inLiteral: boolean;
@@ -92,7 +93,7 @@ export declare class Template {
92
93
  target: string;
93
94
  targetStack: string[];
94
95
  };
95
- include(path: string, data: any): Promise<any>;
96
+ include(path: string, data: any): Promise<string>;
96
97
  isContextClean(): boolean;
97
98
  literalTarget(index: number, isTitle?: boolean): void;
98
99
  parseBuffer(buffer: string): Promise<string>;
package/esm/template.js CHANGED
@@ -20,6 +20,7 @@ export class Template {
20
20
  tagName = '';
21
21
  tagStack = [];
22
22
  target = '';
23
+ targetReplace = '';
23
24
  targetStack = [];
24
25
  // literal
25
26
  doLiteral = false;
@@ -171,6 +172,12 @@ export class Template {
171
172
  this.headLinks.push(...template.headLinks);
172
173
  const beginPosition = parsed.indexOf('<!--BEGIN-->');
173
174
  const endPosition = parsed.indexOf('<!--END-->');
175
+ if ((beginPosition === -1) && (parsed[1] === '!') && parsed.startsWith('<!DOCTYPE html>')) {
176
+ if (this.targetReplace === '') {
177
+ this.targetReplace = parsed;
178
+ }
179
+ return '';
180
+ }
174
181
  return (beginPosition > -1)
175
182
  ? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
176
183
  : parsed;
@@ -227,7 +234,7 @@ export class Template {
227
234
  + this.headTitle
228
235
  + this.target.slice(this.target.indexOf('</title>', position));
229
236
  }
230
- return this.target;
237
+ return (this.targetReplace !== '') ? this.targetReplace : this.target;
231
238
  }
232
239
  async parseExpression(data, open, close, finalClose = '') {
233
240
  const indexOut = this.index;
@@ -715,9 +722,7 @@ export class Template {
715
722
  if (targetTagIndex > -1) {
716
723
  this.sourceToTarget();
717
724
  const headLink = this.target.substring(targetTagIndex);
718
- if (!this.doneLinks.includes(headLink)) {
719
- this.headLinks.insert(headLink);
720
- }
725
+ this.headLinks.insert(headLink);
721
726
  }
722
727
  if (inScript) {
723
728
  continue;
@@ -812,7 +817,7 @@ export class Template {
812
817
  this.start = this.index;
813
818
  }
814
819
  startsExpression(char, open = '{', close = '}') {
815
- return RegExp('[a-z0-9"*.?\'' + open + close + this.prefixes + ']', 'i').test(char);
820
+ return RegExp(`[a-z0-9"'*./?` + open + close + this.prefixes + ']', 'i').test(char);
816
821
  }
817
822
  trimEndLine(string) {
818
823
  let index = string.length;
package/package.json CHANGED
@@ -69,5 +69,5 @@
69
69
  "test": "jest"
70
70
  },
71
71
  "types": "./esm/template.d.ts",
72
- "version": "0.0.33"
72
+ "version": "0.0.35"
73
73
  }