avv2word 1.1.33 → 1.1.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 113ac8940f8624930ea119678404b57b22286b6cc34f2569e8fda538286f6511
4
- data.tar.gz: 774e847ebd3f21dffa2b463615e5d406094a8b7f43f84f1650fbf66fa0e341f7
3
+ metadata.gz: 2ac8c2201742521a8490bbfc7d4dd37c48b266a55a0433523eb77673c2a4f7e1
4
+ data.tar.gz: f07a18f6d7e78f77ad2514f83bed08289d9e556ccbbc13741fd0583fdc0e3d6b
5
5
  SHA512:
6
- metadata.gz: 90a259c1d490a2d05d4f563b9e4d140be9aea06e034032e9e307a3cb32fad79d282519560acc4d9f371b6f191b177ebea5b381608e7ee52a4d38454b09f09bb7
7
- data.tar.gz: 81a82fafb181e12a440b3e594c289aa09d44e61f3dc3bbe4fb401e35ad75629467cbf8149474347516b8dab95cd077074e5bd31093dd5f55147b16f9920bd5aa
6
+ metadata.gz: 12578f80fa3c9bbd6e406a2f81ce125c0af34042d898aad7888e2f50233d3341c3604ed8103f92efdf4361029d425e45c67e74c906782a84022f8e37cf910e54
7
+ data.tar.gz: 23e13191db0523d71321d8507136e1e499bb39e49da54586f7596311043a9141bffaaffc1c1d192ddf1e71613f404fb0e125429f8d3e45fa3c6e1270c945f645
@@ -184,6 +184,7 @@ module Avv2word
184
184
  local_images(header, :header) if @header
185
185
 
186
186
  add_footnotes(source.css("footnote").map{ |footnote| footnote.text })
187
+ add_comments(source.css("comment")) unless source.css("comment").empty?
187
188
  end
188
189
 
189
190
  def transform_doc_xml(source, extras = false)
@@ -194,7 +195,28 @@ module Avv2word
194
195
 
195
196
  private
196
197
 
