btrz-liquid-templates 1.5.0 → 1.6.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.
- package/docs/index.md +1 -0
- package/package.json +2 -2
- package/src/money.js +7 -2
package/docs/index.md
CHANGED
|
@@ -706,6 +706,7 @@ Parameters
|
|
|
706
706
|
|------|------------|----------|---------|
|
|
707
707
|
| item | An object in the data given to the liquid template | N | ticket
|
|
708
708
|
| propName | The name of the property of the item | N | total
|
|
709
|
+
| evalPropName | Evaluates the second parameter to get the propName of the context | N | false
|
|
709
710
|
|
|
710
711
|
```liquid
|
|
711
712
|
"{% raw %} {%- money ticket total -%} {% endraw %}" //Given that ticket.total is 2800000 returns "28.00"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "btrz-liquid-templates",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"liquidjs": "^10.20.2",
|
|
28
28
|
"moment": "^2.30.1",
|
|
29
29
|
"moment-timezone": "^0.5.46",
|
|
30
|
-
"symbology": "
|
|
30
|
+
"symbology": "4.0.1",
|
|
31
31
|
"written-number": "^0.11.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
package/src/money.js
CHANGED
|
@@ -123,12 +123,17 @@ function Money(engine) {
|
|
|
123
123
|
const args = tagToken.args.split(" ");
|
|
124
124
|
this.item = args[0] || "ticket.total";
|
|
125
125
|
this.propName = args[1] || "total";
|
|
126
|
+
this.evalPropName = false;
|
|
127
|
+
if (args.length > 2) {
|
|
128
|
+
this.evalPropName = args[2] === "true"
|
|
129
|
+
}
|
|
126
130
|
},
|
|
127
131
|
render: async function(ctx) {
|
|
128
132
|
const item = await this.liquid.evalValue(this.item, ctx);
|
|
133
|
+
const propName = this.evalPropName ? await this.liquid.evalValue(this.propName, ctx) : this.propName;
|
|
129
134
|
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
130
|
-
item && item[
|
|
131
|
-
return formatter.money(getCurrencyValue(item,
|
|
135
|
+
item && item[propName] !== undefined) {
|
|
136
|
+
return formatter.money(getCurrencyValue(item, propName, ctx.environments.providerPreferences, {prefix: "display"}));
|
|
132
137
|
}
|
|
133
138
|
return "PNA";
|
|
134
139
|
}
|