Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
docxtemplater-image-module
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
docxtemplater-image-module
Commits
00f76531
Commit
00f76531
authored
Dec 13, 2015
by
Edgar HIPP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue #32 : Multiple images in header fails
parent
acb23e89
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
73 deletions
+72
-73
coffee/index.coffee
+7
-3
coffee/test.coffee
+65
-70
examples/qrHeader.docx
+0
-0
examples/qrHeaderNoImage.docx
+0
-0
No files found.
coffee/index.coffee
View file @
00f76531
...
@@ -75,10 +75,10 @@ class ImageModule
...
@@ -75,10 +75,10 @@ class ImageModule
xmlTemplater
=
@
manager
.
getInstance
(
'xmlTemplater'
)
xmlTemplater
=
@
manager
.
getInstance
(
'xmlTemplater'
)
imR
=
new
ImgReplacer
(
xmlTemplater
,
@
imgManager
)
imR
=
new
ImgReplacer
(
xmlTemplater
,
@
imgManager
)
imR
.
getDataFromString
=
(
result
,
cb
)
=>
imR
.
getDataFromString
=
(
result
,
cb
)
=>
if
@
getImageAsync
?
if
@
options
.
getImageAsync
?
@
getImageAsync
(
result
,
cb
)
@
options
.
getImageAsync
(
result
,
cb
)
else
else
cb
(
null
,
@
getImage
(
result
))
cb
(
null
,
@
options
.
getImage
(
result
))
imR
.
pushQrQueue
=
(
num
)
=>
imR
.
pushQrQueue
=
(
num
)
=>
@
qrQueue
.
push
(
num
)
@
qrQueue
.
push
(
num
)
imR
.
popQrQueue
=
(
num
)
=>
imR
.
popQrQueue
=
(
num
)
=>
...
@@ -87,12 +87,16 @@ class ImageModule
...
@@ -87,12 +87,16 @@ class ImageModule
@
qrQueue
.
splice
(
found
,
1
)
@
qrQueue
.
splice
(
found
,
1
)
else
@
on
(
'error'
,
new
Error
(
"qrqueue
#{
num
}
is not in qrqueue"
))
else
@
on
(
'error'
,
new
Error
(
"qrqueue
#{
num
}
is not in qrqueue"
))
if
@
qrQueue
.
length
==
0
then
@
finished
()
if
@
qrQueue
.
length
==
0
then
@
finished
()
num
=
parseInt
(
Math
.
random
()
*
10000
)
imR
.
pushQrQueue
(
"rendered-"
+
num
)
try
try
imR
imR
.
findImages
()
.
findImages
()
.
replaceImages
()
.
replaceImages
()
catch
e
catch
e
@
on
(
'error'
,
e
)
@
on
(
'error'
,
e
)
f
=
()
=>
imR
.
popQrQueue
(
"rendered-"
+
num
)
setImmediate
f
finished
:->
finished
:->
on
:
(
event
,
data
)
->
on
:
(
event
,
data
)
->
if
event
==
'error'
if
event
==
'error'
...
...
coffee/test.coffee
View file @
00f76531
...
@@ -10,9 +10,11 @@ fileNames=[
...
@@ -10,9 +10,11 @@ fileNames=[
'qrExample.docx'
,
'qrExample.docx'
,
'noImage.docx'
,
'noImage.docx'
,
'qrExample2.docx'
,
'qrExample2.docx'
,
'qrHeader.docx'
,
'qrHeaderNoImage.docx'
,
]
]
opts
=
{}
opts
=
null
beforeEach
()
->
beforeEach
()
->
opts
=
{}
opts
=
{}
opts
.
getImage
=
(
tagValue
)
->
opts
.
getImage
=
(
tagValue
)
->
...
@@ -50,22 +52,21 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -50,22 +52,21 @@ describe 'image adding with {% image} syntax', ()->
.
render
()
.
render
()
zip
=
out
.
getZip
()
zip
=
out
.
getZip
()
fs
.
writeFile
(
"test7.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}))
imageFile
=
zip
.
files
[
'word/media/image_generated_1.png'
]
imageFile
=
zip
.
files
[
'word/media/image_generated_1.png'
]
expect
(
imageFile
?
).
to
.
equal
(
true
)
expect
(
imageFile
?
,
"No image file found"
).
to
.
equal
(
true
)
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
relsFile
=
zip
.
files
[
'word/_rels/document.xml.rels'
]
relsFile
=
zip
.
files
[
'word/_rels/document.xml.rels'
]
expect
(
relsFile
?
).
to
.
equal
(
true
)
expect
(
relsFile
?
,
"No rels file found"
).
to
.
equal
(
true
)
relsFileContent
=
relsFile
.
asText
()
relsFileContent
=
relsFile
.
asText
()
expect
(
relsFileContent
).
to
.
equal
(
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/><Relationship Id="hId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header0.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image_generated_1.png"/></Relationships>"""
)
expect
(
relsFileContent
).
to
.
equal
(
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/><Relationship Id="hId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header0.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image_generated_1.png"/></Relationships>"""
)
documentFile
=
zip
.
files
[
'word/document.xml'
]
documentFile
=
zip
.
files
[
'word/document.xml'
]
expect
(
documentFile
?
).
to
.
equal
(
true
)
expect
(
documentFile
?
,
"No document file found"
).
to
.
equal
(
true
)
documentContent
=
documentFile
.
asText
()
documentContent
=
documentFile
.
asText
()
# expect(documentContent).to.equal("""<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT="0" distB="0" distL="0" distR="0">\n <wp:extent cx="1905000" cy="1905000"/>\n <wp:effectExtent l="0" t="0" r="0" b="0"/>\n <wp:docPr id="2" name="Image 2" descr="description"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">\n <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">\n <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">\n <pic:nvPicPr>\n <pic:cNvPr id="0" name="Picture 1" descr="description"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed="rId6">\n <a:extLst>\n <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">\n <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode="auto">\n <a:xfrm>\n <a:off x="0" y="0"/>\n <a:ext cx="1905000" cy="1905000"/>\n </a:xfrm>\n <a:prstGeom prst="rect">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r><w:bookmarkStart w:id="13" w:name="_GoBack"/><w:bookmarkEnd w:id="13"/></w:p><w:sectPr><w:headerReference w:type="default" r:id="hId0"/><w:type w:val="continuous"/><w:pgSz w:w="12240" w:h="15840" w:orient="portrait"/><w:pgMar w:top="2810" w:left="1800" w:right="1800" w:bottom="1440"/><w:cols w:num="1" w:sep="off" w:equalWidth="1"/></w:sectPr></w:body></w:document>""")
fs
.
writeFile
(
"test.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}))
it
'should work with centering'
,()
->
it
'should work with centering'
,()
->
d
=
new
DocxGen
()
d
=
new
DocxGen
()
...
@@ -79,6 +80,7 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -79,6 +80,7 @@ describe 'image adding with {% image} syntax', ()->
.
render
()
.
render
()
zip
=
out
.
getZip
()
zip
=
out
.
getZip
()
fs
.
writeFile
(
"test_center.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}))
imageFile
=
zip
.
files
[
'word/media/image_generated_1.png'
]
imageFile
=
zip
.
files
[
'word/media/image_generated_1.png'
]
expect
(
imageFile
?
).
to
.
equal
(
true
)
expect
(
imageFile
?
).
to
.
equal
(
true
)
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
...
@@ -91,13 +93,6 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -91,13 +93,6 @@ describe 'image adding with {% image} syntax', ()->
documentFile
=
zip
.
files
[
'word/document.xml'
]
documentFile
=
zip
.
files
[
'word/document.xml'
]
expect
(
documentFile
?
).
to
.
equal
(
true
)
expect
(
documentFile
?
).
to
.
equal
(
true
)
documentContent
=
documentFile
.
asText
()
documentContent
=
documentFile
.
asText
()
# expect(documentContent).to.equal("""<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body><w:p>\n\t<w:pPr>\n\t<w:jc w:val=\"center\"/>\n </w:pPr>\n <w:r>\n\t<w:rPr/>\n\t<w:drawing>\n\t <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n\t\t<wp:extent cx=\"1905000\" cy=\"1905000\"/>\n\t\t<wp:docPr id=\"15\" name=\"rId6.png\"/>\n\t\t<a:graphic>\n\t\t <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n\t\t\t<pic:pic>\n\t\t\t <pic:nvPicPr>\n\t\t\t\t<pic:cNvPr id=\"15\" name=\"rId6.png\"/>\n\t\t\t\t<pic:cNvPicPr/>\n\t\t\t </pic:nvPicPr>\n\t\t\t <pic:blipFill>\n\t\t\t\t<a:blip r:embed=\"rId6\"/>\n\t\t\t\t</pic:blipFill>\n\t\t\t <pic:spPr>\n\t\t\t\t<a:xfrm>\n\t\t\t\t <a:off x=\"0\" y=\"0\"/>\n\t\t\t\t <a:ext cx=\"1905000\" cy=\"1905000\"/>\n\t\t\t\t</a:xfrm>\n\t\t\t\t<a:prstGeom prst=\"rect\">\n\t\t\t\t <a:avLst/>\n\t\t\t\t</a:prstGeom>\n\t\t\t </pic:spPr>\n\t\t\t</pic:pic>\n\t\t </a:graphicData>\n\t\t </a:graphic>\n\t\t </wp:inline>\n\t\t </w:drawing>\n\t</w:r>\n</w:p><w:sectPr><w:headerReference w:type=\"default\" r:id=\"hId0\"/><w:type w:val=\"continuous\"/><w:pgSz w:w=\"12240\" w:h=\"15840\" w:orient=\"portrait\"/><w:pgMar w:top=\"2810\" w:left=\"1800\" w:right=\"1800\" w:bottom=\"1440\"/><w:cols w:num=\"1\" w:sep=\"off\" w:equalWidth=\"1\"/></w:sectPr></w:body></w:document>""")
#
# expect(documentContent).to.contain('align')
# expect(documentContent).to.contain('center')
fs
.
writeFile
(
"test_center.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}))
it
'should work with loops'
,()
->
it
'should work with loops'
,()
->
name
=
'imageLoopExample.docx'
name
=
'imageLoopExample.docx'
...
@@ -131,7 +126,6 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -131,7 +126,6 @@ describe 'image adding with {% image} syntax', ()->
documentFile
=
zip
.
files
[
'word/document.xml'
]
documentFile
=
zip
.
files
[
'word/document.xml'
]
expect
(
documentFile
?
).
to
.
equal
(
true
)
expect
(
documentFile
?
).
to
.
equal
(
true
)
documentContent
=
documentFile
.
asText
()
documentContent
=
documentFile
.
asText
()
# expect(documentContent).to.equal("""<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId6\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId7\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r><w:bookmarkStart w:id=\"20\" w:name=\"_GoBack\"/><w:bookmarkEnd w:id=\"20\"/></w:p><w:sectPr><w:headerReference w:type=\"default\" r:id=\"hId0\"/><w:type w:val=\"continuous\"/><w:pgSz w:w=\"12240\" w:h=\"15840\" w:orient=\"portrait\"/><w:pgMar w:top=\"2810\" w:left=\"1800\" w:right=\"1800\" w:bottom=\"1440\"/><w:cols w:num=\"1\" w:sep=\"off\" w:equalWidth=\"1\"/></w:sectPr></w:body></w:document>""")
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_multi.docx"
,
buffer
)
fs
.
writeFile
(
"test_multi.docx"
,
buffer
)
...
@@ -184,108 +178,109 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -184,108 +178,109 @@ describe 'image adding with {% image} syntax', ()->
describe
'qrcode replacing'
,
->
describe
'qrcode replacing'
,
->
describe
'shoud work without loops'
,
->
describe
'shoud work without loops'
,
->
zip
=
null
before
(
done
)
->
it
'should work with simple'
,
(
done
)
->
name
=
'qrExample.docx'
name
=
'qrExample.docx'
opts
.
qrCode
=
true
opts
.
qrCode
=
true
imageModule
=
new
ImageModule
(
opts
)
imageModule
=
new
ImageModule
(
opts
)
imageModule
.
getImage
=
(
imgData
)
->
d
=
fs
.
readFileSync
(
'examples/'
+
imgData
,
'binary'
)
d
imageModule
.
finished
=
()
->
imageModule
.
finished
=
()
->
zip
=
docX
[
name
].
getZip
()
zip
=
docX
[
name
].
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr.docx"
,
buffer
)
fs
.
writeFileSync
(
"test_qr.docx"
,
buffer
)
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
2
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
1
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
done
()
done
()
docX
[
name
]
=
docX
[
name
]
docX
[
name
]
=
docX
[
name
]
.
load
(
docX
[
name
].
loadedContent
)
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'image'
})
.
setData
({
image
:
'
examples/
image'
})
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
]
docX
[
name
]
.
render
()
.
render
()
it
'should work with simple'
,
->
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
2
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
1
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
describe
'should work with two'
,
->
describe
'should work with two'
,
->
zip
=
null
before
(
done
)
->
it
'should work'
,
(
done
)
->
name
=
'qrExample2.docx'
name
=
'qrExample2.docx'
opts
.
qrCode
=
true
opts
.
qrCode
=
true
imageModule
=
new
ImageModule
(
opts
)
imageModule
=
new
ImageModule
(
opts
)
imageModule
.
getImage
=
(
imgData
)
->
d
=
fs
.
readFileSync
(
'examples/'
+
imgData
,
'binary'
)
d
imageModule
.
finished
=
()
->
imageModule
.
finished
=
()
->
zip
=
docX
[
name
].
getZip
()
zip
=
docX
[
name
].
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr2.docx"
,
buffer
)
fs
.
writeFileSync
(
"test_qr3.docx"
,
buffer
)
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
4
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
859
)
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
2
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
expect
(
images
[
3
].
asText
().
length
).
to
.
be
.
within
(
7177
,
7181
)
done
()
done
()
docX
[
name
]
=
docX
[
name
]
docX
[
name
]
=
docX
[
name
]
.
load
(
docX
[
name
].
loadedContent
)
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'
image'
,
image2
:
'
image2.png'
})
.
setData
({
image
:
'
examples/image'
,
image2
:
'examples/
image2.png'
})
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
]
docX
[
name
]
.
render
()
.
render
()
it
'should work with two'
,
->
describe
'should work qr in headers without extra images'
,
->
images
=
zip
.
file
(
/media\/.*.png/
)
it
'should work in a header too'
,(
done
)
->
expect
(
images
.
length
).
to
.
equal
(
4
)
name
=
'qrHeaderNoImage.docx'
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
859
)
opts
.
qrCode
=
true
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
2
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
expect
(
images
[
3
].
asText
().
length
).
to
.
be
.
within
(
7177
,
7181
)
describe
'should work without images (it should call finished())'
,()
->
d
=
null
before
(
done
)
->
d
=
new
DocxGen
()
name
=
'noImage.docx'
opts
.
qrCode
=
true
imageModule
=
new
ImageModule
(
opts
)
imageModule
=
new
ImageModule
(
opts
)
imageModule
.
finished
=
()
->
imageModule
.
finished
=
()
->
zip
=
d
.
getZip
()
zip
=
d
ocX
[
name
]
.
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"testNoImage.docx"
,
buffer
)
fs
.
writeFile
(
"test_qr_header_no_image.docx"
,
buffer
)
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
3
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
12888
)
expect
(
images
[
2
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
done
()
done
()
d
.
attachModule
(
imageModule
)
docX
[
name
]
=
docX
[
name
]
out
=
d
.
load
(
docX
[
name
].
loadedContent
)
.
load
(
docX
[
name
].
loadedContent
)
.
setData
()
.
setData
({
image
:
'examples/image'
,
image2
:
'examples/image2.png'
})
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
]
.
render
()
.
render
()
it
'should have the same text'
,
->
describe
'should work qr in headers with extra images'
,
->
text
=
d
.
getFullText
()
it
'should work in a header too'
,(
done
)
->
expect
(
text
).
to
.
equal
(
"Here is no image"
)
name
=
'qrHeader.docx'
opts
.
qrCode
=
true
imageModule
=
new
ImageModule
(
opts
)
# it 'should work with inline images',()->
imageModule
.
finished
=
()
->
# name='imageInlineExample.docx'
zip
=
docX
[
name
].
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr_header.docx"
,
buffer
)
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
3
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
12888
)
expect
(
images
[
2
].
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
)
done
()
# imageModule=new ImageModule()
docX
[
name
]
=
docX
[
name
]
# docX[name].attachModule(imageModule)
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'examples/image'
,
image2
:
'examples/image2.png'
})
# out=docX[name]
docX
[
name
].
attachModule
(
imageModule
)
# .load(docX[name].loadedContent)
# .setData({firefox:'examples/image2.png'})
# out
docX
[
name
]
#
.render()
.
render
()
examples/qrHeader.docx
0 → 100644
View file @
00f76531
File added
examples/qrHeaderNoImage.docx
0 → 100644
View file @
00f76531
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment