docx_manipulator 0.0.7 → 0.0.8
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.
data/lib/docx_manipulator.rb
CHANGED
@@ -28,6 +28,10 @@ class DocxManipulator
|
|
28
28
|
@relationships.add_image(id, path)
|
29
29
|
end
|
30
30
|
|
31
|
+
def add_relationship(id, type, target, attributes = {})
|
32
|
+
@relationships.add_node(id, type, target, attributes)
|
33
|
+
end
|
34
|
+
|
31
35
|
def add_binary_image(id, name, data)
|
32
36
|
@relationships.add_binary_image(id, name, data)
|
33
37
|
end
|
@@ -20,23 +20,25 @@ class DocxManipulator
|
|
20
20
|
|
21
21
|
def add_image(id, path)
|
22
22
|
@images << path
|
23
|
-
add_node(id, I18n.transliterate(File.basename(path)))
|
23
|
+
add_node(id, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', "media/#{I18n.transliterate(File.basename(path))}")
|
24
24
|
end
|
25
25
|
|
26
26
|
def add_binary_image(id, name, data)
|
27
27
|
name = I18n.transliterate(name)
|
28
28
|
@binary_images[name] = data
|
29
|
-
add_node(id, name)
|
29
|
+
add_node(id, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', "media/#{name}")
|
30
30
|
end
|
31
31
|
|
32
|
-
def add_node(id,
|
32
|
+
def add_node(id, type, target, attributes = {})
|
33
33
|
image_node = Nokogiri::XML::Node.new('Relationship', @relationships)
|
34
34
|
image_node['Id'] = id
|
35
|
-
image_node['Type'] =
|
36
|
-
image_node['Target'] =
|
35
|
+
image_node['Type'] = type
|
36
|
+
image_node['Target'] = target
|
37
|
+
attributes.each do |key, value|
|
38
|
+
image_node[key] = value
|
39
|
+
end
|
37
40
|
@relationships.root << image_node
|
38
41
|
end
|
39
|
-
private :add_node
|
40
42
|
|
41
43
|
def writes_to_files
|
42
44
|
['word/_rels/document.xml.rels']
|
@@ -128,4 +128,18 @@ EOF
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
context 'relationsships' do
|
132
|
+
it 'adds a reletionshop' do
|
133
|
+
subject.add_relationship('rId28', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', 'http://www.fricktalischer-reiterclub.ch', 'TargetMode' => 'External')
|
134
|
+
subject.process
|
135
|
+
|
136
|
+
Zip::ZipFile.open('spec/files/result.docx') do |file|
|
137
|
+
content = Nokogiri::XML.parse(file.get_input_stream('word/_rels/document.xml.rels').read)
|
138
|
+
node = content.xpath('//r:Relationship[@Id="rId28"]', 'r' => 'http://schemas.openxmlformats.org/package/2006/relationships').first
|
139
|
+
node['Target'].should == 'http://www.fricktalischer-reiterclub.ch'
|
140
|
+
node['TargetMode'].should == 'External'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
131
145
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: docx_manipulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Michael St\xC3\xA4mpfli"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2013-02-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|