@dogsbay/minja 0.2.0-beta.100

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +623 -0
  3. package/bin/minja.js +1225 -0
  4. package/dist/browser.d.ts +12 -0
  5. package/dist/browser.d.ts.map +1 -0
  6. package/dist/browser.js +11 -0
  7. package/dist/browser.js.map +1 -0
  8. package/dist/cli.d.ts +5 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +98 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/context.d.ts +47 -0
  13. package/dist/context.d.ts.map +1 -0
  14. package/dist/context.js +112 -0
  15. package/dist/context.js.map +1 -0
  16. package/dist/evaluator.d.ts +20 -0
  17. package/dist/evaluator.d.ts.map +1 -0
  18. package/dist/evaluator.js +213 -0
  19. package/dist/evaluator.js.map +1 -0
  20. package/dist/index.d.ts +20 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +18 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/index.umd.js +1160 -0
  25. package/dist/index.umd.js.map +7 -0
  26. package/dist/index.umd.min.js +12 -0
  27. package/dist/index.umd.min.js.map +7 -0
  28. package/dist/loader-fetch.d.ts +8 -0
  29. package/dist/loader-fetch.d.ts.map +1 -0
  30. package/dist/loader-fetch.js +15 -0
  31. package/dist/loader-fetch.js.map +1 -0
  32. package/dist/loader-memory.d.ts +11 -0
  33. package/dist/loader-memory.d.ts.map +1 -0
  34. package/dist/loader-memory.js +36 -0
  35. package/dist/loader-memory.js.map +1 -0
  36. package/dist/loader.d.ts +73 -0
  37. package/dist/loader.d.ts.map +1 -0
  38. package/dist/loader.js +159 -0
  39. package/dist/loader.js.map +1 -0
  40. package/dist/parser.d.ts +7 -0
  41. package/dist/parser.d.ts.map +1 -0
  42. package/dist/parser.js +609 -0
  43. package/dist/parser.js.map +1 -0
  44. package/dist/renderer.d.ts +13 -0
  45. package/dist/renderer.d.ts.map +1 -0
  46. package/dist/renderer.js +494 -0
  47. package/dist/renderer.js.map +1 -0
  48. package/dist/scan.d.ts +46 -0
  49. package/dist/scan.d.ts.map +1 -0
  50. package/dist/scan.js +46 -0
  51. package/dist/scan.js.map +1 -0
  52. package/dist/types.d.ts +175 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +5 -0
  55. package/dist/types.js.map +1 -0
  56. package/package.json +72 -0
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Type definitions for minja template engine
3
+ */
4
+ export type ASTNode = TextNode | VariableNode | SetNode | IfNode | IncludeNode | CommentNode | SwitchNode | LeveloffsetNode;
5
+ export interface TextNode {
6
+ type: 'text';
7
+ value: string;
8
+ }
9
+ export interface VariableNode {
10
+ type: 'variable';
11
+ name: string;
12
+ }
13
+ export interface SetNode {
14
+ type: 'set';
15
+ name: string;
16
+ value: Expression;
17
+ }
18
+ export interface IfNode {
19
+ type: 'if';
20
+ condition: Expression;
21
+ trueBranch: ASTNode[];
22
+ elifBranches?: Array<{
23
+ condition: Expression;
24
+ body: ASTNode[];
25
+ }>;
26
+ elseBranch?: ASTNode[];
27
+ }
28
+ export interface IncludeNode {
29
+ type: 'include';
30
+ path: string;
31
+ }
32
+ export interface CommentNode {
33
+ type: 'comment';
34
+ value: string;
35
+ }
36
+ export interface SwitchNode {
37
+ type: 'switch';
38
+ expression: Expression;
39
+ cases: Array<{
40
+ value: Expression;
41
+ body: ASTNode[];
42
+ }>;
43
+ }
44
+ export interface LeveloffsetNode {
45
+ type: 'leveloffset';
46
+ offset: number;
47
+ isRelative: boolean;
48
+ body: ASTNode[];
49
+ }
50
+ export type Expression = LiteralExpression | VariableExpression | BinaryExpression | UnaryExpression;
51
+ export interface LiteralExpression {
52
+ type: 'literal';
53
+ value: string | number | boolean | null;
54
+ }
55
+ export interface VariableExpression {
56
+ type: 'variable';
57
+ name: string;
58
+ }
59
+ export interface BinaryExpression {
60
+ type: 'binary';
61
+ operator: '==' | '!=' | '<' | '>' | '<=' | '>=' | 'and' | 'or';
62
+ left: Expression;
63
+ right: Expression;
64
+ }
65
+ export interface UnaryExpression {
66
+ type: 'unary';
67
+ operator: 'not';
68
+ operand: Expression;
69
+ }
70
+ export interface Loader {
71
+ /**
72
+ * Load a file from the given path.
73
+ * @param path - The path to load (can be relative or absolute)
74
+ * @param basePath - The base path to resolve relative paths against
75
+ * @returns The file contents as a string
76
+ */
77
+ load(path: string, basePath?: string): Promise<string>;
78
+ }
79
+ export interface RenderOptions {
80
+ /**
81
+ * File loader for {% include %} statements
82
+ */
83
+ loader?: Loader;
84
+ /**
85
+ * Initial context (variables)
86
+ */
87
+ context?: Record<string, unknown>;
88
+ /**
89
+ * Base path for resolving relative includes (e.g., current file URL)
90
+ */
91
+ basePath?: string;
92
+ /**
93
+ * Maximum include depth (default: 10)
94
+ */
95
+ maxIncludeDepth?: number;
96
+ /**
97
+ * Timeout in milliseconds (default: 5000)
98
+ */
99
+ timeout?: number;
100
+ /**
101
+ * Convert hyphenated variable names to underscores during lookup.
102
+ * When true, {{ my-var }} will look up 'my_var' in the context.
103
+ * (default: false)
104
+ */
105
+ hyphenToUnderscore?: boolean;
106
+ /**
107
+ * What to do when a `{{ var }}` references an identifier that
108
+ * isn't in the context.
109
+ *
110
+ * - `'empty'` (default) — emit an empty string. Unchanged behaviour
111
+ * for existing callers; matches the standard Nunjucks default.
112
+ * - `'throw'` — throw `Error('Undefined variable: <name>')`. Useful
113
+ * in strict pipelines that want to fail-fast on typos.
114
+ * - `'preserve'` — emit the literal `{{ <name> }}` (or `{% if … %}…`
115
+ * for conditionals whose condition references undefined vars).
116
+ * Used by the AsciiDoc convert pipeline so unresolved attributes
117
+ * survive into the post-render artifact for downstream resolution.
118
+ * See plans/format-asciidoc-import.md.
119
+ * - `'asciidoc-literal'` — emit the single-brace `{<name>}` form:
120
+ * what asciidoctor renders for an undefined attribute reference.
121
+ * For terminal builds of AsciiDoc-migrated corpora, where every
122
+ * `{{ name }}` the renderer sees was converted from an `{name}`
123
+ * attribute ref — an unresolvable one is a literal placeholder
124
+ * (`{namespace}`, `${url}`), not a variable to carry forward.
125
+ * Behaves like `'preserve'` for conditionals and includes.
126
+ * NOTE: the emitted name keeps Minja's underscore normalization
127
+ * (`{policy_gen_cr}` for source `{policy-gen-cr}`).
128
+ */
129
+ undefinedBehavior?: 'empty' | 'throw' | 'preserve' | 'asciidoc-literal';
130
+ /**
131
+ * How `{% if %}` conditions that reference an undefined variable
132
+ * behave. Only consulted when `undefinedBehavior` is `'preserve'`
133
+ * or `'asciidoc-literal'`.
134
+ *
135
+ * - `'preserve'` (default) — round-trip the whole
136
+ * `{% if … %}…{% endif %}` verbatim so a later pass (with the value
137
+ * supplied) can resolve it. Back-compat with the migrate pipeline.
138
+ * - `'falsy'` — treat the undefined reference as falsy and evaluate
139
+ * the condition now, dropping (or `else`-branching) the block. This
140
+ * matches AsciiDoc `ifdef::attr[]` semantics, where an undefined
141
+ * attribute is false. Use for a *terminal* build where no further
142
+ * Minja pass will run — undefined `{{ var }}` interpolations are
143
+ * still preserved, but dangling conditionals don't leak to readers.
144
+ */
145
+ undefinedConditions?: 'preserve' | 'falsy';
146
+ }
147
+ export interface IContext {
148
+ /**
149
+ * Get a variable from the context
150
+ */
151
+ get(name: string): unknown;
152
+ /**
153
+ * Set a variable in the context
154
+ */
155
+ set(name: string, value: unknown): void;
156
+ /**
157
+ * Create a child scope
158
+ */
159
+ push(): IContext;
160
+ /**
161
+ * Return to parent scope
162
+ */
163
+ pop(): IContext | null;
164
+ }
165
+ export interface ParseResult {
166
+ ast: ASTNode[];
167
+ errors: ParseError[];
168
+ }
169
+ export interface ParseError {
170
+ message: string;
171
+ position: number;
172
+ line: number;
173
+ column: number;
174
+ }
175
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,MA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G,OAAO,GAAG,UAAU,GAAG,kBAAkB,CAAA;IAEvE;;;;;;;;;;;;;;OAcG;IACH,mBAAmB,CAAC,EAAE,UAAU,GAAG,OAAO,CAAA;CAC3C;AAMD,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAE1B;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;IAEvC;;OAEG;IACH,IAAI,IAAI,QAAQ,CAAA;IAEhB;;OAEG;IACH,GAAG,IAAI,QAAQ,GAAG,IAAI,CAAA;CACvB;AAMD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,OAAO,EAAE,CAAA;IACd,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type definitions for minja template engine
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@dogsbay/minja",
3
+ "version": "0.2.0-beta.100",
4
+ "description": "Minimal, secure Jinja2/Nunjucks subset for documentation preprocessing with zero code execution",
5
+ "keywords": [
6
+ "template",
7
+ "jinja2",
8
+ "nunjucks",
9
+ "asciidoc",
10
+ "documentation",
11
+ "secure",
12
+ "sandbox",
13
+ "safe"
14
+ ],
15
+ "author": "",
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "import": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "./browser": {
32
+ "import": {
33
+ "types": "./dist/browser.d.ts",
34
+ "default": "./dist/browser.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/browser.d.ts",
38
+ "default": "./dist/browser.js"
39
+ }
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "bin"
45
+ ],
46
+ "bin": {
47
+ "minja": "./bin/minja.js"
48
+ },
49
+ "sideEffects": false,
50
+ "dependencies": {
51
+ "commander": "^15.0.0",
52
+ "yaml": "^2.9.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^20.19.43",
56
+ "esbuild": "^0.19.12",
57
+ "typescript": "^5.9.3",
58
+ "vitest": "^4.1.10"
59
+ },
60
+ "engines": {
61
+ "node": ">=18.0.0"
62
+ },
63
+ "scripts": {
64
+ "build": "node build.mjs",
65
+ "dev": "node build.mjs --watch",
66
+ "test": "vitest run",
67
+ "test:watch": "vitest",
68
+ "test:coverage": "vitest run --coverage",
69
+ "lint": "tsc --noEmit",
70
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\""
71
+ }
72
+ }