open_xml_package 0.0.3 → 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/open_xml/content_types_presets.rb +18 -0
- data/lib/open_xml/errors.rb +8 -0
- data/lib/open_xml/package.rb +135 -0
- data/lib/open_xml/part.rb +32 -0
- data/lib/open_xml/parts/content_types.rb +51 -0
- data/lib/open_xml/parts/rels.rb +57 -0
- data/lib/open_xml/parts/unparsed_part.rb +20 -0
- data/lib/open_xml/parts.rb +10 -0
- data/lib/{open_xml_package → open_xml}/rubyzip_fix.rb +0 -0
- data/lib/open_xml/types.rb +6 -0
- data/lib/open_xml_package/version.rb +2 -2
- data/lib/open_xml_package.rb +1 -87
- data/open_xml_package.gemspec +3 -2
- data/test/content_types_test.rb +34 -0
- data/test/open_xml_package_test.rb +44 -18
- metadata +55 -31
- data/lib/open_xml_package/part.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dccd074a45e7ab40ae475a08cc76fa971b1fdf28
|
4
|
+
data.tar.gz: 9c2b1b2f54b9ebe31ea4dc5fb897811ef868048c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed7b80d5fdc04c631963c985b7cd514b1a7dcaec082ad508e5a8f4eaf01185952dc25359bd3466a027eea5c4018bec380d3243e4ba111664cc196bd793a1b58c
|
7
|
+
data.tar.gz: 1e2c65ddc9e0c1f92f9b54dc02240ba50b6558f3289b0343bda5a79cc7337c8fbb2fe8b2194086cce6cb0a52a93d407f37d7caae00d9916fde35bba8fcf2a6ba
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OpenXml
|
2
|
+
class ContentTypesPresets
|
3
|
+
attr_reader :defaults, :overrides
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@defaults, @overrides = {}, {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def default(extension, content_type)
|
10
|
+
defaults[extension] = content_type
|
11
|
+
end
|
12
|
+
|
13
|
+
def override(part_name, content_type)
|
14
|
+
overrides[part_name] = content_type
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "open_xml_package/version"
|
2
|
+
require "open_xml/content_types_presets"
|
3
|
+
require "open_xml/rubyzip_fix"
|
4
|
+
require "open_xml/errors"
|
5
|
+
require "open_xml/types"
|
6
|
+
require "open_xml/parts"
|
7
|
+
require "zip"
|
8
|
+
|
9
|
+
module OpenXml
|
10
|
+
class Package
|
11
|
+
attr_reader :parts, :content_types, :rels
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def content_types_presets
|
17
|
+
@content_types_presets ||= OpenXml::ContentTypesPresets.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def content_types(&block)
|
21
|
+
content_types_presets.instance_eval &block
|
22
|
+
end
|
23
|
+
|
24
|
+
def open(path)
|
25
|
+
if block_given?
|
26
|
+
Zip::File.open(path) do |zipfile|
|
27
|
+
yield new(zipfile)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
new Zip::File.open(path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def from_stream(stream)
|
35
|
+
stream = StringIO.new(stream) if stream.is_a?(String)
|
36
|
+
|
37
|
+
# Hack: Zip::Entry.read_c_dir_entry initializes
|
38
|
+
# a new Zip::Entry by calling `io.path`. Zip::Entry
|
39
|
+
# uses this to open the original zipfile; but in
|
40
|
+
# this case, the StringIO _is_ the original.
|
41
|
+
def stream.path
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
zipfile = ::Zip::File.new("", true, true)
|
46
|
+
zipfile.read_from_stream(stream)
|
47
|
+
new(zipfile)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def initialize(zipfile=nil)
|
54
|
+
@zipfile = zipfile
|
55
|
+
@parts = {}
|
56
|
+
|
57
|
+
if zipfile
|
58
|
+
read_zipfile!
|
59
|
+
else
|
60
|
+
set_defaults
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
def add_part(path, part)
|
67
|
+
@parts[path] = part
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_part(path)
|
71
|
+
@parts.fetch(path)
|
72
|
+
end
|
73
|
+
|
74
|
+
def type_of(path)
|
75
|
+
raise Errors::MissingContentTypesPart, "We haven't yet read [ContentTypes].xml; but are reading #{path.inspect}" unless content_types
|
76
|
+
content_types.of(path)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
def close
|
82
|
+
zipfile.close if zipfile
|
83
|
+
end
|
84
|
+
|
85
|
+
def write_to(path)
|
86
|
+
File.open(path, "w") do |file|
|
87
|
+
file.write to_stream.string
|
88
|
+
end
|
89
|
+
end
|
90
|
+
alias :save :write_to
|
91
|
+
|
92
|
+
def to_stream
|
93
|
+
Zip::OutputStream.write_buffer do |io|
|
94
|
+
parts.each do |path, part|
|
95
|
+
io.put_next_entry path
|
96
|
+
io.write part.content
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
attr_reader :zipfile
|
104
|
+
|
105
|
+
def read_zipfile!
|
106
|
+
zipfile.entries.each do |entry|
|
107
|
+
path, part = entry.name, Parts::UnparsedPart.new(entry)
|
108
|
+
add_part path, case path
|
109
|
+
when "[Content_Types].xml" then @content_types = Parts::ContentTypes.parse(part.content)
|
110
|
+
when "_rels/.rels" then @rels = Parts::Rels.parse(part.content)
|
111
|
+
else part_for(path, type_of(path), part)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
|
118
|
+
def set_defaults
|
119
|
+
presets = self.class.content_types_presets
|
120
|
+
@content_types = Parts::ContentTypes.new(presets.defaults, presets.overrides)
|
121
|
+
add_part "[Content_Types].xml", content_types
|
122
|
+
|
123
|
+
@rels = Parts::Rels.new
|
124
|
+
add_part "_rels/.rels", rels
|
125
|
+
end
|
126
|
+
|
127
|
+
def part_for(path, content_type, part)
|
128
|
+
case content_type
|
129
|
+
when Types::RELATIONSHIPS then Parts::Rels.parse(part.content)
|
130
|
+
else part
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
class Part
|
5
|
+
include ::Nokogiri
|
6
|
+
|
7
|
+
def build_xml
|
8
|
+
XML::Builder.new(encoding: "utf-8") { |xml| yield xml }.to_xml
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_standalone_xml
|
12
|
+
xml = Nokogiri::XML("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>")
|
13
|
+
XML::Builder.with(xml) { |xml| yield xml }.to_xml
|
14
|
+
end
|
15
|
+
|
16
|
+
def read
|
17
|
+
strip_whitespace to_xml
|
18
|
+
end
|
19
|
+
alias :content :read
|
20
|
+
|
21
|
+
def to_xml
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def strip_whitespace(xml)
|
28
|
+
xml.lines.map(&:strip).join
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Parts
|
3
|
+
class ContentTypes < OpenXml::Part
|
4
|
+
attr_reader :defaults, :overrides
|
5
|
+
|
6
|
+
REQUIRED_DEFAULTS = {
|
7
|
+
"xml" => Types::XML,
|
8
|
+
"rels" => Types::RELATIONSHIPS
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def self.parse(xml)
|
12
|
+
document = Nokogiri(xml)
|
13
|
+
self.new.tap do |part|
|
14
|
+
document.css("Default").each do |default|
|
15
|
+
part.add_default default["Extension"], default["ContentType"]
|
16
|
+
end
|
17
|
+
document.css("Override").each do |default|
|
18
|
+
part.add_override default["PartName"], default["ContentType"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(defaults={}, overrides={})
|
24
|
+
@defaults = REQUIRED_DEFAULTS.merge(defaults)
|
25
|
+
@overrides = overrides
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_default(extension, content_type)
|
29
|
+
defaults[extension] = content_type
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_override(part_name, content_type)
|
33
|
+
overrides[part_name] = content_type
|
34
|
+
end
|
35
|
+
|
36
|
+
def of(path)
|
37
|
+
overrides.fetch(path, defaults[File.extname(path)[1..-1]])
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_xml
|
41
|
+
build_xml do |xml|
|
42
|
+
xml.Types(xmlns: "http://schemas.openxmlformats.org/package/2006/content-types") {
|
43
|
+
defaults.each { |extension, content_type| xml.Default("Extension" => extension, "ContentType" => content_type) }
|
44
|
+
overrides.each { |part_name, content_type| xml.Override("PartName" => part_name, "ContentType" => content_type) }
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
module Parts
|
5
|
+
class Rels < OpenXml::Part
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def self.parse(xml)
|
9
|
+
document = Nokogiri(xml)
|
10
|
+
self.new.tap do |part|
|
11
|
+
document.css("Relationship").each do |rel|
|
12
|
+
part.add_relationship rel["Type"], rel["Target"], rel["Id"]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(defaults=[])
|
18
|
+
@relationships = []
|
19
|
+
Array(defaults).each do |default|
|
20
|
+
add_relationship(*default.values_at("Type", "Target", "Id"))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_relationship(type, target, id=nil)
|
25
|
+
Relationship.new(type, target, id).tap do |relationship|
|
26
|
+
relationships.push relationship
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def each(&block)
|
31
|
+
relationships.each(&block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_xml
|
35
|
+
build_standalone_xml do |xml|
|
36
|
+
xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") do
|
37
|
+
relationships.each do |rel|
|
38
|
+
xml.Relationship("Id" => rel.id, "Type" => rel.type, "Target" => rel.target)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class Relationship < Struct.new(:type, :target, :id)
|
47
|
+
def initialize(type, target, id=nil)
|
48
|
+
super type, target, id || "R#{SecureRandom.hex}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
attr_reader :relationships
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Parts
|
3
|
+
class UnparsedPart
|
4
|
+
|
5
|
+
def initialize(content)
|
6
|
+
@content = content
|
7
|
+
end
|
8
|
+
|
9
|
+
def content
|
10
|
+
@content = @content.get_input_stream.read if promise?
|
11
|
+
@content
|
12
|
+
end
|
13
|
+
|
14
|
+
def promise?
|
15
|
+
@content.respond_to? :get_input_stream
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module OpenXmlPackage
|
2
|
+
VERSION = "0.1.0.beta1"
|
3
3
|
end
|
data/lib/open_xml_package.rb
CHANGED
@@ -1,87 +1 @@
|
|
1
|
-
require "
|
2
|
-
require "open_xml_package/rubyzip_fix"
|
3
|
-
require "open_xml_package/version"
|
4
|
-
require "zip"
|
5
|
-
|
6
|
-
|
7
|
-
class OpenXmlPackage
|
8
|
-
attr_reader :parts
|
9
|
-
|
10
|
-
def self.open(path)
|
11
|
-
if block_given?
|
12
|
-
Zip::File.open(path) do |zipfile|
|
13
|
-
yield new(zipfile)
|
14
|
-
end
|
15
|
-
else
|
16
|
-
new Zip::File.open(path)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.from_stream(stream)
|
21
|
-
stream = StringIO.new(stream) if stream.is_a?(String)
|
22
|
-
|
23
|
-
# Hack: Zip::Entry.read_c_dir_entry initializes
|
24
|
-
# a new Zip::Entry by calling `io.path`. Zip::Entry
|
25
|
-
# uses this to open the original zipfile; but in
|
26
|
-
# this case, the StringIO _is_ the original.
|
27
|
-
def stream.path
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
|
-
zipfile = ::Zip::File.new("", true, true)
|
32
|
-
zipfile.read_from_stream(stream)
|
33
|
-
new(zipfile)
|
34
|
-
end
|
35
|
-
|
36
|
-
def initialize(zipfile=nil)
|
37
|
-
@zipfile = zipfile
|
38
|
-
@parts = []
|
39
|
-
read_zipfile! if zipfile
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def add_part(path_or_part, content=nil)
|
45
|
-
path = path_or_part
|
46
|
-
path = path_or_part.path if path_or_part.respond_to?(:path)
|
47
|
-
content = path_or_part.read if path_or_part.respond_to?(:read)
|
48
|
-
|
49
|
-
@parts << Part.new(path, content)
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_part(path)
|
53
|
-
@parts.detect { |part| part.path == path }
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def close
|
59
|
-
zipfile.close if zipfile
|
60
|
-
end
|
61
|
-
|
62
|
-
def write_to(path)
|
63
|
-
File.open(path, "w") do |file|
|
64
|
-
file.write to_stream.string
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_stream
|
69
|
-
Zip::OutputStream.write_buffer do |io|
|
70
|
-
parts.each do |part|
|
71
|
-
io.put_next_entry part.path
|
72
|
-
io.write part.content
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
attr_reader :zipfile
|
80
|
-
|
81
|
-
def read_zipfile!
|
82
|
-
zipfile.entries.each do |entry|
|
83
|
-
@parts << Part.new(entry.name, entry)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
1
|
+
require "open_xml/package"
|
data/open_xml_package.gemspec
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "rubyzip"
|
21
|
+
spec.add_dependency "rubyzip", "~> 1.1.0"
|
22
|
+
spec.add_dependency "nokogiri"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
25
|
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rails", ">= 3.2", "<
|
26
|
+
spec.add_development_dependency "rails", ">= 3.2", "< 5.0"
|
26
27
|
spec.add_development_dependency "turn"
|
27
28
|
spec.add_development_dependency "pry"
|
28
29
|
spec.add_development_dependency "rr"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ContentTypesTest < ActiveSupport::TestCase
|
4
|
+
attr_reader :content_types
|
5
|
+
|
6
|
+
WORDPROCESSING_DOCUMENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@content_types = OpenXml::Parts::ContentTypes.new(
|
10
|
+
{"xml" => OpenXml::Types::XML, "rels" => OpenXml::Types::RELATIONSHIPS},
|
11
|
+
{"word/document.xml" => WORDPROCESSING_DOCUMENT_TYPE})
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
context "Given a path without an override" do
|
16
|
+
should "identify the content type from its extension" do
|
17
|
+
assert_equal OpenXml::Types::XML, content_types.of("content/some.xml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "Given a path with an override" do
|
22
|
+
should "identify the content type from its path" do
|
23
|
+
assert_equal WORDPROCESSING_DOCUMENT_TYPE, content_types.of("word/document.xml")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "Given a path with an unrecognized extension" do
|
28
|
+
should "be nil" do
|
29
|
+
assert_equal nil, content_types.of("img/screenshot.jpg")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -2,23 +2,17 @@ require "test_helper"
|
|
2
2
|
require "fileutils"
|
3
3
|
require "set"
|
4
4
|
|
5
|
-
|
6
5
|
class OpenXmlPackageTest < ActiveSupport::TestCase
|
7
6
|
attr_reader :package, :temp_file
|
8
7
|
|
9
8
|
|
10
9
|
|
11
10
|
context "#add_part" do
|
12
|
-
should "accept a path and
|
13
|
-
package =
|
14
|
-
package.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
should "accept a part that responds to :path and :read" do
|
19
|
-
package = OpenXmlPackage.new
|
20
|
-
package.add_part OpenXmlPackage::Part.new("PATH", "CONTENT")
|
21
|
-
assert_equal 1, package.parts.count
|
11
|
+
should "accept a path and a part" do
|
12
|
+
package = OpenXml::Package.new
|
13
|
+
assert_difference "package.parts.count", +1 do
|
14
|
+
package.add_part "PATH", OpenXml::Part.new
|
15
|
+
end
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
@@ -32,14 +26,15 @@ class OpenXmlPackageTest < ActiveSupport::TestCase
|
|
32
26
|
|
33
27
|
context "Given a simple part" do
|
34
28
|
setup do
|
35
|
-
@package =
|
36
|
-
package.add_part "content/document.xml", document_content
|
29
|
+
@package = OpenXml::Package.new
|
30
|
+
package.add_part "content/document.xml", OpenXml::Parts::UnparsedPart.new(document_content)
|
37
31
|
end
|
38
32
|
|
39
33
|
should "write a valid zip file with the expected parts" do
|
40
34
|
package.write_to temp_file
|
41
35
|
assert File.exists?(temp_file), "Expected the file #{temp_file.inspect} to have been created"
|
42
|
-
assert_equal %w{content/document.xml},
|
36
|
+
assert_equal %w{[Content_Types].xml _rels/.rels content/document.xml},
|
37
|
+
Zip::File.open(temp_file).entries.map(&:name)
|
43
38
|
end
|
44
39
|
end
|
45
40
|
end
|
@@ -69,7 +64,7 @@ class OpenXmlPackageTest < ActiveSupport::TestCase
|
|
69
64
|
|
70
65
|
context ".open" do
|
71
66
|
setup do
|
72
|
-
@package =
|
67
|
+
@package = OpenXml::Package.open(temp_file)
|
73
68
|
end
|
74
69
|
|
75
70
|
teardown do
|
@@ -77,7 +72,7 @@ class OpenXmlPackageTest < ActiveSupport::TestCase
|
|
77
72
|
end
|
78
73
|
|
79
74
|
should "discover the expected parts" do
|
80
|
-
assert_equal @expected_contents, package.parts.
|
75
|
+
assert_equal @expected_contents, package.parts.keys.to_set
|
81
76
|
end
|
82
77
|
|
83
78
|
should "read their content on-demand" do
|
@@ -87,17 +82,48 @@ class OpenXmlPackageTest < ActiveSupport::TestCase
|
|
87
82
|
|
88
83
|
context ".from_stream" do
|
89
84
|
setup do
|
90
|
-
@package =
|
85
|
+
@package = OpenXml::Package.from_stream(File.open(temp_file, "rb", &:read))
|
91
86
|
end
|
92
87
|
|
93
88
|
should "also discover the expected parts" do
|
94
|
-
assert_equal @expected_contents, package.parts.
|
89
|
+
assert_equal @expected_contents, package.parts.keys.to_set
|
95
90
|
end
|
96
91
|
|
97
92
|
should "read their content" do
|
98
93
|
assert_equal web_settings_content, package.get_part("word/webSettings.xml").content
|
99
94
|
end
|
100
95
|
end
|
96
|
+
|
97
|
+
context "ContentTypes" do
|
98
|
+
setup do
|
99
|
+
@package = OpenXml::Package.open(temp_file)
|
100
|
+
end
|
101
|
+
|
102
|
+
teardown do
|
103
|
+
package.close
|
104
|
+
end
|
105
|
+
|
106
|
+
should "be parsed" do
|
107
|
+
assert_equal %w{jpeg png rels xml}, package.content_types.defaults.keys.sort
|
108
|
+
assert_equal "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
|
109
|
+
package.content_types.overrides["/word/document.xml"]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "Rels" do
|
114
|
+
setup do
|
115
|
+
@package = OpenXml::Package.open(temp_file)
|
116
|
+
end
|
117
|
+
|
118
|
+
teardown do
|
119
|
+
package.close
|
120
|
+
end
|
121
|
+
|
122
|
+
should "be parsed" do
|
123
|
+
assert_equal %w{docProps/core.xml docProps/app.xml word/document.xml docProps/thumbnail.jpeg},
|
124
|
+
package.rels.map(&:target)
|
125
|
+
end
|
126
|
+
end
|
101
127
|
end
|
102
128
|
end
|
103
129
|
|
metadata
CHANGED
@@ -1,145 +1,159 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_xml_package
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.1.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '0'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- -
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - ~>
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '1.6'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - ~>
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.6'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rails
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '3.2'
|
62
|
-
- - <
|
76
|
+
- - "<"
|
63
77
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
78
|
+
version: '5.0'
|
65
79
|
type: :development
|
66
80
|
prerelease: false
|
67
81
|
version_requirements: !ruby/object:Gem::Requirement
|
68
82
|
requirements:
|
69
|
-
- -
|
83
|
+
- - ">="
|
70
84
|
- !ruby/object:Gem::Version
|
71
85
|
version: '3.2'
|
72
|
-
- - <
|
86
|
+
- - "<"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
88
|
+
version: '5.0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: turn
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
|
-
- -
|
93
|
+
- - ">="
|
80
94
|
- !ruby/object:Gem::Version
|
81
95
|
version: '0'
|
82
96
|
type: :development
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
|
-
- -
|
100
|
+
- - ">="
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '0'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: pry
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
|
-
- -
|
107
|
+
- - ">="
|
94
108
|
- !ruby/object:Gem::Version
|
95
109
|
version: '0'
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
|
-
- -
|
114
|
+
- - ">="
|
101
115
|
- !ruby/object:Gem::Version
|
102
116
|
version: '0'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: rr
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
|
-
- -
|
121
|
+
- - ">="
|
108
122
|
- !ruby/object:Gem::Version
|
109
123
|
version: '0'
|
110
124
|
type: :development
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
|
-
- -
|
128
|
+
- - ">="
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '0'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
132
|
name: simplecov
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
120
134
|
requirements:
|
121
|
-
- -
|
135
|
+
- - ">="
|
122
136
|
- !ruby/object:Gem::Version
|
123
137
|
version: '0'
|
124
138
|
type: :development
|
125
139
|
prerelease: false
|
126
140
|
version_requirements: !ruby/object:Gem::Requirement
|
127
141
|
requirements:
|
128
|
-
- -
|
142
|
+
- - ">="
|
129
143
|
- !ruby/object:Gem::Version
|
130
144
|
version: '0'
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
146
|
name: shoulda-context
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- -
|
149
|
+
- - ">="
|
136
150
|
- !ruby/object:Gem::Version
|
137
151
|
version: '0'
|
138
152
|
type: :development
|
139
153
|
prerelease: false
|
140
154
|
version_requirements: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
|
-
- -
|
156
|
+
- - ">="
|
143
157
|
- !ruby/object:Gem::Version
|
144
158
|
version: '0'
|
145
159
|
description: A Ruby implementation of OpenXmlPackage
|
@@ -149,16 +163,25 @@ executables: []
|
|
149
163
|
extensions: []
|
150
164
|
extra_rdoc_files: []
|
151
165
|
files:
|
152
|
-
- .gitignore
|
166
|
+
- ".gitignore"
|
153
167
|
- Gemfile
|
154
168
|
- LICENSE.txt
|
155
169
|
- README.md
|
156
170
|
- Rakefile
|
171
|
+
- lib/open_xml/content_types_presets.rb
|
172
|
+
- lib/open_xml/errors.rb
|
173
|
+
- lib/open_xml/package.rb
|
174
|
+
- lib/open_xml/part.rb
|
175
|
+
- lib/open_xml/parts.rb
|
176
|
+
- lib/open_xml/parts/content_types.rb
|
177
|
+
- lib/open_xml/parts/rels.rb
|
178
|
+
- lib/open_xml/parts/unparsed_part.rb
|
179
|
+
- lib/open_xml/rubyzip_fix.rb
|
180
|
+
- lib/open_xml/types.rb
|
157
181
|
- lib/open_xml_package.rb
|
158
|
-
- lib/open_xml_package/part.rb
|
159
|
-
- lib/open_xml_package/rubyzip_fix.rb
|
160
182
|
- lib/open_xml_package/version.rb
|
161
183
|
- open_xml_package.gemspec
|
184
|
+
- test/content_types_test.rb
|
162
185
|
- test/open_xml_package_test.rb
|
163
186
|
- test/support/sample.docx
|
164
187
|
- test/test_helper.rb
|
@@ -172,21 +195,22 @@ require_paths:
|
|
172
195
|
- lib
|
173
196
|
required_ruby_version: !ruby/object:Gem::Requirement
|
174
197
|
requirements:
|
175
|
-
- -
|
198
|
+
- - ">="
|
176
199
|
- !ruby/object:Gem::Version
|
177
200
|
version: '0'
|
178
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
202
|
requirements:
|
180
|
-
- -
|
203
|
+
- - ">"
|
181
204
|
- !ruby/object:Gem::Version
|
182
|
-
version:
|
205
|
+
version: 1.3.1
|
183
206
|
requirements: []
|
184
207
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.2.
|
208
|
+
rubygems_version: 2.2.2
|
186
209
|
signing_key:
|
187
210
|
specification_version: 4
|
188
211
|
summary: A Ruby implementation of OpenXmlPackage
|
189
212
|
test_files:
|
213
|
+
- test/content_types_test.rb
|
190
214
|
- test/open_xml_package_test.rb
|
191
215
|
- test/support/sample.docx
|
192
216
|
- test/test_helper.rb
|