197
- def add_footnotes(footnotes)
198
+ def add_comments(comments)
199
+ @replaceable_files["word/comments.xml"] = %(<?xml version="1.0" encoding="UTF-8"?><w:comments xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">)
200
+ comments.each_with_index do |comment,id|
201
+ time = comment.attributes["time"].value # 2020-04-29T11:49:00Z
202
+ author = comment.attributes["author"].value
203
+ message = comment.attributes["message"].value
204
+ initials = comment.attributes["initials"].value
205
+ comment_generator = %Q(<w:comment w:id="#{id}" w:author="#{author}" w:date="#{time}" w:initials="#{initials}"><w:p w14:paraId="2F08968D" w14:textId="06CE6739" w:rsidR="009A6661" w:rsidRDefault="009A6661"><w:pPr><w:pStyle w:val="CommentText"/></w:pPr><w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r><w:r><w:t>#{message}</w:t></w:r></w:p></w:comment>)
206
+ @replaceable_files["word/comments.xml"] += comment_generator
207
+ end
208
+ @replaceable_files["word/comments.xml"] += "</w:comments>"
209
+
210
+ rels = Nokogiri::XML(@replaceable_files["word/_rels/document.xml.rels"])
211
+ new_rel = %(<Relationship Id="rIdXX" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="comments.xml"/>)
212
+ new_rel.sub!(/XX/, (rels.xpath("//xmlns:Relationship").size+1).to_s )
213
+ rels.children.first << Nokogiri::XML.parse(new_rel).child
214
+ @replaceable_files["word/_rels/document.xml.rels"] = rels.to_xml
215
+
216
+ insert_nodes_to_xml(Document.content_types_xml_file, ['<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"/>'])
217
+ end
218
+
219
+ def add_footnotes(footnotes)
198
220
  if footnotes.empty?
199
221
  @replaceable_files["word/footnotes.xml"] = ""
200
222
  return
@@ -248,7 +270,7 @@ module Avv2word
248
270
  end
249
271
  end
250
272
  [ '<w:style w:type="paragraph" w:styleId="FootnoteText"><w:name w:val="footnote text"/><w:basedOn w:val="Normal"/><w:link w:val="FootnoteTextChar"/><w:uiPriority w:val="99"/><w:semiHidden/><w:unhideWhenUsed/><w:rsid w:val="008D12FB"/></w:style>',
251
- '<w:style w:type="character" w:customStyle="1" w:styleId="FootnoteTextChar"><w:name w:val="Footnote Text Char"/><w:basedOn w:val="DefaultParagraphFont"/><w:link w:val="FootnoteText"/><w:uiPriority w:val="99"/><w:semiHidden/><w:rsid w:val="008D12FB"/></w:style>',
273
+ '<w:style w:type="character" w:customStyle="1" w:styleId="FootnoteTextChar"><w:name w:val="Footnote Text Char"/><w:basedOn w:val="DefaultParagraphFont"/><w:link w:val="FootnoteText"/><w:uiPriority w:val="99"/><w:semiHidden/><w:rsid w:val="008D12FB"/><w:rPr><w:sz w:val="14"/></w:rPr></w:style>',
252
274
  '<w:style w:type="character" w:styleId="FootnoteReference"><w:name w:val="footnote reference"/><w:basedOn w:val="DefaultParagraphFont"/><w:uiPriority w:val="99"/><w:semiHidden/><w:unhideWhenUsed/><w:rsid w:val="008D12FB"/><w:rPr><w:vertAlign w:val="superscript"/></w:rPr></w:style>'
253
275
  ].each do |new_style|
254
276
  styles.children.first << Nokogiri::XML.parse(new_style).child
@@ -261,15 +283,10 @@ module Avv2word
261
283
  @replaceable_files["word/styles.xml"] = styles.to_xml
262
284
 
263
285
  # content type
264
- Zip::File.open(@template_path) do |zipfile|
265
- types = Nokogiri::XML.parse(zipfile.read("[Content_Types].xml"))
266
- [ # '<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/>',
267
- '<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>'
268
- ].each do |new_type|
269
- types.children.first << Nokogiri::XML.parse(new_type).child
270
- end
271
- @replaceable_files["[Content_Types].xml"] = types.to_xml
272
- end
286
+ insert_nodes_to_xml(Document.content_types_xml_file, [
287
+ # '<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/>',
288
+ '<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>'
289
+ ])
273
290
  end
274
291
 
275
292
  def inject_relations(relations, noko_html_source)
@@ -363,5 +380,20 @@ module Avv2word
363
380
  #return the amended source to be saved into the zip
364
381
  doc.to_s
365
382
  end
383
+
384
+ def insert_nodes_to_xml(target_xml_file, inputs)
385
+ xml_content =
386
+ if @replaceable_files[target_xml_file]
387
+ Nokogiri::XML(@replaceable_files[target_xml_file])
388
+ else
389
+ Zip::File.open(@template_path) do |zipfile|
390
+ Nokogiri::XML.parse(zipfile.read(target_xml_file))
391
+ end
392
+ end
393
+ inputs.each do |new_node|
394
+ xml_content.children.first << Nokogiri::XML.parse(new_node).child
395
+ end
396
+ @replaceable_files[target_xml_file] = xml_content.to_xml
397
+ end
366
398
  end
367
399
  end
@@ -1,3 +1,3 @@
1
1
  module Avv2word
2
- VERSION = '1.1.33'
2
+ VERSION = '1.1.34'
3
3
  end
@@ -585,4 +585,16 @@
585
585
  </w:del>
586
586
  </xsl:template>
587
587
 
588
+ <xsl:template match="comment">
589
+ <xsl:number level="any" count="comment" format="1"/>
590
+ <w:commentRangeStart w:id="{format-number(count(preceding::comment),'0')}"/>
591
+ <w:r>
592
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
593
+ </w:r>
594
+ <w:commentRangeEnd w:id="{format-number(count(preceding::comment),'0')}"/>
595
+ <w:r>
596
+ <w:commentReference w:id="{format-number(count(preceding::comment),'0')}"/>
597
+ </w:r>
598
+ </xsl:template>
599
+
588
600
  </xsl:stylesheet>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avv2word
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.33
4
+ version: 1.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marián Bilas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-24 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack