docx_tools 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/docx_tools/mail_merge.rb +15 -11
- data/lib/docx_tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d8d2712433f3db952944c6e9838e8e43fab2f4a
|
4
|
+
data.tar.gz: d2b37ef44857c24d13377ce081c8762b1581ff7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a3db409b76d4910bbd591cee2f61e6a8d7995fd6cc3aa5656e4510e8b1cc70c95ee2a36d0572eea1f4ed429f0c50df7bb60b5cac622d708ea87cd4e5f608143
|
7
|
+
data.tar.gz: 0e68fbac12573ae6923346164c67ad615b2c1f1fd1622e8a74112a4da24bc05ee34fc25c837506850c175ff1e70939253fbde283de14c98833ba27356cb08019
|
data/Gemfile.lock
CHANGED
@@ -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 =
|
68
|
-
merge_field.replace(
|
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
|
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')
|
90
|
+
instr_tags = parent.xpath('w:r/w:instrText')
|
91
|
+
instr_tag_content = instr_tags.map(&:content)
|
92
92
|
|
93
|
-
|
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.
|
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
|
data/lib/docx_tools/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|