@trustme24/flext 2.0.0 → 2.0.1
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 +13 -13
- package/dist/dialects/index.d.ts +0 -1
- package/dist/dialects/legacy-1-0-beta4.d.ts +7 -1
- package/dist/index.cjs +113 -111
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -20
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/src/dialects/index.ts +0 -1
- package/src/dialects/legacy-1-0-beta4.ts +69 -1
- package/src/index.ts +8 -1
- package/dist/dialects/legacy-1-0-beta3.d.ts +0 -5
- package/src/dialects/legacy-1-0-beta3.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustme24/flext",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A technology for building reliable document templates",
|
|
5
5
|
"keywords": ["templates", "templating engine", "documents", "document engine", "handlebars"],
|
|
6
6
|
"repository": "https://github.com/TrustMe-kz/flext.git",
|
package/src/dialects/index.ts
CHANGED
|
@@ -1,7 +1,75 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AST } from '@handlebars/parser';
|
|
2
|
+
import { types, lib, Dialect, BaseError, BaseWarning } from '@flext/core';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// Constants
|
|
6
|
+
|
|
7
|
+
export const HANDLEBARS_COMMENT_BEGIN = '{{!--';
|
|
8
|
+
|
|
9
|
+
export const DIALECT_MACRO = 'syntax';
|
|
10
|
+
|
|
11
|
+
export const LEGACY_DIALECT_MACRO = 'v';
|
|
12
|
+
|
|
2
13
|
|
|
3
14
|
export class LegacyDialect extends Dialect {
|
|
4
15
|
public name = '1.0.beta4';
|
|
16
|
+
|
|
17
|
+
public testAst(val: AST.Program, doWarn?: boolean|null): boolean {
|
|
18
|
+
|
|
19
|
+
// Doing some checks
|
|
20
|
+
|
|
21
|
+
if (!this.name)
|
|
22
|
+
throw new BaseError(`Flext: Unable to test the template: 'name' param is not set in the dialect`);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// Doing some checks
|
|
26
|
+
|
|
27
|
+
const macros = lib.astToMacros(val);
|
|
28
|
+
const macro = macros?.find(m => m?.name === LEGACY_DIALECT_MACRO) ?? null;
|
|
29
|
+
|
|
30
|
+
if (!macro) {
|
|
31
|
+
if (doWarn)
|
|
32
|
+
throw new BaseWarning(`Flext: Unable to test the template: '@v' macro is not set`);
|
|
33
|
+
else
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// Getting the dialect
|
|
39
|
+
|
|
40
|
+
const [ param ] = macro?.params ?? [];
|
|
41
|
+
|
|
42
|
+
if (!param) {
|
|
43
|
+
if (doWarn)
|
|
44
|
+
throw new BaseWarning(`Flext: Unable to test the template: Bad '@v' macro`);
|
|
45
|
+
else
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (this.aliases && this.aliases?.length)
|
|
51
|
+
return param?.value === this.name || lib.inarr(param?.value, ...this.aliases);
|
|
52
|
+
else
|
|
53
|
+
return param?.value === this.name;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public templateToStandard(template: types.Template): types.StandardTemplate {
|
|
57
|
+
let result = template;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Defining the functions
|
|
61
|
+
|
|
62
|
+
const filter = (search: string, val: string): void => { result = result.replace(search, val); };
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Getting the template
|
|
66
|
+
|
|
67
|
+
filter(HANDLEBARS_COMMENT_BEGIN + ' @' + LEGACY_DIALECT_MACRO, HANDLEBARS_COMMENT_BEGIN + ' @' + DIALECT_MACRO); // '{{!-- @v' --> '{{!-- @syntax'
|
|
68
|
+
filter(HANDLEBARS_COMMENT_BEGIN + '@' + LEGACY_DIALECT_MACRO, HANDLEBARS_COMMENT_BEGIN + '@' + DIALECT_MACRO); // '{{!--@v' --> '{{!--@syntax'
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
5
73
|
}
|
|
6
74
|
|
|
7
75
|
export default LegacyDialect;
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,13 @@ import * as core from '@flext/core';
|
|
|
4
4
|
import * as dialects from '@/dialects';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
// Constants
|
|
8
|
+
|
|
9
|
+
export const DIALECT_MACRO = 'syntax';
|
|
10
|
+
|
|
11
|
+
export const LEGACY_DIALECT_MACRO = 'v';
|
|
12
|
+
|
|
13
|
+
|
|
7
14
|
// Variables
|
|
8
15
|
|
|
9
16
|
export const latestDialect = new dialects.Latest();
|
|
@@ -17,7 +24,7 @@ export class Flext extends Processor implements types.FlextInterface {
|
|
|
17
24
|
|
|
18
25
|
// Getting the macro
|
|
19
26
|
|
|
20
|
-
const macro = macros?.find(m => m?.name
|
|
27
|
+
const macro = macros?.find(m => lib.inarr(m?.name, DIALECT_MACRO, LEGACY_DIALECT_MACRO)) ?? null;
|
|
21
28
|
|
|
22
29
|
if (!macro) {
|
|
23
30
|
this.setDialect(latestDialect);
|