mikel 0.17.1 → 0.18.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 +29 -0
- package/index.js +7 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -161,6 +161,35 @@ const result = m("{{>>foo}}Bob{{/foo}}", {}, options);
|
|
|
161
161
|
// Output: 'Hello Bob!'
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
+
#### Partials data
|
|
165
|
+
|
|
166
|
+
> This feature was added in `v0.18.0`.
|
|
167
|
+
|
|
168
|
+
Partials allows you to define custom data. Instead of providing a string with the partial content, you can provide an object with the following keys:
|
|
169
|
+
|
|
170
|
+
- `body`: a string with the partial content.
|
|
171
|
+
- `data`: an object with your custom data for the partial. You can also use `attributes` as an alias.
|
|
172
|
+
|
|
173
|
+
Custom data will be available in the partial content as a variable `@partial`.
|
|
174
|
+
|
|
175
|
+
Example:
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
const options = {
|
|
179
|
+
partials: {
|
|
180
|
+
foo: {
|
|
181
|
+
body: "Hello {{@partial.name}}!",
|
|
182
|
+
data: {
|
|
183
|
+
name: "Bob",
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const result = m("{{> foo}}", {}, options);
|
|
190
|
+
// Output: 'Hello Bob!'
|
|
191
|
+
```
|
|
192
|
+
|
|
164
193
|
### Inline partials
|
|
165
194
|
|
|
166
195
|
> This feature was added in `v0.16.0`.
|
package/index.js
CHANGED
|
@@ -112,10 +112,14 @@ const create = (template = "", options = {}) => {
|
|
|
112
112
|
if (tokens[i].startsWith(">>")) {
|
|
113
113
|
i = compile(tokens, blockContent, context, vars, i + 1, t);
|
|
114
114
|
}
|
|
115
|
-
if (typeof partials[t] === "string") {
|
|
115
|
+
if (typeof partials[t] === "string" || typeof partials[t]?.body === "string") {
|
|
116
116
|
const newCtx = args.length > 0 ? args[0] : (Object.keys(opt).length > 0 ? opt : context);
|
|
117
|
-
const newVars = {
|
|
118
|
-
|
|
117
|
+
const newVars = {
|
|
118
|
+
...vars,
|
|
119
|
+
content: blockContent.join(""),
|
|
120
|
+
partial: partials[t]?.attributes || partials[t]?.data || {},
|
|
121
|
+
};
|
|
122
|
+
compile(tokenize(partials[t]?.body || partials[t]), output, newCtx, newVars, 0, "");
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
else if (tokens[i].startsWith("=")) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mikel",
|
|
3
3
|
"description": "Micro templating library with zero dependencies",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Josemi Juanes",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"./package.json": "./package.json"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
+
"release": "node ./scripts/release.js",
|
|
21
22
|
"test": "node test.js"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|