@orkestrel/template 0.0.17 → 0.0.19

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 CHANGED
@@ -1,14 +1,17 @@
1
1
  # @orkestrel/template
2
2
 
3
- > A named, versionable template layer: `{{name}}` tokens in a `content`
4
- > string, resolved against a values record by a single-pass fill engine, and
5
- > registered and looked up by id through a self-owning `TemplateManager`.
6
-
7
- Declare a template with the `createTemplate` function, fill it against the
8
- values record your caller supplies, and register it in a `TemplateManager`
9
- where several templates are looked up by id. Reach for `validate` where you
10
- need to know which placeholders a fill would reject before you run it. Part of
11
- the `@orkestrel` line.
3
+ > A template registry, single-pass `{{name}}` filler, and compiled Jinja
4
+ > `TemplateTree` compiler, evaluator, canonical renderer, and safe AST
5
+ > projector into `@orkestrel/html` and `@orkestrel/markdown`.
6
+
7
+ Declare single-pass templates with `createTemplate` and manage collections by id
8
+ through `createTemplateManager`, or compile Jinja chat templates into an
9
+ immutable `TemplateTree` AST with `createTemplateTree` to evaluate values,
10
+ round-trip canonical source through `renderTemplate`, and project safely into
11
+ `@orkestrel/html` and `@orkestrel/markdown` (`templateToHTML`,
12
+ `templateToMarkdown`). Reach for `validate` where you need to know which
13
+ placeholders a single-pass fill would reject before you run it. Part of the
14
+ `@orkestrel` line.
12
15
 
13
16
  ## Install
14
17
 
@@ -18,19 +21,30 @@ npm install @orkestrel/template
18
21
 
19
22
  ## Requirements
20
23
 
21
- - Node.js >= 22.12.0
22
- - Runtime dependencies `@orkestrel/contract` and `@orkestrel/emitter`
24
+ - Node.js >= 22.18.0
25
+ - Runtime dependencies `@orkestrel/contract`, `@orkestrel/emitter`, `@orkestrel/html`, and `@orkestrel/markdown`
23
26
 
24
27
  ## Usage
25
28
 
26
29
  ```ts
27
- import { createTemplate, createTemplateManager } from '@orkestrel/template'
30
+ import {
31
+ createTemplate,
32
+ createTemplateManager,
33
+ createTemplateTree,
34
+ templateToHTML,
35
+ templateToMarkdown,
36
+ } from '@orkestrel/template'
28
37
 
29
38
  const greeting = createTemplate({ name: 'greeting', content: 'Hi {{name}}' })
30
39
  greeting.fill({ name: 'Ada' }) // 'Hi Ada'
31
40
 
32
41
  const templates = createTemplateManager({ templates: [greeting] })
33
42
  templates.fill(greeting.id, { name: 'Grace' }) // 'Hi Grace'
43
+
44
+ const tree = createTemplateTree({ source: '{% for user in users %}Hello {{ user }}!{% endfor %}' })
45
+ tree.evaluate({ users: ['Ada'] }) // 'Hello Ada!'
46
+ templateToHTML('Hi {{ user }}', { user: 'Ada' })
47
+ templateToMarkdown('# Hi {{ user }}', { user: 'Ada' })
34
48
  ```
35
49
 
36
50
  An unresolved required placeholder is governed by `TemplateFillOptions.missing`,