Commit 7358d564 by Edgar HIPP

Fix issue with fileType mandatory for pptx

parent ddc6b911
### 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
- Add support for PPTX.
......
......@@ -75,7 +75,7 @@ class ImageModule {
postparse(parsed) {
let expandTo;
let getInner;
if (this.options.fileType === "pptx") {
if (this.fileType === "pptx") {
expandTo = "p:sp";
getInner = getInnerPptx;
}
......@@ -112,7 +112,7 @@ class ImageModule {
const size = [DocUtils.convertPixelsToEmus(sizePixel[0]), DocUtils.convertPixelsToEmus(sizePixel[1])];
const centered = (this.options.centered || part.centered);
let newText;
if (this.options.fileType === "pptx") {
if (this.fileType === "pptx") {
newText = this.getRenderedPartPptx(part, rId, size, centered);
}
else {
......
......@@ -38,11 +38,10 @@ beforeEach(function () {
};
this.loadAndRender = function () {
const fileType = (testutils.pptX[this.name]) ? "pptx" : "docx";
const file = (fileType === "pptx") ? testutils.pptX[this.name] : testutils.docX[this.name];
const fileType = testutils.pptX[this.name] ? "pptx" : "docx";
const file = fileType === "pptx" ? testutils.pptX[this.name] : testutils.docX[this.name];
this.doc = new Docxtemplater();
this.doc.setOptions({fileType});
this.opts.fileType = fileType;
const inputZip = new JSZip(file.loadedContent);
this.doc.loadZip(inputZip).setData(this.data);
const imageModule = new ImageModule(this.opts);
......@@ -59,7 +58,6 @@ function testStart() {
this.name = "imageExample.docx";
this.expectedName = "expectedOneImage.docx";
this.data = {image: "examples/image.png"};
this.fileType = "docx";
this.loadAndRender();
});
......@@ -119,11 +117,7 @@ function testStart() {
testutils.setExamplesDirectory(path.resolve(__dirname, "..", "examples"));
testutils.setStartFunction(testStart);
fileNames.forEach(function (filename) {
if (filename.indexOf(".pptx") === filename.length - 5) {
testutils.loadFile(filename, testutils.loadPptx);
}
else {
testutils.loadFile(filename, testutils.loadDocx);
}
const loader = /\.pptx$/.test(filename) ? testutils.loadPptx : testutils.loadDocx;
testutils.loadFile(filename, loader);
});
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