@tyravel/views 0.1.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/dist/compiler.d.ts +4 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +332 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compiler.test.d.ts +2 -0
- package/dist/compiler.test.d.ts.map +1 -0
- package/dist/compiler.test.js +40 -0
- package/dist/compiler.test.js.map +1 -0
- package/dist/escape.d.ts +2 -0
- package/dist/escape.d.ts.map +1 -0
- package/dist/escape.js +14 -0
- package/dist/escape.js.map +1 -0
- package/dist/evaluate.d.ts +8 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +42 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/renderer.d.ts +5 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +70 -0
- package/dist/renderer.js.map +1 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/view-engine.d.ts +13 -0
- package/dist/view-engine.d.ts.map +1 -0
- package/dist/view-engine.js +57 -0
- package/dist/view-engine.js.map +1 -0
- package/dist/view-engine.test.d.ts +2 -0
- package/dist/view-engine.test.d.ts.map +1 -0
- package/dist/view-engine.test.js +67 -0
- package/dist/view-engine.test.js.map +1 -0
- package/dist/view-helpers.d.ts +11 -0
- package/dist/view-helpers.d.ts.map +1 -0
- package/dist/view-helpers.js +25 -0
- package/dist/view-helpers.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiB/D,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CASxD;AAqXD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CAsBhE"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
const LAYOUT_RE = /^@layout\(\s*['"]([^'"]+)['"]\s*\)\s*$/m;
|
|
2
|
+
const SECTION_START_RE = /^@section\(\s*['"]([^'"]+)['"]\s*\)\s*$/;
|
|
3
|
+
const SECTION_END_RE = /^@endsection\s*$/;
|
|
4
|
+
const YIELD_RE = /^@yield\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]*)['"]\s*)?\)\s*$/;
|
|
5
|
+
const INCLUDE_RE = /^@include\(\s*['"]([^'"]+)['"]\s*(?:,\s*(.+))?\)\s*$/;
|
|
6
|
+
const COMPONENT_RE = /^@component\(\s*['"]([^'"]+)['"]\s*(?:,\s*(.+))?\)\s*$/;
|
|
7
|
+
const IF_RE = /^@if\s*\((.+)\)\s*$/;
|
|
8
|
+
const ELSEIF_RE = /^@elseif\s*\((.+)\)\s*$/;
|
|
9
|
+
const ELSE_RE = /^@else\s*$/;
|
|
10
|
+
const ENDIF_RE = /^@endif\s*$/;
|
|
11
|
+
const FOREACH_RE = /^@foreach\s*\((.+)\)\s*$/;
|
|
12
|
+
const ENDFOREACH_RE = /^@endforeach\s*$/;
|
|
13
|
+
const ECHO_RE = /\{\{\s*(.+?)\s*\}\}/g;
|
|
14
|
+
const RAW_ECHO_RE = /\{!!\s*(.+?)\s*!!\}/g;
|
|
15
|
+
export function compile(source) {
|
|
16
|
+
const layoutMatch = source.match(LAYOUT_RE);
|
|
17
|
+
const layout = layoutMatch?.[1];
|
|
18
|
+
const body = layout ? source.replace(LAYOUT_RE, '').trimStart() : source;
|
|
19
|
+
return {
|
|
20
|
+
layout,
|
|
21
|
+
ops: parseOps(body),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function parseOps(source) {
|
|
25
|
+
const ops = [];
|
|
26
|
+
let cursor = 0;
|
|
27
|
+
while (cursor < source.length) {
|
|
28
|
+
const nextSpecial = findNextSpecial(source, cursor);
|
|
29
|
+
if (nextSpecial === -1) {
|
|
30
|
+
appendText(ops, source.slice(cursor));
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (nextSpecial > cursor) {
|
|
34
|
+
appendText(ops, source.slice(cursor, nextSpecial));
|
|
35
|
+
cursor = nextSpecial;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const remaining = source.slice(cursor);
|
|
39
|
+
if (remaining.startsWith('{{')) {
|
|
40
|
+
const match = remaining.match(/^\{\{\s*(.+?)\s*\}\}/);
|
|
41
|
+
if (match) {
|
|
42
|
+
ops.push({ type: 'echo', expression: match[1], raw: false });
|
|
43
|
+
cursor += match[0].length;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (remaining.startsWith('{!!')) {
|
|
48
|
+
const match = remaining.match(/^\{!!\s*(.+?)\s*!!\}/);
|
|
49
|
+
if (match) {
|
|
50
|
+
ops.push({ type: 'echo', expression: match[1], raw: true });
|
|
51
|
+
cursor += match[0].length;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const line = takeLine(source, cursor);
|
|
56
|
+
const trimmed = line.trim();
|
|
57
|
+
const ifMatch = trimmed.match(IF_RE);
|
|
58
|
+
if (ifMatch) {
|
|
59
|
+
const block = parseConditionalBlock(source, cursor);
|
|
60
|
+
ops.push(block.op);
|
|
61
|
+
cursor = block.end;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const foreachMatch = trimmed.match(FOREACH_RE);
|
|
65
|
+
if (foreachMatch) {
|
|
66
|
+
const block = parseForeachBlock(source, cursor);
|
|
67
|
+
ops.push(block.op);
|
|
68
|
+
cursor = block.end;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const sectionMatch = trimmed.match(SECTION_START_RE);
|
|
72
|
+
if (sectionMatch) {
|
|
73
|
+
const block = parseSectionBlock(source, cursor, sectionMatch[1]);
|
|
74
|
+
ops.push(block.op);
|
|
75
|
+
cursor = block.end;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const yieldMatch = trimmed.match(YIELD_RE);
|
|
79
|
+
if (yieldMatch) {
|
|
80
|
+
ops.push({
|
|
81
|
+
type: 'yield',
|
|
82
|
+
name: yieldMatch[1],
|
|
83
|
+
defaultValue: yieldMatch[2],
|
|
84
|
+
});
|
|
85
|
+
cursor += line.length;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const includeMatch = trimmed.match(INCLUDE_RE);
|
|
89
|
+
if (includeMatch) {
|
|
90
|
+
ops.push({
|
|
91
|
+
type: 'include',
|
|
92
|
+
name: includeMatch[1],
|
|
93
|
+
dataExpression: includeMatch[2]?.trim(),
|
|
94
|
+
});
|
|
95
|
+
cursor += line.length;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const componentMatch = trimmed.match(COMPONENT_RE);
|
|
99
|
+
if (componentMatch) {
|
|
100
|
+
ops.push({
|
|
101
|
+
type: 'component',
|
|
102
|
+
name: componentMatch[1],
|
|
103
|
+
dataExpression: componentMatch[2]?.trim(),
|
|
104
|
+
});
|
|
105
|
+
cursor += line.length;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
appendText(ops, line);
|
|
109
|
+
cursor += line.length;
|
|
110
|
+
}
|
|
111
|
+
return ops;
|
|
112
|
+
}
|
|
113
|
+
function parseConditionalBlock(source, start) {
|
|
114
|
+
const firstLine = takeLine(source, start);
|
|
115
|
+
const expression = firstLine.trim().match(IF_RE)?.[1] ?? 'false';
|
|
116
|
+
const contentStart = start + firstLine.length;
|
|
117
|
+
const contentEnd = findNestedEnd(source, contentStart, IF_RE, ENDIF_RE);
|
|
118
|
+
const endifLine = takeLine(source, contentEnd);
|
|
119
|
+
const branches = splitConditionalBranches(source.slice(contentStart, contentEnd));
|
|
120
|
+
const [first, ...rest] = branches;
|
|
121
|
+
const elseBody = rest.length > 0 ? flattenBranches(rest) : undefined;
|
|
122
|
+
return {
|
|
123
|
+
op: {
|
|
124
|
+
type: 'if',
|
|
125
|
+
expression,
|
|
126
|
+
body: first?.body ?? [],
|
|
127
|
+
elseBody,
|
|
128
|
+
},
|
|
129
|
+
end: contentEnd + endifLine.length,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function splitConditionalBranches(content) {
|
|
133
|
+
const branches = [{ body: [] }];
|
|
134
|
+
let cursor = 0;
|
|
135
|
+
while (cursor < content.length) {
|
|
136
|
+
const line = takeLine(content, cursor);
|
|
137
|
+
const trimmed = line.trim();
|
|
138
|
+
if (ELSEIF_RE.test(trimmed)) {
|
|
139
|
+
branches.push({
|
|
140
|
+
expression: trimmed.match(ELSEIF_RE)?.[1],
|
|
141
|
+
body: [],
|
|
142
|
+
});
|
|
143
|
+
cursor += line.length;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (ELSE_RE.test(trimmed)) {
|
|
147
|
+
branches.push({ body: [] });
|
|
148
|
+
cursor += line.length;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const end = findBlockBoundary(content, cursor, [ELSEIF_RE, ELSE_RE]);
|
|
152
|
+
const chunk = content.slice(cursor, end);
|
|
153
|
+
const current = branches[branches.length - 1];
|
|
154
|
+
if (current && chunk.length > 0) {
|
|
155
|
+
current.body.push(...parseOps(chunk));
|
|
156
|
+
}
|
|
157
|
+
if (end <= cursor) {
|
|
158
|
+
cursor += Math.max(line.length, 1);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
cursor = end;
|
|
162
|
+
}
|
|
163
|
+
return branches;
|
|
164
|
+
}
|
|
165
|
+
function flattenBranches(branches) {
|
|
166
|
+
if (branches.length === 0) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
const [current, ...remaining] = branches;
|
|
170
|
+
if (!current) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
if (current.expression === undefined) {
|
|
174
|
+
return current.body;
|
|
175
|
+
}
|
|
176
|
+
return [
|
|
177
|
+
{
|
|
178
|
+
type: 'if',
|
|
179
|
+
expression: current.expression,
|
|
180
|
+
body: current.body,
|
|
181
|
+
elseBody: flattenBranches(remaining),
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
function parseForeachBlock(source, start) {
|
|
186
|
+
const firstLine = takeLine(source, start);
|
|
187
|
+
const expression = firstLine.trim().match(FOREACH_RE)?.[1] ?? '[]';
|
|
188
|
+
const contentStart = start + firstLine.length;
|
|
189
|
+
const contentEnd = findNestedEnd(source, contentStart, FOREACH_RE, ENDFOREACH_RE);
|
|
190
|
+
const endLine = takeLine(source, contentEnd);
|
|
191
|
+
return {
|
|
192
|
+
op: {
|
|
193
|
+
type: 'foreach',
|
|
194
|
+
expression,
|
|
195
|
+
body: parseOps(source.slice(contentStart, contentEnd)),
|
|
196
|
+
},
|
|
197
|
+
end: contentEnd + endLine.length,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function parseSectionBlock(source, start, name) {
|
|
201
|
+
const headerLine = takeLine(source, start);
|
|
202
|
+
const contentStart = start + headerLine.length;
|
|
203
|
+
const contentEnd = findNestedEnd(source, contentStart, SECTION_START_RE, SECTION_END_RE);
|
|
204
|
+
const endLine = takeLine(source, contentEnd);
|
|
205
|
+
return {
|
|
206
|
+
op: {
|
|
207
|
+
type: 'section',
|
|
208
|
+
name,
|
|
209
|
+
body: parseOps(source.slice(contentStart, contentEnd)),
|
|
210
|
+
},
|
|
211
|
+
end: contentEnd + endLine.length,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function findNestedEnd(source, start, openRe, closeRe) {
|
|
215
|
+
let cursor = start;
|
|
216
|
+
let depth = 0;
|
|
217
|
+
while (cursor < source.length) {
|
|
218
|
+
const line = takeLine(source, cursor);
|
|
219
|
+
const trimmed = line.trim();
|
|
220
|
+
if (openRe.test(trimmed)) {
|
|
221
|
+
depth += 1;
|
|
222
|
+
}
|
|
223
|
+
if (closeRe.test(trimmed)) {
|
|
224
|
+
if (depth === 0) {
|
|
225
|
+
return cursor;
|
|
226
|
+
}
|
|
227
|
+
depth -= 1;
|
|
228
|
+
}
|
|
229
|
+
cursor += line.length;
|
|
230
|
+
}
|
|
231
|
+
return source.length;
|
|
232
|
+
}
|
|
233
|
+
function findBlockBoundary(source, start, patterns) {
|
|
234
|
+
let cursor = start;
|
|
235
|
+
while (cursor < source.length) {
|
|
236
|
+
const line = takeLine(source, cursor);
|
|
237
|
+
const trimmed = line.trim();
|
|
238
|
+
if (patterns.some((pattern) => pattern.test(trimmed))) {
|
|
239
|
+
return cursor;
|
|
240
|
+
}
|
|
241
|
+
if (source.slice(cursor).startsWith('{{') || source.slice(cursor).startsWith('{!!')) {
|
|
242
|
+
return cursor;
|
|
243
|
+
}
|
|
244
|
+
cursor += line.length;
|
|
245
|
+
}
|
|
246
|
+
return source.length;
|
|
247
|
+
}
|
|
248
|
+
function findNextSpecial(source, start) {
|
|
249
|
+
const indexes = [
|
|
250
|
+
source.indexOf('{{', start),
|
|
251
|
+
source.indexOf('{!!', start),
|
|
252
|
+
source.indexOf('@', start),
|
|
253
|
+
].filter((index) => index !== -1);
|
|
254
|
+
return indexes.length > 0 ? Math.min(...indexes) : -1;
|
|
255
|
+
}
|
|
256
|
+
function takeLine(source, start) {
|
|
257
|
+
const end = source.indexOf('\n', start);
|
|
258
|
+
if (end === -1) {
|
|
259
|
+
return source.slice(start);
|
|
260
|
+
}
|
|
261
|
+
return source.slice(start, end + 1);
|
|
262
|
+
}
|
|
263
|
+
function appendText(ops, value) {
|
|
264
|
+
if (!value) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
for (const op of parseTextWithDirectives(value)) {
|
|
268
|
+
const last = ops[ops.length - 1];
|
|
269
|
+
if (op.type === 'text' && last?.type === 'text') {
|
|
270
|
+
last.value += op.value;
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
ops.push(op);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function parseTextWithDirectives(text) {
|
|
277
|
+
const ops = [];
|
|
278
|
+
const pattern = /@yield\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]*)['"]\s*)?\)|@include\(\s*['"]([^'"]+)['"]\s*(?:,\s*(.+?))?\s*\)|@component\(\s*['"]([^'"]+)['"]\s*(?:,\s*(.+?))?\s*\)/g;
|
|
279
|
+
let lastIndex = 0;
|
|
280
|
+
let match;
|
|
281
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
282
|
+
if (match.index > lastIndex) {
|
|
283
|
+
ops.push({ type: 'text', value: text.slice(lastIndex, match.index) });
|
|
284
|
+
}
|
|
285
|
+
if (match[0].startsWith('@yield')) {
|
|
286
|
+
ops.push({
|
|
287
|
+
type: 'yield',
|
|
288
|
+
name: match[1],
|
|
289
|
+
defaultValue: match[2],
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
else if (match[0].startsWith('@include')) {
|
|
293
|
+
ops.push({
|
|
294
|
+
type: 'include',
|
|
295
|
+
name: match[3],
|
|
296
|
+
dataExpression: match[4]?.trim(),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
ops.push({
|
|
301
|
+
type: 'component',
|
|
302
|
+
name: match[5],
|
|
303
|
+
dataExpression: match[6]?.trim(),
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
lastIndex = match.index + match[0].length;
|
|
307
|
+
}
|
|
308
|
+
if (lastIndex < text.length) {
|
|
309
|
+
ops.push({ type: 'text', value: text.slice(lastIndex) });
|
|
310
|
+
}
|
|
311
|
+
return ops;
|
|
312
|
+
}
|
|
313
|
+
export function compileInlineEchoes(source) {
|
|
314
|
+
const ops = [];
|
|
315
|
+
let lastIndex = 0;
|
|
316
|
+
const pattern = new RegExp(`${ECHO_RE.source}|${RAW_ECHO_RE.source}`, 'g');
|
|
317
|
+
let match;
|
|
318
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
319
|
+
if (match.index > lastIndex) {
|
|
320
|
+
appendText(ops, source.slice(lastIndex, match.index));
|
|
321
|
+
}
|
|
322
|
+
const raw = match[0].startsWith('{!!');
|
|
323
|
+
const expression = match[1] ?? '';
|
|
324
|
+
ops.push({ type: 'echo', expression, raw });
|
|
325
|
+
lastIndex = match.index + match[0].length;
|
|
326
|
+
}
|
|
327
|
+
if (lastIndex < source.length) {
|
|
328
|
+
appendText(ops, source.slice(lastIndex));
|
|
329
|
+
}
|
|
330
|
+
return ops;
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,yCAAyC,CAAC;AAC5D,MAAM,gBAAgB,GAAG,yCAAyC,CAAC;AACnE,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,QAAQ,GAAG,mEAAmE,CAAC;AACrF,MAAM,UAAU,GAAG,sDAAsD,CAAC;AAC1E,MAAM,YAAY,GAAG,wDAAwD,CAAC;AAC9E,MAAM,KAAK,GAAG,qBAAqB,CAAC;AACpC,MAAM,SAAS,GAAG,yBAAyB,CAAC;AAC5C,MAAM,OAAO,GAAG,YAAY,CAAC;AAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC;AAC/B,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAC9C,MAAM,aAAa,GAAG,kBAAkB,CAAC;AACzC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AACvC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,MAAM,UAAU,OAAO,CAAC,MAAc;IACpC,MAAM,WAAW,GAAG,MAAM,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mB,CAAC,MAAc;IAChD,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3E,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC/C,IAAI,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;YAC5B,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAClC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAC5C,SAAS,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5C,CAAC;IAED,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC9B,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.test.d.ts","sourceRoot":"","sources":["../src/compiler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { compile } from './compiler.js';
|
|
3
|
+
describe('compile', () => {
|
|
4
|
+
it('parses layout, sections, echoes, and control flow', () => {
|
|
5
|
+
const source = `@layout('layouts.app')
|
|
6
|
+
|
|
7
|
+
@section('title')
|
|
8
|
+
Hello {{ name }}
|
|
9
|
+
@endsection
|
|
10
|
+
|
|
11
|
+
@if (show)
|
|
12
|
+
<p>Visible</p>
|
|
13
|
+
@else
|
|
14
|
+
<p>Hidden</p>
|
|
15
|
+
@endif
|
|
16
|
+
|
|
17
|
+
@foreach (users as user)
|
|
18
|
+
<span>{{ user }}</span>
|
|
19
|
+
@endforeach
|
|
20
|
+
`;
|
|
21
|
+
const template = compile(source);
|
|
22
|
+
expect(template.layout).toBe('layouts.app');
|
|
23
|
+
expect(template.ops.some((op) => op.type === 'section' && op.name === 'title')).toBe(true);
|
|
24
|
+
expect(template.ops.some((op) => op.type === 'if')).toBe(true);
|
|
25
|
+
expect(template.ops.some((op) => op.type === 'foreach')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('parses include, component, and yield directives', () => {
|
|
28
|
+
const source = `@yield('content', 'fallback')
|
|
29
|
+
@include('partials.header', { title: 'Home' })
|
|
30
|
+
@component('components.alert', { message: 'Hi' })
|
|
31
|
+
`;
|
|
32
|
+
const template = compile(source);
|
|
33
|
+
expect(template.ops).toEqual([
|
|
34
|
+
{ type: 'yield', name: 'content', defaultValue: 'fallback' },
|
|
35
|
+
{ type: 'include', name: 'partials.header', dataExpression: '{ title: \'Home\' }' },
|
|
36
|
+
{ type: 'component', name: 'components.alert', dataExpression: '{ message: \'Hi\' }' },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=compiler.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.test.js","sourceRoot":"","sources":["../src/compiler.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,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E,qBAAqB,EAAE;YACnF,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE;SACvF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/escape.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../src/escape.ts"],"names":[],"mappings":"AAQA,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMjD"}
|
package/dist/escape.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const ESCAPE_MAP = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
"'": ''',
|
|
7
|
+
};
|
|
8
|
+
export function escapeHtml(value) {
|
|
9
|
+
if (value === null || value === undefined) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return String(value).replace(/[&<>"']/g, (char) => ESCAPE_MAP[char] ?? char);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../src/escape.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAA2B;IACzC,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;CACb,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ViewContext } from './types.js';
|
|
2
|
+
export declare function evaluateExpression(expression: string, context: ViewContext): unknown;
|
|
3
|
+
export declare function parseForeachExpression(expression: string): {
|
|
4
|
+
itemsExpression: string;
|
|
5
|
+
valueName: string;
|
|
6
|
+
keyName?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAepF;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CA6BP"}
|
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function evaluateExpression(expression, context) {
|
|
2
|
+
const trimmed = expression.trim();
|
|
3
|
+
if (!trimmed) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
const keys = Object.keys(context);
|
|
7
|
+
const values = Object.values(context);
|
|
8
|
+
try {
|
|
9
|
+
const evaluator = Function(...keys, `"use strict"; return (${trimmed});`);
|
|
10
|
+
return evaluator(...values);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function parseForeachExpression(expression) {
|
|
17
|
+
const trimmed = expression.trim();
|
|
18
|
+
const ofMatch = trimmed.match(/^(\w+)\s+of\s+(.+)$/);
|
|
19
|
+
if (ofMatch) {
|
|
20
|
+
return {
|
|
21
|
+
valueName: ofMatch[1],
|
|
22
|
+
itemsExpression: ofMatch[2].trim(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const asMatch = trimmed.match(/^(.+?)\s+as\s+(\w+)$/);
|
|
26
|
+
if (asMatch) {
|
|
27
|
+
return {
|
|
28
|
+
itemsExpression: asMatch[1].trim(),
|
|
29
|
+
valueName: asMatch[2],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const keyedMatch = trimmed.match(/^(.+?)\s+as\s+(\w+)\s*=>\s*(\w+)$/);
|
|
33
|
+
if (keyedMatch) {
|
|
34
|
+
return {
|
|
35
|
+
itemsExpression: keyedMatch[1].trim(),
|
|
36
|
+
keyName: keyedMatch[2],
|
|
37
|
+
valueName: keyedMatch[3],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=evaluate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,OAAoB;IACzE,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEtC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,IAAI,EAAE,yBAAyB,OAAO,IAAI,CAAC,CAAC;QAC1E,OAAO,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IAKvD,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAElC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACrD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO;YACL,SAAS,EAAE,OAAO,CAAC,CAAC,CAAE;YACtB,eAAe,EAAE,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE;SACpC,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACtD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO;YACL,eAAe,EAAE,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE;YACnC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAE;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACtE,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,eAAe,EAAE,UAAU,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE;YACtC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAE;YACvB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAE;SAC1B,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { compile } from './compiler.js';
|
|
2
|
+
export { escapeHtml } from './escape.js';
|
|
3
|
+
export { evaluateExpression } from './evaluate.js';
|
|
4
|
+
export { ViewEngine } from './view-engine.js';
|
|
5
|
+
export type { CompiledTemplate, TemplateOp, ViewConfig, ViewContext, } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TemplateOp, ViewContext } from './types.js';
|
|
2
|
+
import type { ViewEngine } from './view-engine.js';
|
|
3
|
+
import { ViewHelpers } from './view-helpers.js';
|
|
4
|
+
export declare function renderOps(ops: TemplateOp[], context: ViewContext, helpers: ViewHelpers, engine: ViewEngine): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,wBAAsB,SAAS,CAC7B,GAAG,EAAE,UAAU,EAAE,EACjB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,IAAI,CAAC,CA2Ef"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { escapeHtml } from './escape.js';
|
|
2
|
+
import { evaluateExpression, parseForeachExpression } from './evaluate.js';
|
|
3
|
+
import { ViewHelpers } from './view-helpers.js';
|
|
4
|
+
export async function renderOps(ops, context, helpers, engine) {
|
|
5
|
+
for (const op of ops) {
|
|
6
|
+
switch (op.type) {
|
|
7
|
+
case 'text':
|
|
8
|
+
helpers.append(op.value);
|
|
9
|
+
break;
|
|
10
|
+
case 'echo': {
|
|
11
|
+
const value = evaluateExpression(op.expression, context);
|
|
12
|
+
helpers.append(op.raw ? String(value ?? '') : escapeHtml(value));
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
case 'if': {
|
|
16
|
+
const result = Boolean(evaluateExpression(op.expression, context));
|
|
17
|
+
if (result) {
|
|
18
|
+
await renderOps(op.body, context, helpers, engine);
|
|
19
|
+
}
|
|
20
|
+
else if (op.elseBody) {
|
|
21
|
+
await renderOps(op.elseBody, context, helpers, engine);
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case 'foreach': {
|
|
26
|
+
const parsed = parseForeachExpression(op.expression);
|
|
27
|
+
if (!parsed) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
const items = evaluateExpression(parsed.itemsExpression, context);
|
|
31
|
+
if (!items || typeof items !== 'object') {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const iterable = Array.isArray(items)
|
|
35
|
+
? items.entries()
|
|
36
|
+
: Object.entries(items);
|
|
37
|
+
for (const [key, value] of iterable) {
|
|
38
|
+
const loopContext = {
|
|
39
|
+
...context,
|
|
40
|
+
[parsed.valueName]: value,
|
|
41
|
+
};
|
|
42
|
+
if (parsed.keyName) {
|
|
43
|
+
loopContext[parsed.keyName] = key;
|
|
44
|
+
}
|
|
45
|
+
await renderOps(op.body, loopContext, helpers, engine);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'section': {
|
|
50
|
+
const sectionHelpers = new ViewHelpers();
|
|
51
|
+
await renderOps(op.body, context, sectionHelpers, engine);
|
|
52
|
+
helpers.setSection(op.name, sectionHelpers.toString());
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 'yield':
|
|
56
|
+
helpers.append(helpers.yield(op.name, op.defaultValue ?? ''));
|
|
57
|
+
break;
|
|
58
|
+
case 'include':
|
|
59
|
+
case 'component': {
|
|
60
|
+
const data = op.dataExpression
|
|
61
|
+
? evaluateExpression(op.dataExpression, context)
|
|
62
|
+
: context;
|
|
63
|
+
const html = await engine.render(op.name, data, helpers.getSections());
|
|
64
|
+
helpers.append(html);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAiB,EACjB,OAAoB,EACpB,OAAoB,EACpB,MAAkB;IAElB,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,MAAM;gBACT,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;gBACzB,MAAM;YAER,KAAK,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C,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type ViewContext = Record<string, unknown>;
|
|
2
|
+
export interface ViewConfig {
|
|
3
|
+
path: string;
|
|
4
|
+
extension?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface CompiledTemplate {
|
|
7
|
+
layout?: string;
|
|
8
|
+
ops: TemplateOp[];
|
|
9
|
+
}
|
|
10
|
+
export type TemplateOp = {
|
|
11
|
+
type: 'text';
|
|
12
|
+
value: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'echo';
|
|
15
|
+
expression: string;
|
|
16
|
+
raw: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'if';
|
|
19
|
+
expression: string;
|
|
20
|
+
body: TemplateOp[];
|
|
21
|
+
elseBody?: TemplateOp[];
|
|
22
|
+
} | {
|
|
23
|
+
type: 'foreach';
|
|
24
|
+
expression: string;
|
|
25
|
+
body: TemplateOp[];
|
|
26
|
+
} | {
|
|
27
|
+
type: 'section';
|
|
28
|
+
name: string;
|
|
29
|
+
body: TemplateOp[];
|
|
30
|
+
} | {
|
|
31
|
+
type: 'yield';
|
|
32
|
+
name: string;
|
|
33
|
+
defaultValue?: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'include';
|
|
36
|
+
name: string;
|
|
37
|
+
dataExpression?: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'component';
|
|
40
|
+
name: string;
|
|
41
|
+
dataExpression?: string;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,MAAM,W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
1
|
+
import type { ViewConfig, ViewContext } from './types.js';
|
|
2
|
+
export declare class ViewEngine {
|
|
3
|
+
private readonly basePath;
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly cache;
|
|
6
|
+
private readonly extension;
|
|
7
|
+
constructor(basePath: string, config: ViewConfig);
|
|
8
|
+
render(name: string, context?: ViewContext, parentSections?: ReadonlyMap<string, string>): Promise<string>;
|
|
9
|
+
exists(name: string): boolean;
|
|
10
|
+
private loadTemplate;
|
|
11
|
+
private resolvePath;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=view-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-engine.d.ts","sourceRoot":"","sources":["../src/view-engine.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQ5E,qBAAa,UAAU;IAKnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAGhB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU;IAK/B,MAAM,CACV,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,EACzB,cAAc,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,MAAM,CAAC;IAyBlB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,WAAW;CAIpB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { compile } from './compiler.js';
|
|
4
|
+
import { renderOps } from './renderer.js';
|
|
5
|
+
import { ViewHelpers } from './view-helpers.js';
|
|
6
|
+
export class ViewEngine {
|
|
7
|
+
basePath;
|
|
8
|
+
config;
|
|
9
|
+
cache = new Map();
|
|
10
|
+
extension;
|
|
11
|
+
constructor(basePath, config) {
|
|
12
|
+
this.basePath = basePath;
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.extension = config.extension ?? '.tyr';
|
|
15
|
+
}
|
|
16
|
+
async render(name, context = {}, parentSections) {
|
|
17
|
+
const template = this.loadTemplate(name);
|
|
18
|
+
const helpers = new ViewHelpers();
|
|
19
|
+
if (parentSections) {
|
|
20
|
+
helpers.importSections(parentSections);
|
|
21
|
+
}
|
|
22
|
+
await renderOps(template.ops, context, helpers, this);
|
|
23
|
+
if (template.layout) {
|
|
24
|
+
const layoutHelpers = new ViewHelpers();
|
|
25
|
+
layoutHelpers.importSections(helpers.getSections());
|
|
26
|
+
await renderOps(this.loadTemplate(template.layout).ops, context, layoutHelpers, this);
|
|
27
|
+
return layoutHelpers.toString();
|
|
28
|
+
}
|
|
29
|
+
return helpers.toString();
|
|
30
|
+
}
|
|
31
|
+
exists(name) {
|
|
32
|
+
try {
|
|
33
|
+
this.resolvePath(name);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
loadTemplate(name) {
|
|
41
|
+
const path = this.resolvePath(name);
|
|
42
|
+
const stats = statSync(path);
|
|
43
|
+
const cached = this.cache.get(path);
|
|
44
|
+
if (cached && cached.mtimeMs === stats.mtimeMs) {
|
|
45
|
+
return cached.template;
|
|
46
|
+
}
|
|
47
|
+
const source = readFileSync(path, 'utf8');
|
|
48
|
+
const template = compile(source);
|
|
49
|
+
this.cache.set(path, { mtimeMs: stats.mtimeMs, template });
|
|
50
|
+
return template;
|
|
51
|
+
}
|
|
52
|
+
resolvePath(name) {
|
|
53
|
+
const relative = name.replace(/\./g, '/');
|
|
54
|
+
return join(this.basePath, this.config.path, `${relative}${this.extension}`);
|
|
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E,GAAG,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-engine.test.d.ts","sourceRoot":"","sources":["../src/view-engine.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { ViewEngine } from './view-engine.js';
|
|
6
|
+
function createFixture() {
|
|
7
|
+
const basePath = join(tmpdir(), `tyravel-views-${Date.now()}-${Math.random()}`);
|
|
8
|
+
const viewsPath = join(basePath, 'resources/views');
|
|
9
|
+
mkdirSync(join(viewsPath, 'layouts'), { recursive: true });
|
|
10
|
+
mkdirSync(join(viewsPath, 'components'), { recursive: true });
|
|
11
|
+
writeFileSync(join(viewsPath, 'layouts/app.tyr'), `<!DOCTYPE html>
|
|
12
|
+
<html>
|
|
13
|
+
<head><title>@yield('title', 'Tyravel')</title></head>
|
|
14
|
+
<body>
|
|
15
|
+
@yield('content')
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
18
|
+
`);
|
|
19
|
+
writeFileSync(join(viewsPath, 'welcome.tyr'), `@layout('layouts.app')
|
|
20
|
+
|
|
21
|
+
@section('title')
|
|
22
|
+
Welcome
|
|
23
|
+
@endsection
|
|
24
|
+
|
|
25
|
+
@section('content')
|
|
26
|
+
<h1>Hello {{ name }}</h1>
|
|
27
|
+
@if (showDetails)
|
|
28
|
+
<p>Users: {{ users.length }}</p>
|
|
29
|
+
@endif
|
|
30
|
+
<ul>
|
|
31
|
+
@foreach (users as user)
|
|
32
|
+
<li>{{ user }}</li>
|
|
33
|
+
@endforeach
|
|
34
|
+
</ul>
|
|
35
|
+
@component('components.alert', { message: greeting })
|
|
36
|
+
@endsection
|
|
37
|
+
`);
|
|
38
|
+
writeFileSync(join(viewsPath, 'components/alert.tyr'), `<div class="alert">{{ message }}</div>`);
|
|
39
|
+
const engine = new ViewEngine(basePath, { path: 'resources/views' });
|
|
40
|
+
return { basePath, engine };
|
|
41
|
+
}
|
|
42
|
+
describe('ViewEngine', () => {
|
|
43
|
+
it('renders layouts, sections, control flow, and components', async () => {
|
|
44
|
+
const { engine } = createFixture();
|
|
45
|
+
const html = await engine.render('welcome', {
|
|
46
|
+
name: 'Ada',
|
|
47
|
+
showDetails: true,
|
|
48
|
+
users: ['Grace', 'Alan'],
|
|
49
|
+
greeting: 'Welcome back',
|
|
50
|
+
});
|
|
51
|
+
expect(html).toMatch(/<title>\s*Welcome\s*<\/title>/);
|
|
52
|
+
expect(html).toContain('<h1>Hello Ada</h1>');
|
|
53
|
+
expect(html).toContain('<p>Users: 2</p>');
|
|
54
|
+
expect(html).toContain('<li>Grace</li>');
|
|
55
|
+
expect(html).toContain('<div class="alert">Welcome back</div>');
|
|
56
|
+
});
|
|
57
|
+
it('escapes echoed values by default', async () => {
|
|
58
|
+
const { basePath, engine } = createFixture();
|
|
59
|
+
writeFileSync(join(basePath, 'resources/views/unsafe.tyr'), `<p>{{ payload }}</p>`);
|
|
60
|
+
const html = await engine.render('unsafe', {
|
|
61
|
+
payload: '<script>alert(1)</script>',
|
|
62
|
+
});
|
|
63
|
+
expect(html).toContain('<script>');
|
|
64
|
+
expect(html).not.toContain('<script>');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=view-engine.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-engine.test.js","sourceRoot":"","sources":["../src/view-engine.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC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,EAAE,IAAI;YACjB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;YACxB,QAAQ,EAAE,cAAc;SACzB,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAChD,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;QAC7C,aAAa,CACX,IAAI,CAAC,QAAQ,EAAE,4BAA4B,CAAC,EAC5C,sBAAsB,CACvB,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;YACzC,OAAO,EAAE,2BAA2B;SACrC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ViewHelpers {
|
|
2
|
+
private readonly sections;
|
|
3
|
+
private output;
|
|
4
|
+
append(value: string): void;
|
|
5
|
+
setSection(name: string, content: string): void;
|
|
6
|
+
importSections(sections: ReadonlyMap<string, string>): void;
|
|
7
|
+
yield(name: string, defaultValue?: string): string;
|
|
8
|
+
getSections(): ReadonlyMap<string, string>;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=view-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-helpers.d.ts","sourceRoot":"","sources":["../src/view-helpers.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,MAAM,CAAM;IAEpB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI/C,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAM3D,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,SAAK,GAAG,MAAM;IAI9C,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;IAI1C,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class ViewHelpers {
|
|
2
|
+
sections = new Map();
|
|
3
|
+
output = '';
|
|
4
|
+
append(value) {
|
|
5
|
+
this.output += value;
|
|
6
|
+
}
|
|
7
|
+
setSection(name, content) {
|
|
8
|
+
this.sections.set(name, content);
|
|
9
|
+
}
|
|
10
|
+
importSections(sections) {
|
|
11
|
+
for (const [name, content] of sections) {
|
|
12
|
+
this.sections.set(name, content);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
yield(name, defaultValue = '') {
|
|
16
|
+
return this.sections.get(name) ?? defaultValue;
|
|
17
|
+
}
|
|
18
|
+
getSections() {
|
|
19
|
+
return this.sections;
|
|
20
|
+
}
|
|
21
|
+
toString() {
|
|
22
|
+
return this.output;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=view-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-helpers.js","sourceRoot":"","sources":["../src/view-helpers.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IACL,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,MAAM,GAAG,EAAE,CAAC;IAEpB,MAAM,CAAC,KAAa;QAClB,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;IACvB,CAAC;IAED,UAAU,CAAC,IAAY,EAAE,OAAe;QACtC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,cAAc,CAAC,QAAqC;QAClD,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,YAAY,GAAG,EAAE;QACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC;IACjD,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tyravel/views",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.json",
|
|
15
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"description": "Blade-like view engine for Tyravel",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/thesimonharms/tyravel.git",
|
|
25
|
+
"directory": "packages/views"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22"
|
|
32
|
+
}
|
|
33
|
+
}
|