openxml-package 0.2.5 → 0.2.6

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
  SHA1:
3
- metadata.gz: a805e6c27e2e6fc3ea5f11ead8ec9666f2b50b99
4
- data.tar.gz: 483e85445b9bd192bd114ac8df7f97ecb5dc2f60
3
+ metadata.gz: 5323017681158167286a27e7c26df3781b547b7b
4
+ data.tar.gz: 4ab1a1397d8452202ecc02abbb3a484160b9c7f7
5
5
  SHA512:
6
- metadata.gz: 330d0e43f2d872dfbbe6431b75b486df3100aad56b61aaac8af1f580f32a828cd3e9d3f6736cb76481e80c2f32800219921252bad7e34ad7a8bda2b5c529c587
7
- data.tar.gz: 25c92ae9fc7843bcc28bd2af9667263d585a8d9efb62d32a613ea3db5312c85fd8d4a966192bc0b8dcf91d42e5f8e8635d79fedf8594823c838e43cccbf459ed
6
+ metadata.gz: 5e528096108f7b0536aad09ce7ef073c3774766cf506a797cf8807b887d126c8a216490dfbfab4b32ac736a0c7278a6001bd609d635bc570368d04b91e9b6e41
7
+ data.tar.gz: 6b9897eae69205b5d1e4f6723ca092569fe348775c265c3a6b38e5531e91abe52c7464cd09e0f87f79791752a289d96e0b6299901711da1e45c6d05b0ad1badf
@@ -1,3 +1,3 @@
1
1
  module OpenXmlPackage
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -9,7 +9,7 @@ module OpenXml
9
9
  document = Nokogiri(xml)
10
10
  self.new.tap do |part|
11
11
  document.css("Relationship").each do |rel|
12
- part.add_relationship rel["Type"], rel["Target"], rel["Id"]
12
+ part.add_relationship rel["Type"], rel["Target"], rel["Id"], rel["TargetMode"]
13
13
  end
14
14
  end
15
15
  end
@@ -17,12 +17,12 @@ module OpenXml
17
17
  def initialize(defaults=[])
18
18
  @relationships = []
19
19
  Array(defaults).each do |default|
20
- add_relationship(*default.values_at("Type", "Target", "Id"))
20
+ add_relationship(*default.values_at("Type", "Target", "Id", "TargetMode"))
21
21
  end
22
22
  end
23
23
 
24
- def add_relationship(type, target, id=nil)
25
- Relationship.new(type, target, id).tap do |relationship|
24
+ def add_relationship(type, target, id=nil, target_mode=nil)
25
+ Relationship.new(type, target, id, target_mode).tap do |relationship|
26
26
  relationships.push relationship
27
27
  end
28
28
  end
@@ -35,7 +35,9 @@ module OpenXml
35
35
  build_standalone_xml do |xml|
36
36
  xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") do
37
37
  relationships.each do |rel|
38
- xml.Relationship("Id" => rel.id, "Type" => rel.type, "Target" => rel.target)
38
+ attributes = { "Id" => rel.id, "Type" => rel.type, "Target" => rel.target }
39
+ attributes["TargetMode"] = rel.target_mode if rel.target_mode
40
+ xml.Relationship(attributes)
39
41
  end
40
42
  end
41
43
  end
@@ -43,9 +45,9 @@ module OpenXml
43
45
 
44
46
 
45
47
 
46
- class Relationship < Struct.new(:type, :target, :id)
47
- def initialize(type, target, id=nil)
48
- super type, target, id || "R#{SecureRandom.hex}"
48
+ class Relationship < Struct.new(:type, :target, :id, :target_mode)
49
+ def initialize(type, target, id=nil, target_mode=nil)
50
+ super type, target, id || "R#{SecureRandom.hex}", target_mode
49
51
  end
50
52
  end
51
53
 
data/test/package_test.rb CHANGED
@@ -125,6 +125,19 @@ class OpenXmlPackageTest < ActiveSupport::TestCase
125
125
  end
126
126
  end
127
127
  end
128
+
129
+ context "Given a document with an external hyperlink" do
130
+ context ".open" do
131
+ should "parse the TargetMode attribute of the Relationship element" do
132
+ path = expand_path "support/external_hyperlink.docx"
133
+ OpenXml::Package.open(path) do |package|
134
+ part = package.parts["word/_rels/document.xml.rels"]
135
+ relationship = part.find { |r| r.target == "http://example.com" }
136
+ assert_equal relationship.target_mode, 'External'
137
+ end
138
+ end
139
+ end
140
+ end
128
141
  end
129
142
 
130
143
 
data/test/rels_test.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class RelsTest < ActiveSupport::TestCase
4
+ context "#to_xml" do
5
+ context "given a document with an external hyperlink" do
6
+ should "write the TargetMode attribute of the Relationship element" do
7
+ path = File.expand_path "../support/external_hyperlink.docx", __FILE__
8
+ OpenXml::Package.open(path) do |package|
9
+ part = package.parts["word/_rels/document.xml.rels"]
10
+ assert_match /<Relationship Id=".+" Target="http:\/\/example.com" TargetMode="External"/, part.to_xml.to_s
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openxml-package
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -229,6 +229,8 @@ files:
229
229
  - test/element_test.rb
230
230
  - test/package_test.rb
231
231
  - test/part_test.rb
232
+ - test/rels_test.rb
233
+ - test/support/external_hyperlink.docx
232
234
  - test/support/sample.docx
233
235
  - test/test_helper.rb
234
236
  - tmp/.keep
@@ -261,5 +263,7 @@ test_files:
261
263
  - test/element_test.rb
262
264
  - test/package_test.rb
263
265
  - test/part_test.rb
266
+ - test/rels_test.rb
267
+ - test/support/external_hyperlink.docx
264
268
  - test/support/sample.docx
265
269
  - test/test_helper.rb