mikel 0.20.2 → 0.22.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 +3 -2
  2. package/index.js +4 -4
  3. package/package.json +3 -2
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
- - `context` (**DEPRECATED**): the current context (data) where the helper has been executed.
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
- - `context`: the current context (data) where the function has been executed.
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
@@ -20,7 +20,7 @@ const untokenize = (ts = [], s = "{{", e = "}}") => {
20
20
  const parseArgs = (str = "", data = {}, vars = {}, argv = [], opt = {}) => {
21
21
  const [t, ...args] = str.trim().match(/(?:[^\s"]+|"[^"]*")+/g);
22
22
  args.forEach(argStr => {
23
- if (argStr.includes("=")) {
23
+ if (argStr.includes("=") && !argStr.startsWith(`"`)) {
24
24
  const [k, v] = argStr.split("=");
25
25
  opt[k] = parse(v, data, vars);
26
26
  }
@@ -85,9 +85,9 @@ const create = (template = "", options = {}) => {
85
85
  args: args,
86
86
  opt: opt,
87
87
  data: data,
88
- context: data,
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("/")) {
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.20.2",
4
+ "version": "0.22.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Josemi Juanes",
@@ -19,7 +19,8 @@
19
19
  },
20
20
  "scripts": {
21
21
  "release": "node ./scripts/release.js",
22
- "test": "node test.js && yarn test:markdown",
22
+ "test": "node test.js && yarn test:eval && yarn test:markdown",
23
+ "test:eval": "node ./packages/mikel-eval/test.js",
23
24
  "test:markdown": "node ./packages/mikel-markdown/test.js"
24
25
  },
25
26
  "keywords": [