docx_tools 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5a2434c4452cf3eb2b6602513bbac7da765114d
4
- data.tar.gz: 3e5d338708722a05adb60937b6ebc161dce2a2e9
3
+ metadata.gz: 5d8d2712433f3db952944c6e9838e8e43fab2f4a
4
+ data.tar.gz: d2b37ef44857c24d13377ce081c8762b1581ff7a
5
5
  SHA512:
6
- metadata.gz: 1864672d009f8bc460c2730aabb4f9fa5818957b04c80d020cf8b0fd6e428a4272e1c1f9ef70165b93ca4a96a1d260606a31a8f897144d2a3a50a05e95cfb001
7
- data.tar.gz: 7b904651582f0ac616d291ce0b751478fee02945c0228d0a47c481cb5da99972574df4c407b803528037aac31e522eb34129d60bf80b4a65283f14e511c470de
6
+ metadata.gz: 9a3db409b76d4910bbd591cee2f61e6a8d7995fd6cc3aa5656e4510e8b1cc70c95ee2a36d0572eea1f4ed429f0c50df7bb60b5cac622d708ea87cd4e5f608143
7
+ data.tar.gz: 0e68fbac12573ae6923346164c67ad615b2c1f1fd1622e8a74112a4da24bc05ee34fc25c837506850c175ff1e70939253fbde283de14c98833ba27356cb08019
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docx_tools (0.0.1)
4
+ docx_tools (0.0.2)
5
5
  nokogiri (~> 1.6, >= 1.6.6)
6
6
  rubyzip (~> 1.1, >= 1.1.7)
7
7
 
@@ -61,15 +61,14 @@ module DocxTools
61
61
 
62
62
  def merge_field(part, field, text)
63
63
  part.xpath(".//w:MergeField[text()=\"#{field}\"]").each do |merge_field|
64
- r_elem = Nokogiri::XML::Node.new('r', part)
65
64
  t_elem = Nokogiri::XML::Node.new('t', part)
66
65
  t_elem.content = text
67
- t_elem.parent = r_elem
68
- merge_field.replace(r_elem)
66
+ t_elem.parent = merge_field.parent
67
+ merge_field.replace(t_elem)
69
68
  end
70
69
  end
71
70
 
72
- # replace the original convoluted tag with a simplified tag for easy searching a processing
71
+ # replace the original convoluted tag with a simplified tag for easy searching and processing
73
72
  def process_merge_fields
74
73
  self.part_list.each_part do |part|
75
74
  part.root.remove_attribute('Ignorable')
@@ -88,21 +87,26 @@ module DocxTools
88
87
  part.xpath('.//w:instrText/../..').each do |parent|
89
88
  begin_tags = parent.xpath('w:r/w:fldChar[@w:fldCharType="begin"]/..')
90
89
  end_tags = parent.xpath('w:r/w:fldChar[@w:fldCharType="end"]/..')
91
- instr_tags = parent.xpath('w:r/w:instrText').map(&:content)
90
+ instr_tags = parent.xpath('w:r/w:instrText')
91
+ instr_tag_content = instr_tags.map(&:content)
92
92
 
93
- instr_tags.take(begin_tags.length).each_with_index do |instr, idx|
93
+ instr_tag_content.take(begin_tags.length).each_with_index do |instr, idx|
94
94
  next unless match_data = REGEXP.match(instr)
95
95
 
96
+ new_tag = Nokogiri::XML::Node.new('MergeField', part)
97
+ new_tag.content = match_data[1]
98
+
96
99
  children = parent.children
97
100
  start_idx = children.index(begin_tags[idx]) + 1
98
101
  end_idx = children.index(end_tags[idx])
99
102
  children[start_idx..end_idx].each do |child|
100
- child.remove
103
+ instr_node = child.xpath('w:instrText')
104
+ if instr_node.empty?
105
+ child.remove
106
+ else
107
+ instr_node.first.replace(new_tag)
108
+ end
101
109
  end
102
-
103
- new_tag = Nokogiri::XML::Node.new('MergeField', part)
104
- new_tag.content = match_data[1]
105
- begin_tags[idx].replace(new_tag)
106
110
  end
107
111
  end
108
112
  end
@@ -1,4 +1,4 @@
1
1
  module DocxTools
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri