Comparing version 1.9.0 to 1.10.0
{ | ||
"name": "btrz-pdf", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Generates pdf documents based on a liquid template", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
function Localizer(engine) { | ||
this.registerTag("t", { | ||
parse: function(tagToken, remainTokens) { | ||
this.str = tagToken.args; | ||
const args = tagToken.args.split("|"); | ||
this.str = (args[0] || "").trim(); | ||
if (args.length > 1) { | ||
this.tags = args.slice(1); | ||
} | ||
}, | ||
@@ -9,4 +13,7 @@ render: async function(ctx) { | ||
if (ctx && ctx.environments && ctx.environments.localizer && ctx.environments.localizer.get) { | ||
return ctx.environments.localizer.get(str); | ||
str = ctx.environments.localizer.get(str); | ||
} | ||
if (this.tags) { | ||
return await this.liquid.evalValue(`'${str}'|${this.tags}`, ctx); | ||
} | ||
return str; | ||
@@ -13,0 +20,0 @@ } |
@@ -135,2 +135,5 @@ describe("index.js", () => { | ||
} | ||
if (key === "text") { | ||
return "text here please"; | ||
} | ||
return `=>${key}`; | ||
@@ -193,2 +196,19 @@ } | ||
it("should apply tag after translations", async () => { | ||
const pdf = require("../src/index"); | ||
const template = `{ | ||
"content": [ | ||
"{% t 'text' | upcase %}" | ||
] | ||
}`; | ||
data.ticket.total = 0; | ||
data.ticket.ssrs[0].subTotal = 0; | ||
const documentDefinition = await pdf.toDocumentDefinition(template, data); | ||
expect(documentDefinition).to.be.eql({ | ||
"content": [ | ||
"TEXT HERE PLEASE" | ||
] | ||
}); | ||
}); | ||
it("should return money even when values is zero", async () => { | ||
@@ -195,0 +215,0 @@ const pdf = require("../src/index"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58154
1208