@ynode/squirrellyify 1.5.1 → 1.5.2
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 +20 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025 Michael Welter <me@mikinho.com>
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@ynode/squirrellyify)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.npmjs.com/package/@ynode/squirrellyify) [](https://opensource.org/licenses/MIT)
|
|
7
6
|
|
|
8
|
-
A simple and fast plugin for using the [Squirrelly](https://squirrelly.js.org/) template engine with
|
|
9
|
-
[Fastify](https://www.fastify.io/).
|
|
7
|
+
A simple and fast plugin for using the [Squirrelly](https://squirrelly.js.org/) template engine with [Fastify](https://www.fastify.io/).
|
|
10
8
|
|
|
11
9
|
## Features
|
|
12
10
|
|
|
@@ -76,8 +74,7 @@ fastify.listen({ port: 3000 }, (err) => {
|
|
|
76
74
|
|
|
77
75
|
### Request-Scoped View Data
|
|
78
76
|
|
|
79
|
-
`reply.view(template, data)` automatically merges request-scoped values from `reply.locals` and `reply.context` into the
|
|
80
|
-
template data:
|
|
77
|
+
`reply.view(template, data)` automatically merges request-scoped values from `reply.locals` and `reply.context` into the template data:
|
|
81
78
|
|
|
82
79
|
```javascript
|
|
83
80
|
fastify.addHook("preHandler", async (request, reply) => {
|
|
@@ -100,23 +97,22 @@ Merge precedence is:
|
|
|
100
97
|
|
|
101
98
|
You can pass an options object when registering the plugin.
|
|
102
99
|
|
|
103
|
-
| Option
|
|
104
|
-
|
|
|
105
|
-
| `templates`
|
|
106
|
-
| `partials`
|
|
107
|
-
| `partialsRecursive` | `boolean`
|
|
108
|
-
| `partialsNamespace` | `boolean \| string`
|
|
109
|
-
| `layout`
|
|
110
|
-
| `defaultExtension`
|
|
111
|
-
| `cache`
|
|
112
|
-
| `sqrl`
|
|
100
|
+
| Option | Type | Default | Description |
|
|
101
|
+
| --- | --- | --- | --- |
|
|
102
|
+
| `templates` | `string \| string[]` | `path.join(process.cwd(), "views")` | The directory or directories to search for page and layout templates. Searched in the provided order. |
|
|
103
|
+
| `partials` | `string \| string[]` | `[]` | The directory or directories for partial templates. All partials are loaded on startup and available by name. |
|
|
104
|
+
| `partialsRecursive` | `boolean` | `true` | If `true`, partials are loaded recursively from subdirectories. Names use forward slashes (for example, `emails/header`). |
|
|
105
|
+
| `partialsNamespace` | `boolean \| string` | `false` | Optional namespace prefix for partial names. Use `true` to prefix with each partials directory basename, or provide a custom string. |
|
|
106
|
+
| `layout` | `string` | `undefined` | The name of the default layout file to use (without extension). Can be overridden per-route. |
|
|
107
|
+
| `defaultExtension` | `string` | `"sqrl"` | The file extension for all template files. Leading `.` is optional (for example, `"html"` or `".html"`). |
|
|
108
|
+
| `cache` | `boolean` | `NODE_ENV === "production"` | If `true`, compiled templates and resolved file paths will be cached in memory. |
|
|
109
|
+
| `sqrl` | `object` | `undefined` | Squirrelly options. Supports `{ scope: "global" \| "scoped", config, helpers, filters }`. |
|
|
113
110
|
|
|
114
111
|
Runtime API after registration:
|
|
115
112
|
|
|
116
113
|
- `fastify.viewHelpers.define(name, fn)`, `fastify.viewHelpers.get(name)`, `fastify.viewHelpers.remove(name)`
|
|
117
114
|
- `fastify.viewFilters.define(name, fn)`, `fastify.viewFilters.get(name)`, `fastify.viewFilters.remove(name)`
|
|
118
|
-
- `fastify.viewPartials.define(name, templateOrFn)`, `fastify.viewPartials.get(name)`,
|
|
119
|
-
`fastify.viewPartials.remove(name)`
|
|
115
|
+
- `fastify.viewPartials.define(name, templateOrFn)`, `fastify.viewPartials.get(name)`, `fastify.viewPartials.remove(name)`
|
|
120
116
|
- `fastify.viewCache.clear()`, `fastify.viewCache.stats()`
|
|
121
117
|
|
|
122
118
|
These APIs are scope-aware:
|
|
@@ -124,8 +120,7 @@ These APIs are scope-aware:
|
|
|
124
120
|
- In `global` mode they modify shared helpers/filters/partials.
|
|
125
121
|
- In `scoped` mode they only affect the current plugin registration scope.
|
|
126
122
|
|
|
127
|
-
The cache API is process-local and lets you invalidate compiled template/path caches at runtime when `cache: true` is
|
|
128
|
-
used.
|
|
123
|
+
The cache API is process-local and lets you invalidate compiled template/path caches at runtime when `cache: true` is used.
|
|
129
124
|
|
|
130
125
|
Invalid option types are rejected at plugin registration time with descriptive errors.
|
|
131
126
|
|
|
@@ -133,8 +128,7 @@ Invalid option types are rejected at plugin registration time with descriptive e
|
|
|
133
128
|
|
|
134
129
|
### Layouts
|
|
135
130
|
|
|
136
|
-
Layouts are wrappers for your page templates. The rendered page content is injected into the `body` variable within the
|
|
137
|
-
layout.
|
|
131
|
+
Layouts are wrappers for your page templates. The rendered page content is injected into the `body` variable within the layout.
|
|
138
132
|
|
|
139
133
|
**`views/layouts/main.sqrl`**
|
|
140
134
|
|
|
@@ -147,8 +141,8 @@ layout.
|
|
|
147
141
|
<body>
|
|
148
142
|
<header>My Awesome Site</header>
|
|
149
143
|
<main>
|
|
150
|
-
{{@block("content")}} {{@try}} {{it.body | safe}} {{#catch => err}} Uh-oh, error!
|
|
151
|
-
'{{err.message}}' {{/try}} {{/block}}
|
|
144
|
+
{{@block("content")}} {{@try}} {{it.body | safe}} {{#catch => err}} Uh-oh, error!
|
|
145
|
+
Message was '{{err.message}}' {{/try}} {{/block}}
|
|
152
146
|
</main>
|
|
153
147
|
</body>
|
|
154
148
|
</html>
|
|
@@ -192,8 +186,7 @@ You can specify a layout in three ways (in order of precedence):
|
|
|
192
186
|
|
|
193
187
|
### Partials
|
|
194
188
|
|
|
195
|
-
Partials are reusable chunks of template code. Create a `partials` directory and place your files there. By default,
|
|
196
|
-
partials are loaded recursively and registered by forward-slash path from the partials directory root.
|
|
189
|
+
Partials are reusable chunks of template code. Create a `partials` directory and place your files there. By default, partials are loaded recursively and registered by forward-slash path from the partials directory root.
|
|
197
190
|
|
|
198
191
|
**`partials/user-card.sqrl`**
|
|
199
192
|
|
|
@@ -258,8 +251,7 @@ fastify.register(squirrellyify, {
|
|
|
258
251
|
|
|
259
252
|
### Scoped Configuration (Encapsulation)
|
|
260
253
|
|
|
261
|
-
This plugin supports Fastify's encapsulation model. You can register it multiple times with different settings for
|
|
262
|
-
different route prefixes.
|
|
254
|
+
This plugin supports Fastify's encapsulation model. You can register it multiple times with different settings for different route prefixes.
|
|
263
255
|
|
|
264
256
|
```javascript
|
|
265
257
|
import Fastify from "fastify";
|
|
@@ -331,4 +323,3 @@ fastify.register(squirrellyify, {
|
|
|
331
323
|
## License
|
|
332
324
|
|
|
333
325
|
This project is licensed under the [MIT License](./LICENSE).
|
|
334
|
-
|