@unrdf/kgn 5.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/LICENSE +21 -0
- package/README.md +210 -0
- package/package.json +90 -0
- package/src/MIGRATION_COMPLETE.md +186 -0
- package/src/PORT-MAP.md +302 -0
- package/src/base/filter-templates.js +479 -0
- package/src/base/index.js +92 -0
- package/src/base/injection-targets.js +583 -0
- package/src/base/macro-templates.js +298 -0
- package/src/base/macro-templates.js.bak +461 -0
- package/src/base/shacl-templates.js +617 -0
- package/src/base/template-base.js +388 -0
- package/src/core/attestor.js +381 -0
- package/src/core/filters.js +518 -0
- package/src/core/index.js +21 -0
- package/src/core/kgen-engine.js +372 -0
- package/src/core/parser.js +447 -0
- package/src/core/post-processor.js +313 -0
- package/src/core/renderer.js +469 -0
- package/src/doc-generator/cli.mjs +122 -0
- package/src/doc-generator/index.mjs +28 -0
- package/src/doc-generator/mdx-generator.mjs +71 -0
- package/src/doc-generator/nav-generator.mjs +136 -0
- package/src/doc-generator/parser.mjs +291 -0
- package/src/doc-generator/rdf-builder.mjs +306 -0
- package/src/doc-generator/scanner.mjs +189 -0
- package/src/engine/index.js +42 -0
- package/src/engine/pipeline.js +448 -0
- package/src/engine/renderer.js +604 -0
- package/src/engine/template-engine.js +566 -0
- package/src/filters/array.js +436 -0
- package/src/filters/data.js +479 -0
- package/src/filters/index.js +270 -0
- package/src/filters/rdf.js +264 -0
- package/src/filters/text.js +369 -0
- package/src/index.js +109 -0
- package/src/inheritance/index.js +40 -0
- package/src/injection/api.js +260 -0
- package/src/injection/atomic-writer.js +327 -0
- package/src/injection/constants.js +136 -0
- package/src/injection/idempotency-manager.js +295 -0
- package/src/injection/index.js +28 -0
- package/src/injection/injection-engine.js +378 -0
- package/src/injection/integration.js +339 -0
- package/src/injection/modes/index.js +341 -0
- package/src/injection/rollback-manager.js +373 -0
- package/src/injection/target-resolver.js +323 -0
- package/src/injection/tests/atomic-writer.test.js +382 -0
- package/src/injection/tests/injection-engine.test.js +611 -0
- package/src/injection/tests/integration.test.js +392 -0
- package/src/injection/tests/run-tests.js +283 -0
- package/src/injection/validation-engine.js +547 -0
- package/src/linter/determinism-linter.js +473 -0
- package/src/linter/determinism.js +410 -0
- package/src/linter/index.js +6 -0
- package/src/linter/test-doubles.js +475 -0
- package/src/parser/frontmatter.js +228 -0
- package/src/parser/variables.js +344 -0
- package/src/renderer/deterministic.js +245 -0
- package/src/renderer/index.js +6 -0
- package/src/templates/latex/academic-paper.njk +186 -0
- package/src/templates/latex/index.js +104 -0
- package/src/templates/nextjs/app-page.njk +66 -0
- package/src/templates/nextjs/index.js +80 -0
- package/src/templates/office/docx/document.njk +368 -0
- package/src/templates/office/index.js +79 -0
- package/src/templates/office/word-report.njk +129 -0
- package/src/utils/template-utils.js +426 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KGEN Macro Templates - Reusable template components (Fixed)
|
|
3
|
+
*
|
|
4
|
+
* Provides a library of pre-built macros for common template patterns
|
|
5
|
+
* All macros are deterministic and compatible with KGEN template engine
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class KGenMacroTemplates {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.options = {
|
|
11
|
+
deterministicMode: options.deterministicMode !== false,
|
|
12
|
+
staticBuildTime: options.staticBuildTime || '2024-01-01T00:00:00.000Z',
|
|
13
|
+
namespace: options.namespace || 'kgen',
|
|
14
|
+
...options
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.macros = new Map();
|
|
18
|
+
this.initializeMacros();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Initialize built-in macro templates
|
|
23
|
+
*/
|
|
24
|
+
initializeMacros() {
|
|
25
|
+
// Document structure macros
|
|
26
|
+
this.registerMacro('document_header', `{%- macro document_header(title, author, version='1.0.0') -%}
|
|
27
|
+
/**
|
|
28
|
+
* {{ title }}
|
|
29
|
+
*
|
|
30
|
+
* @author {{ author | default('KGEN Generator') }}
|
|
31
|
+
* @version {{ version }}
|
|
32
|
+
* @generated {{ __kgen.renderTime }}
|
|
33
|
+
* @hash {{ (title + author + version) | hash | shortHash(8) }}
|
|
34
|
+
*/
|
|
35
|
+
{%- endmacro -%}`);
|
|
36
|
+
|
|
37
|
+
this.registerMacro('code_block', `{%- macro code_block(content, language='javascript') -%}
|
|
38
|
+
\\u0060\\u0060\\u0060{{ language }}
|
|
39
|
+
{{ content }}
|
|
40
|
+
\\u0060\\u0060\\u0060
|
|
41
|
+
{%- endmacro -%}`);
|
|
42
|
+
|
|
43
|
+
// HTML/Web macros
|
|
44
|
+
this.registerMacro('html_form', `{%- macro html_form(fields, action='#', method='POST', cssClass='kgen-form') -%}
|
|
45
|
+
<form action="{{ action }}" method="{{ method }}" class="{{ cssClass }}">
|
|
46
|
+
{%- for field in fields %}
|
|
47
|
+
<div class="form-group">
|
|
48
|
+
{%- if field.label %}
|
|
49
|
+
<label for="{{ field.name }}">{{ field.label }}</label>
|
|
50
|
+
{%- endif %}
|
|
51
|
+
<input
|
|
52
|
+
type="{{ field.type | default('text') }}"
|
|
53
|
+
name="{{ field.name }}"
|
|
54
|
+
id="{{ field.name }}"
|
|
55
|
+
{%- if field.required %} required{% endif %}
|
|
56
|
+
{%- if field.placeholder %} placeholder="{{ field.placeholder }}"{% endif %}
|
|
57
|
+
{%- if field.value %} value="{{ field.value }}"{% endif %}
|
|
58
|
+
class="form-control"
|
|
59
|
+
>
|
|
60
|
+
</div>
|
|
61
|
+
{%- endfor %}
|
|
62
|
+
<button type="submit" class="btn btn-primary">Submit</button>
|
|
63
|
+
</form>
|
|
64
|
+
{%- endmacro -%}`);
|
|
65
|
+
|
|
66
|
+
// Code generation macros
|
|
67
|
+
this.registerMacro('js_class', `{%- macro js_class(className, methods=[], imports=[], exports=true) -%}
|
|
68
|
+
{%- if imports | length > 0 %}
|
|
69
|
+
{%- for import in imports %}
|
|
70
|
+
import {{ import.name }}{{ import.from ? ' from \\'' + import.from + '\\'' : '' }};
|
|
71
|
+
{%- endfor %}
|
|
72
|
+
|
|
73
|
+
{%- endif %}
|
|
74
|
+
{%- if exports %}export {% endif %}class {{ className }} {
|
|
75
|
+
constructor(options = {}) {
|
|
76
|
+
this.options = { ...options };
|
|
77
|
+
}
|
|
78
|
+
{%- for method in methods %}
|
|
79
|
+
|
|
80
|
+
{{ method.name }}({{ method.params | default('') }}) {
|
|
81
|
+
{{ method.body | default('// Method implementation') }}
|
|
82
|
+
}
|
|
83
|
+
{%- endfor %}
|
|
84
|
+
}
|
|
85
|
+
{%- if exports %}
|
|
86
|
+
|
|
87
|
+
export default {{ className }};
|
|
88
|
+
{%- endif %}
|
|
89
|
+
{%- endmacro -%}`);
|
|
90
|
+
|
|
91
|
+
this.registerMacro('js_function', `{%- macro js_function(name, params=[], body='', isAsync=false, isExport=false) -%}
|
|
92
|
+
{%- if isExport %}export {% endif %}{%- if isAsync %}async {% endif %}function {{ name }}({{ params | join(', ') }}) {
|
|
93
|
+
{{ body }}
|
|
94
|
+
}
|
|
95
|
+
{%- endmacro -%}`);
|
|
96
|
+
|
|
97
|
+
// Configuration macros
|
|
98
|
+
this.registerMacro('config_json', `{%- macro config_json(config, indent=2) -%}
|
|
99
|
+
{
|
|
100
|
+
{%- for key, value in config.items() %}
|
|
101
|
+
{{ ' '.repeat(indent) }}"{{ key }}": {{ value | json }}{%- if not loop.last %},{% endif %}
|
|
102
|
+
{%- endfor %}
|
|
103
|
+
}
|
|
104
|
+
{%- endmacro -%}`);
|
|
105
|
+
|
|
106
|
+
this.registerMacro('env_file', `{%- macro env_file(vars) -%}
|
|
107
|
+
# Environment Configuration
|
|
108
|
+
# Generated {{ __kgen.renderTime }}
|
|
109
|
+
|
|
110
|
+
{%- for key, value in vars.items() %}
|
|
111
|
+
{{ key }}={{ value }}
|
|
112
|
+
{%- endfor %}
|
|
113
|
+
{%- endmacro -%}`);
|
|
114
|
+
|
|
115
|
+
// Testing macros
|
|
116
|
+
this.registerMacro('test_suite', `{%- macro test_suite(name, tests=[], setup='', teardown='') -%}
|
|
117
|
+
describe('{{ name }}', () => {
|
|
118
|
+
{%- if setup %}
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
{{ setup }}
|
|
121
|
+
});
|
|
122
|
+
{%- endif %}
|
|
123
|
+
|
|
124
|
+
{%- for test in tests %}
|
|
125
|
+
it('{{ test.description }}', {{ 'async ' if test.async }}() => {
|
|
126
|
+
{{ test.body }}
|
|
127
|
+
});
|
|
128
|
+
{%- endfor %}
|
|
129
|
+
|
|
130
|
+
{%- if teardown %}
|
|
131
|
+
afterEach(() => {
|
|
132
|
+
{{ teardown }}
|
|
133
|
+
});
|
|
134
|
+
{%- endif %}
|
|
135
|
+
});
|
|
136
|
+
{%- endmacro -%}`);
|
|
137
|
+
|
|
138
|
+
// Utility macros
|
|
139
|
+
this.registerMacro('copyright_notice', `{%- macro copyright_notice(year, holder, license='MIT') -%}
|
|
140
|
+
/**
|
|
141
|
+
* Copyright (c) {{ year }} {{ holder }}
|
|
142
|
+
*
|
|
143
|
+
* Licensed under the {{ license }} License
|
|
144
|
+
* Generated by KGEN {{ __kgen.renderTime }}
|
|
145
|
+
*/
|
|
146
|
+
{%- endmacro -%}`);
|
|
147
|
+
|
|
148
|
+
this.registerMacro('version_info', `{%- macro version_info(version, date, changes=[]) -%}
|
|
149
|
+
/**
|
|
150
|
+
* Version: {{ version }}
|
|
151
|
+
* Date: {{ date }}
|
|
152
|
+
* {%- if changes | length > 0 %}
|
|
153
|
+
* Changes:
|
|
154
|
+
{%- for change in changes %}
|
|
155
|
+
* - {{ change }}
|
|
156
|
+
{%- endfor %}
|
|
157
|
+
* {%- endif %}
|
|
158
|
+
*/
|
|
159
|
+
{%- endmacro -%}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Register a macro template
|
|
164
|
+
*/
|
|
165
|
+
registerMacro(name, template, metadata = {}) {
|
|
166
|
+
this.macros.set(name, {
|
|
167
|
+
template,
|
|
168
|
+
metadata: {
|
|
169
|
+
name,
|
|
170
|
+
registered: this.options.staticBuildTime,
|
|
171
|
+
namespace: this.options.namespace,
|
|
172
|
+
deterministic: true,
|
|
173
|
+
...metadata
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get macro template by name
|
|
180
|
+
*/
|
|
181
|
+
getMacro(name) {
|
|
182
|
+
return this.macros.get(name);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get all macro names
|
|
187
|
+
*/
|
|
188
|
+
getMacroNames() {
|
|
189
|
+
return Array.from(this.macros.keys()).sort();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Generate macro library as template content
|
|
194
|
+
*/
|
|
195
|
+
generateMacroLibrary(macroNames = []) {
|
|
196
|
+
const macrosToInclude = macroNames.length > 0
|
|
197
|
+
? macroNames.filter(name => this.macros.has(name))
|
|
198
|
+
: Array.from(this.macros.keys());
|
|
199
|
+
|
|
200
|
+
const content = [];
|
|
201
|
+
|
|
202
|
+
content.push('{% comment %}');
|
|
203
|
+
content.push('KGEN Macro Library');
|
|
204
|
+
content.push(`Generated: ${this.options.staticBuildTime}`);
|
|
205
|
+
content.push(`Macros: ${macrosToInclude.length}`);
|
|
206
|
+
content.push('{% endcomment %}');
|
|
207
|
+
content.push('');
|
|
208
|
+
|
|
209
|
+
for (const name of macrosToInclude.sort()) {
|
|
210
|
+
const macro = this.macros.get(name);
|
|
211
|
+
if (macro) {
|
|
212
|
+
content.push(`{% comment %} Macro: ${name} {% endcomment %}`);
|
|
213
|
+
content.push(macro.template);
|
|
214
|
+
content.push('');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return content.join('\\n');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Export macros for external use
|
|
223
|
+
*/
|
|
224
|
+
exportMacros(format = 'kgen') {
|
|
225
|
+
const exported = {
|
|
226
|
+
format,
|
|
227
|
+
generated: this.options.staticBuildTime,
|
|
228
|
+
namespace: this.options.namespace,
|
|
229
|
+
macros: {}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
for (const [name, macro] of this.macros) {
|
|
233
|
+
exported.macros[name] = {
|
|
234
|
+
template: macro.template,
|
|
235
|
+
metadata: macro.metadata
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return exported;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Validate macro template syntax
|
|
244
|
+
*/
|
|
245
|
+
validateMacro(name) {
|
|
246
|
+
const macro = this.macros.get(name);
|
|
247
|
+
if (!macro) {
|
|
248
|
+
throw new Error(`Macro '${name}' not found`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Basic syntax validation
|
|
252
|
+
const template = macro.template;
|
|
253
|
+
const errors = [];
|
|
254
|
+
|
|
255
|
+
// Check for balanced tags
|
|
256
|
+
const macroStart = template.match(/{%-?\\s*macro\\s+/g) || [];
|
|
257
|
+
const macroEnd = template.match(/{%-?\\s*endmacro\\s*-?%}/g) || [];
|
|
258
|
+
|
|
259
|
+
if (macroStart.length !== macroEnd.length) {
|
|
260
|
+
errors.push('Unbalanced macro tags');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
valid: errors.length === 0,
|
|
265
|
+
errors
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get macro statistics
|
|
271
|
+
*/
|
|
272
|
+
getStats() {
|
|
273
|
+
const stats = {
|
|
274
|
+
total: this.macros.size,
|
|
275
|
+
categories: {},
|
|
276
|
+
imported: 0,
|
|
277
|
+
invalid: 0
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
for (const [name, macro] of this.macros) {
|
|
281
|
+
const category = macro.metadata.category || 'general';
|
|
282
|
+
stats.categories[category] = (stats.categories[category] || 0) + 1;
|
|
283
|
+
|
|
284
|
+
if (macro.metadata.imported) {
|
|
285
|
+
stats.imported++;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const validation = this.validateMacro(name);
|
|
289
|
+
if (!validation.valid) {
|
|
290
|
+
stats.invalid++;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return stats;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export default KGenMacroTemplates;
|