Commit 7358d564 by Edgar HIPP

Fix issue with fileType mandatory for pptx

parent ddc6b911
### unreleased (master branch) ### unreleased (master branch)
### 3.0.2
- Fix issue with PPTX : Before, you had to add to your options : {fileType: "pptx"} in the module options passed as argument in the constructor of the module. Now, the fileType is retrieved from the main docxtemplater.
### 3.0.1 ### 3.0.1
- Add support for PPTX. - Add support for PPTX.
......
...@@ -75,7 +75,7 @@ class ImageModule { ...@@ -75,7 +75,7 @@ class ImageModule {
postparse(parsed) { postparse(parsed) {
let expandTo; let expandTo;
let getInner; let getInner;
if (this.options.fileType === "pptx") { if (this.fileType === "pptx") {
expandTo = "p:sp"; expandTo = "p:sp";
getInner = getInnerPptx; getInner = getInnerPptx;
} }
...@@ -112,7 +112,7 @@ class ImageModule { ...@@ -112,7 +112,7 @@ class ImageModule {
const size = [DocUtils.convertPixelsToEmus(sizePixel[0]), DocUtils.convertPixelsToEmus(sizePixel[1])]; const size = [DocUtils.convertPixelsToEmus(sizePixel[0]), DocUtils.convertPixelsToEmus(sizePixel[1])];
const centered = (this.options.centered || part.centered); const centered = (this.options.centered || part.centered);
let newText; let newText;
if (this.options.fileType === "pptx") { if (this.fileType === "pptx") {
newText = this.getRenderedPartPptx(part, rId, size, centered); newText = this.getRenderedPartPptx(part, rId, size, centered);
} }
else { else {
......
...@@ -38,11 +38,10 @@ beforeEach(function () { ...@@ -38,11 +38,10 @@ beforeEach(function () {
}; };
this.loadAndRender = function () { this.loadAndRender = function () {
const fileType = (testutils.pptX[this.name]) ? "pptx" : "docx"; const fileType = testutils.pptX[this.name] ? "pptx" : "docx";
const file = (fileType === "pptx") ? testutils.pptX[this.name] : testutils.docX[this.name]; const file = fileType === "pptx" ? testutils.pptX[this.name] : testutils.docX[this.name];
this.doc = new Docxtemplater(); this.doc = new Docxtemplater();
this.doc.setOptions({fileType}); this.doc.setOptions({fileType});
this.opts.fileType = fileType;
const inputZip = new JSZip(file.loadedContent); const inputZip = new JSZip(file.loadedContent);
this.doc.loadZip(inputZip).setData(this.data); this.doc.loadZip(inputZip).setData(this.data);
const imageModule = new ImageModule(this.opts); const imageModule = new ImageModule(this.opts);
...@@ -59,7 +58,6 @@ function testStart() { ...@@ -59,7 +58,6 @@ function testStart() {
this.name = "imageExample.docx"; this.name = "imageExample.docx";
this.expectedName = "expectedOneImage.docx"; this.expectedName = "expectedOneImage.docx";
this.data = {image: "examples/image.png"}; this.data = {image: "examples/image.png"};
this.fileType = "docx";
this.loadAndRender(); this.loadAndRender();
}); });
...@@ -119,11 +117,7 @@ function testStart() { ...@@ -119,11 +117,7 @@ function testStart() {
testutils.setExamplesDirectory(path.resolve(__dirname, "..", "examples")); testutils.setExamplesDirectory(path.resolve(__dirname, "..", "examples"));
testutils.setStartFunction(testStart); testutils.setStartFunction(testStart);
fileNames.forEach(function (filename) { fileNames.forEach(function (filename) {
if (filename.indexOf(".pptx") === filename.length - 5) { const loader = /\.pptx$/.test(filename) ? testutils.loadPptx : testutils.loadDocx;
testutils.loadFile(filename, testutils.loadPptx); testutils.loadFile(filename, loader);
}
else {
testutils.loadFile(filename, testutils.loadDocx);
}
}); });
testutils.start(); testutils.start();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment