Commit 6a79b682 by Dk Saha

Added ResolveData support

parent c18b9be4
......@@ -8,7 +8,8 @@
"env": {
"node": true,
"browser": true,
"mocha": true
"mocha": true,
"es6": true
},
"rules": {
"accessor-pairs": 2,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -66,6 +66,9 @@ class ImageModule {
parse(placeHolderContent) {
const module = moduleName;
const type = "placeholder";
if (this.options.setParser) {
return this.options.setParser(placeHolderContent);
}
if (placeHolderContent.substring(0, 2) === "%%") {
return {type, value: placeHolderContent.substr(2), module, centered: true};
}
......@@ -88,23 +91,53 @@ class ImageModule {
return DocUtils.traits.expandToOne(parsed, {moduleName, getInner, expandTo});
}
render(part, options) {
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
const imgManager = this.imgManagers[options.filePath];
if (!part.type === "placeholder" || part.module !== moduleName) {
return null;
}
const tagValue = options.scopeManager.getValue(part.value);
const tagValue = options.scopeManager.getValue(part.value, {
part: part,
});
if (!tagValue) {
return {value: this.fileTypeConfig.tagTextXml};
}
const imgBuffer = this.options.getImage(tagValue, part.value);
if (!imgBuffer) {
return {value: this.fileTypeConfig.tagTextXml};
else if (typeof tagValue === "object") {
return this.getRenderedPart(part, tagValue.rId, tagValue.sizePixel);
}
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
const imgManager = this.imgManagers[options.filePath];
const imgBuffer = this.options.getImage(tagValue, part.value);
const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
const sizePixel = this.options.getSize(imgBuffer, tagValue, part.value);
return this.getRenderedPart(part, rId, sizePixel);
}
resolve(part, options) {
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
const imgManager = this.imgManagers[options.filePath];
if (!part.type === "placeholder" || part.module !== moduleName) {
return null;
}
const value = options.scopeManager.getValue(part.value, {
part: part,
});
if (!value) {
return {value: this.fileTypeConfig.tagTextXml};
}
return new Promise((resolve) => {
const imgBuffer = this.options.getImage(value, part.value);
resolve(imgBuffer);
}).then((imgBuffer) => {
const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
return new Promise((resolve) => {
const sizePixel = this.options.getSize(imgBuffer, value, part.value);
resolve(sizePixel);
}).then((sizePixel) => {
return {
rId: rId,
sizePixel: sizePixel,
};
});
});
}
getRenderedPart(part, rId, sizePixel) {
if (isNaN(rId)) {
throw new Error("rId is NaN, aborting");
......
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
......@@ -92,6 +94,9 @@ var ImageModule = function () {
value: function parse(placeHolderContent) {
var module = moduleName;
var type = "placeholder";
if (this.options.setParser) {
return this.options.setParser(placeHolderContent);
}
if (placeHolderContent.substring(0, 2) === "%%") {
return { type: type, value: placeHolderContent.substr(2), module: module, centered: true };
}
......@@ -117,24 +122,57 @@ var ImageModule = function () {
}, {
key: "render",
value: function render(part, options) {
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
var imgManager = this.imgManagers[options.filePath];
if (!part.type === "placeholder" || part.module !== moduleName) {
return null;
}
var tagValue = options.scopeManager.getValue(part.value);
var tagValue = options.scopeManager.getValue(part.value, {
part: part
});
if (!tagValue) {
return { value: this.fileTypeConfig.tagTextXml };
} else if ((typeof tagValue === "undefined" ? "undefined" : _typeof(tagValue)) === "object") {
return this.getRenderedPart(part, tagValue.rId, tagValue.sizePixel);
}
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
var imgManager = this.imgManagers[options.filePath];
var imgBuffer = this.options.getImage(tagValue, part.value);
if (!imgBuffer) {
return { value: this.fileTypeConfig.tagTextXml };
}
var rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
var sizePixel = this.options.getSize(imgBuffer, tagValue, part.value);
return this.getRenderedPart(part, rId, sizePixel);
}
}, {
key: "resolve",
value: function resolve(part, options) {
var _this = this;
this.imgManagers[options.filePath] = this.imgManagers[options.filePath] || new ImgManager(this.zip, options.filePath, this.xmlDocuments, this.fileType);
var imgManager = this.imgManagers[options.filePath];
if (!part.type === "placeholder" || part.module !== moduleName) {
return null;
}
var value = options.scopeManager.getValue(part.value, {
part: part
});
if (!value) {
return { value: this.fileTypeConfig.tagTextXml };
}
return new Promise(function (resolve) {
var imgBuffer = _this.options.getImage(value, part.value);
resolve(imgBuffer);
}).then(function (imgBuffer) {
var rId = imgManager.addImageRels(_this.getNextImageName(), imgBuffer);
return new Promise(function (resolve) {
var sizePixel = _this.options.getSize(imgBuffer, value, part.value);
resolve(sizePixel);
}).then(function (sizePixel) {
return {
rId: rId,
sizePixel: sizePixel
};
});
});
}
}, {
key: "getRenderedPart",
value: function getRenderedPart(part, rId, sizePixel) {
if (isNaN(rId)) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "open-docxtemplater-image-module",
"version": "1.0.3",
"name": "docxtemplater-image-module-free",
"version": "1.0.0",
"description": "Open Source Image Module for docxtemplater",
"main": "js/index.js",
"scripts": {
......@@ -32,9 +32,9 @@
},
"repository": {
"type": "git",
"url": "https://github.com/MaxRcd/open-docxtemplater-image-module"
"url": "https://github.com/evilc0des/docxtemplater-image-module-free"
},
"author": "MaxRcd (Edgar Hipp)",
"author": "Dk Saha",
"license": "MIT",
"dependencies": {
"xmldom": "^0.1.27"
......
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