mikel 0.27.0 → 0.27.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/README.md +9 -2
- package/index.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,6 +112,13 @@ const result = m("{{> hello}}", data, {partials});
|
|
|
112
112
|
// Output: 'Hello Bob!'
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
Partial metadata can be accessed using the `@partial` variable inside the partial. It contains the following fields:
|
|
116
|
+
|
|
117
|
+
- `name`: the name of the partial being rendered.
|
|
118
|
+
- `args`: an array containing the positional arguments provided to the partial (if any). See the **Custom context in partials** section for more details.
|
|
119
|
+
- `opt`: an object containing the keyword arguments provided to the partial (if any). See the **Keyword arguments in partials** section for more details.
|
|
120
|
+
- `attributes`: the custom data provided to the partial (if any). See the **Partials data** section for more details.
|
|
121
|
+
|
|
115
122
|
#### Custom context in partials
|
|
116
123
|
|
|
117
124
|
> This feature was added in `v0.3.1`.
|
|
@@ -205,7 +212,7 @@ Partials allows you to define custom data. Instead of providing a string with th
|
|
|
205
212
|
- `body`: a string with the partial content.
|
|
206
213
|
- `data`: an object with your custom data for the partial. You can also use `attributes` as an alias.
|
|
207
214
|
|
|
208
|
-
Custom data will be available in the partial content
|
|
215
|
+
Custom data will be available in the partial content in the `@partial.attributes` variable.
|
|
209
216
|
|
|
210
217
|
Example:
|
|
211
218
|
|
|
@@ -213,7 +220,7 @@ Example:
|
|
|
213
220
|
const options = {
|
|
214
221
|
partials: {
|
|
215
222
|
foo: {
|
|
216
|
-
body: "Hello {{@partial.name}}!",
|
|
223
|
+
body: "Hello {{@partial.attributes.name}}!",
|
|
217
224
|
data: {
|
|
218
225
|
name: "Bob",
|
|
219
226
|
},
|
package/index.js
CHANGED
|
@@ -146,7 +146,12 @@ const create = (options = {}) => {
|
|
|
146
146
|
const newVars = {
|
|
147
147
|
...vars,
|
|
148
148
|
content: blockContent.join(""),
|
|
149
|
-
partial:
|
|
149
|
+
partial: {
|
|
150
|
+
name: t,
|
|
151
|
+
attributes: ctx.partials[t]?.attributes || ctx.partials[t]?.data || {},
|
|
152
|
+
args: args || [],
|
|
153
|
+
opt: opt || {},
|
|
154
|
+
},
|
|
150
155
|
};
|
|
151
156
|
compile(tokenize(ctx.partials[t]?.body || ctx.partials[t]), output, newData, newVars, 0, "");
|
|
152
157
|
}
|