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')
DocUtils=DocXTemplater.DocUtils
vm=require('vm')
JSZip=require('jszip')
......@@ -11,8 +10,6 @@ module.exports= class DocxQrCode
@callbacked=false
@data=imageData
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
@result=null
decode:(@callback) ->
......@@ -27,10 +24,7 @@ module.exports= class DocxQrCode
testdoc.render()
_this.result=testdoc.content
_this.searchImage()
if DocUtils.env=='browser'
@qr.decode("data:image/png;base64,#{@base64Data}")
else
@qr.decode(@data,@data.decoded)
@qr.decode(@data,@data.decoded)
searchImage:() ->
cb=(err,@data=@data.data)=>
if err then console.error err
......
......@@ -52,23 +52,19 @@ module.exports= class ImgReplacer
if imageTag==undefined then throw new Error('imageTag undefined')
replacement= DocUtils.xml2Str imageTag
@xmlTemplater.content= @xmlTemplater.content.replace(match[0], replacement)
if DocUtils.env=='browser'
@qr[u]= new DocxQrCode(oldFile.asBinary(),@xmlTemplater,imgName,num,@getDataFromString)
@qr[u].decode(@imageSetter)
mockedQrCode={xmlTemplater:@xmlTemplater,imgName:imgName,data:oldFile.asBinary(),num:num}
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
mockedQrCode={xmlTemplater:@xmlTemplater,imgName:imgName,data:oldFile.asBinary(),num:num}
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)
@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