Skip to content

Commit d3be84a

Browse files
committed
update api for 1.x
1 parent 7a6b2c4 commit d3be84a

File tree

3 files changed

+86
-85
lines changed

3 files changed

+86
-85
lines changed

coffee/docxgen.coffee

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ JSZip=require('jszip')
99

1010
DocxGen=class DocxGen
1111
templatedFiles=["word/document.xml","word/footer1.xml","word/footer2.xml","word/footer3.xml","word/header1.xml","word/header2.xml","word/header3.xml"]
12-
constructor:(content) ->
12+
constructor:(content,options) ->
1313
@setOptions({})
14-
if content? then if content.length>0 then @load(content)
14+
if content? then @load(content,options)
1515
setOptions:(@options={})->
1616
@intelligentTagging= if @options.intelligentTagging? then @options.intelligentTagging else on
1717
if @options.parser? then @parser=options.parser
1818
this
19-
load: (content)->
20-
@zip = new JSZip content
19+
load: (content,options)->
20+
if content.file?
21+
@zip=content
22+
else
23+
@zip = new JSZip content,options
2124
this
22-
applyTags:(@Tags=@Tags)->
25+
render:()->
2326
#Loop inside all templatedFiles (basically xml files with content). Sometimes they dont't exist (footer.xml for example)
2427
for fileName in templatedFiles when @zip.files[fileName]?
2528
currentFile= new DocXTemplater(@zip.files[fileName].asText(),{
@@ -29,10 +32,8 @@ DocxGen=class DocxGen
2932
parser:@parser
3033
fileName:fileName
3134
})
32-
@setData(fileName,currentFile.applyTags().content)
35+
@zip.file(fileName,currentFile.render().content)
3336
this
34-
setData:(fileName,data,options={})->
35-
@zip.file(fileName,data,options)
3637
getTags:()->
3738
usedTags=[]
3839
for fileName in templatedFiles when @zip.files[fileName]?
@@ -42,17 +43,15 @@ DocxGen=class DocxGen
4243
intelligentTagging:@intelligentTagging
4344
parser:@parser
4445
})
45-
usedTemplateV= currentFile.applyTags().usedTags
46+
usedTemplateV= currentFile.render().usedTags
4647
if DocUtils.sizeOfObject(usedTemplateV)
4748
usedTags.push {fileName,vars:usedTemplateV}
4849
usedTags
49-
setTags: (@Tags) ->
50+
setData:(@Tags) ->
5051
this
5152
#output all files, if docx has been loaded via javascript, it will be available
52-
output: (options={}) ->
53-
if !options.type? then options.type="base64"
54-
if !options.compression? then options.compression="DEFLATE"
55-
@zip.generate({type:options.type, compression:options.compression})
53+
getZip:()->
54+
@zip
5655
getFullText:(path="word/document.xml") ->
5756
usedData=@zip.files[path].asText()
5857
(new DocXTemplater(usedData,{DocxGen:this,Tags:@Tags,intelligentTagging:@intelligentTagging})).getFullText()

0 commit comments

Comments
 (0)