mikel 0.12.0 → 0.13.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.
Files changed (3) hide show
  1. package/README.md +21 -0
  2. package/index.js +3 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -110,6 +110,27 @@ const result = m("User: {{> user currentUser}}", data, {partials});
110
110
  // Output: 'User: John Doe <john@example.com>'
111
111
  ```
112
112
 
113
+ #### Keyword arguments in partials
114
+
115
+ > This feature was added in `v0.13.0`.
116
+
117
+ You can provide keyword arguments in partials to generate a new context object using the provided keywords.
118
+
119
+ ```javascript
120
+ const data = {
121
+ name: "John Doe",
122
+ email: "john@example.com",
123
+ };
124
+ const partials = {
125
+ user: "{{userName}} <{{userEmail}}>",
126
+ };
127
+
128
+ const result = m("User: {{>user userName=name userEmail=email }}", data, {partials});
129
+ // Output: 'User: John Doe <john@example.com>'
130
+ ```
131
+
132
+ Please note that providing keyword arguments and a custom context to a partial is not supported. On this situation, the partial will be evaluated only with the custom context.
133
+
113
134
  ### Built-in helpers
114
135
 
115
136
  > Added in `v0.4.0`.
package/index.js CHANGED
@@ -110,9 +110,10 @@ const create = (template = "", options = {}) => {
110
110
  }
111
111
  }
112
112
  else if (tokens[i].startsWith(">")) {
113
- const [t, v] = tokens[i].slice(1).trim().split(" ");
113
+ const [t, args, opt] = parseArgs(tokens[i].slice(1), context, vars);
114
114
  if (typeof partials[t] === "string") {
115
- compile(partials[t].split(tags), output, v ? get(context, v) : context, vars, 0, "");
115
+ const newCtx = args.length > 0 ? args[0] : (Object.keys(opt).length > 0 ? opt : context);
116
+ compile(partials[t].split(tags), output, newCtx, vars, 0, "");
116
117
  }
117
118
  }
118
119
  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.12.0",
4
+ "version": "0.13.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Josemi Juanes",