Commit 908385e7 by Edgar HIPP

Remove all unnecessary references to DocUtils.env

docxtemplater shouldn't have any references to browser or node specific
functionality, so that it can be used from both without some magic
tricks
parent a359fcc8
DocXTemplater=require('docxtemplater') DocXTemplater=require('docxtemplater')
DocUtils=DocXTemplater.DocUtils
vm=require('vm') vm=require('vm')
JSZip=require('jszip') JSZip=require('jszip')
...@@ -11,8 +10,6 @@ module.exports= class DocxQrCode ...@@ -11,8 +10,6 @@ module.exports= class DocxQrCode
@callbacked=false @callbacked=false
@data=imageData @data=imageData
if @data==undefined then throw new Error("data of qrcode can't be undefined") if @data==undefined then throw new Error("data of qrcode can't be undefined")
if DocUtils.env=='browser'
@base64Data=JSZip.base64.encode(@data)
@ready=false @ready=false
@result=null @result=null
decode:(@callback) -> decode:(@callback) ->
...@@ -27,10 +24,7 @@ module.exports= class DocxQrCode ...@@ -27,10 +24,7 @@ module.exports= class DocxQrCode
testdoc.render() testdoc.render()
_this.result=testdoc.content _this.result=testdoc.content
_this.searchImage() _this.searchImage()
if DocUtils.env=='browser' @qr.decode(@data,@data.decoded)
@qr.decode("data:image/png;base64,#{@base64Data}")
else
@qr.decode(@data,@data.decoded)
searchImage:() -> searchImage:() ->
cb=(err,@data=@data.data)=> cb=(err,@data=@data.data)=>
if err then console.error err if err then console.error err
......
...@@ -52,23 +52,19 @@ module.exports= class ImgReplacer ...@@ -52,23 +52,19 @@ module.exports= class ImgReplacer
if imageTag==undefined then throw new Error('imageTag undefined') if imageTag==undefined then throw new Error('imageTag undefined')
replacement= DocUtils.xml2Str imageTag replacement= DocUtils.xml2Str imageTag
@xmlTemplater.content= @xmlTemplater.content.replace(match[0], replacement) @xmlTemplater.content= @xmlTemplater.content.replace(match[0], replacement)
if DocUtils.env=='browser' mockedQrCode={xmlTemplater:@xmlTemplater,imgName:imgName,data:oldFile.asBinary(),num:num}
@qr[u]= new DocxQrCode(oldFile.asBinary(),@xmlTemplater,imgName,num,@getDataFromString) if /\.png$/.test(oldFile.name)
@qr[u].decode(@imageSetter) do (imgName) =>
base64= JSZip.base64.encode oldFile.asBinary()
binaryData = new Buffer(base64, 'base64')
png= new PNG(binaryData)
finished= (a) =>
png.decoded= a
try
@qr[u]= new DocxQrCode(png,@xmlTemplater,imgName,num,@getDataFromString)
@qr[u].decode(@imageSetter)
catch e
@imageSetter(mockedQrCode)
dat= png.decode(finished)
else else
mockedQrCode={xmlTemplater:@xmlTemplater,imgName:imgName,data:oldFile.asBinary(),num:num} @imageSetter(mockedQrCode)
if /\.png$/.test(oldFile.name)
do (imgName) =>
base64= JSZip.base64.encode oldFile.asBinary()
binaryData = new Buffer(base64, 'base64')
png= new PNG(binaryData)
finished= (a) =>
png.decoded= a
try
@qr[u]= new DocxQrCode(png,@xmlTemplater,imgName,num,@getDataFromString)
@qr[u].decode(@imageSetter)
catch e
@imageSetter(mockedQrCode)
dat= png.decode(finished)
else
@imageSetter(mockedQrCode)
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