Skip to content

Commit

Permalink
Update tests and inspectModule
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 committed Dec 1, 2016
1 parent b3a9e45 commit 7afe04c
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 60 deletions.
7 changes: 4 additions & 3 deletions es6/docxtemplater.js
Expand Up @@ -38,7 +38,7 @@ const Docxtemplater = class Docxtemplater {
renderFile(fileName) {
const currentFile = this.createTemplateClass(fileName);
this.zip.file(fileName, currentFile.render().content);
this.compiled[fileName] = currentFile.compiled;
this.compiled[fileName] = currentFile.postparsed;
}
compile() {
this.templatedFiles = this.fileTypeConfig.getTemplatedFiles(this.zip);
Expand All @@ -61,9 +61,10 @@ const Docxtemplater = class Docxtemplater {
}
});
this.compile();
// Loop inside all templatedFiles (basically xml files with content). Sometimes they dont't exist (footer.xml for example)
// Loop inside all templatedFiles (ie xml files with content).
// Sometimes they don't exist (footer.xml for example)
this.templatedFiles.forEach((fileName) => {
if ((this.zip.files[fileName] != null)) {
if (this.zip.files[fileName] != null) {
this.renderFile(fileName);
}
});
Expand Down
152 changes: 100 additions & 52 deletions es6/tests/base.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions es6/tests/docxtemplater.js
Expand Up @@ -35,11 +35,13 @@ function startTest() {

describe("pptx generation", function () {
it("should work with simple pptx", function () {
const p = testUtils.pptX["simple-example.pptx"].setData({name: "Edgar"}).render();
const doc = testUtils.createPpt("simple-example.pptx");
const p = doc.setData({name: "Edgar"}).render();
expect(p.getFullText()).to.be.equal("Hello Edgar");
});
it("should work with simple raw pptx", function () {
const p = testUtils.pptX["raw-xml-example.pptx"].setData({raw: "<p:sp><a:t>Hello World</a:t></p:sp>"}).render();
const doc = testUtils.createPpt("raw-xml-example.pptx");
const p = doc.setData({raw: "<p:sp><a:t>Hello World</a:t></p:sp>"}).render();
expect(p.getFullText()).to.be.equal("Hello World");
});
});
Expand Down
7 changes: 6 additions & 1 deletion es6/tests/inspect-module.js
Expand Up @@ -3,13 +3,18 @@ const _ = require("lodash");
class inspectModule {
constructor() {
this.inspect = {};
this.fullInspected = {};
this.filePath = null;
}
set(obj) {
if (obj.inspect) {
if (obj.inspect.filePath) {
this.filePath = obj.inspect.filePath;
}
this.inspect = _.merge({}, this.inspect, obj.inspect);
this.fullInspected[this.filePath] = this.inspect;
}
}

}

module.exports = inspectModule;
14 changes: 12 additions & 2 deletions es6/tests/utils.js
Expand Up @@ -83,10 +83,10 @@ function load(name, content, fileType, obj) {
return obj[name];
}
function loadDocx(name, content) {
load(name, content, "docx", docX);
return load(name, content, "docx", docX);
}
function loadPptx(name, content) {
load(name, content, "pptx", pptX);
return load(name, content, "pptx", pptX);
}
function loadImage(name, content) {
imageData[name] = content;
Expand Down Expand Up @@ -142,8 +142,18 @@ function makeDocx(name, content) {
return load(name, base64, "docx", docX);
}

function createDoc(name) {
return loadDocx(name, docX[name].loadedContent);
}

function createPpt(name) {
return loadPptx(name, pptX[name].loadedContent);
}

module.exports = {
createXmlTemplaterDocx,
createDoc,
createPpt,
loadDocx,
loadPptx,
loadImage,
Expand Down
1 change: 1 addition & 0 deletions es6/xml-templater.js
Expand Up @@ -19,6 +19,7 @@ function getFullText(content, tagsXmlArray) {
module.exports = class XmlTemplater {
constructor(content, options) {
this.fromJson(options);
this.setModules({inspect: {filePath: this.filePath}});
this.load(content);
}
load(content) {
Expand Down
Binary file modified examples/tag-example-expected.docx
Binary file not shown.
Binary file modified examples/tag-intelligent-loop-table-expected.docx
Binary file not shown.

0 comments on commit 7afe04c

Please sign in to comment.