mikel 0.21.0 → 0.22.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 +3 -2
- package/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -391,7 +391,7 @@ Custom helper functions receive a single object as argument, containing the foll
|
|
|
391
391
|
- `args`: an array containing the variables with the helper is called in the template.
|
|
392
392
|
- `opt`: an object containing the keyword arguments provided to the helper.
|
|
393
393
|
- `data`: the current data where the helper has been executed.
|
|
394
|
-
- `
|
|
394
|
+
- `variables`: an object containing the runtime variables available in the current context (e.g., `@root`, `@index`, etc.).
|
|
395
395
|
- `fn`: a function that executes the template provided in the helper block and returns a string with the evaluated template in the provided context.
|
|
396
396
|
|
|
397
397
|
The helper function must return a string, which will be injected into the result string. Example:
|
|
@@ -508,7 +508,8 @@ Functions will receive a single object as argument, containing the following key
|
|
|
508
508
|
|
|
509
509
|
- `args`: an array containing the variables with the function is called in the template.
|
|
510
510
|
- `opt`: an object containing the keyword arguments provided to the function.
|
|
511
|
-
- `
|
|
511
|
+
- `data`: the current data object where the function has been executed.
|
|
512
|
+
- `variables`: an object containing the runtime variables available in the current context (e.g., `@root`, `@index`, etc.).
|
|
512
513
|
|
|
513
514
|
Example:
|
|
514
515
|
|
package/index.js
CHANGED
|
@@ -85,9 +85,9 @@ const create = (template = "", options = {}) => {
|
|
|
85
85
|
args: args,
|
|
86
86
|
opt: opt,
|
|
87
87
|
data: data,
|
|
88
|
-
|
|
88
|
+
variables: vars,
|
|
89
89
|
fn: (blockData = {}, blockVars = {}, blockOutput = []) => {
|
|
90
|
-
i = compile(tokens, blockOutput, blockData, {...vars, ...blockVars, root: vars.root}, j, t);
|
|
90
|
+
i = compile(tokens, blockOutput, blockData, {...vars, ...blockVars, parent: data, root: vars.root}, j, t);
|
|
91
91
|
return blockOutput.join("");
|
|
92
92
|
},
|
|
93
93
|
}));
|
|
@@ -130,7 +130,7 @@ const create = (template = "", options = {}) => {
|
|
|
130
130
|
else if (tokens[i].startsWith("=")) {
|
|
131
131
|
const [t, args, opt] = parseArgs(tokens[i].slice(1), data, vars);
|
|
132
132
|
if (typeof ctx.functions[t] === "function") {
|
|
133
|
-
output.push(ctx.functions[t]({args, opt, data}) || "");
|
|
133
|
+
output.push(ctx.functions[t]({args, opt, data, variables: vars}) || "");
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
else if (tokens[i].startsWith("/")) {
|