openxml-package 0.2.6 → 0.2.7

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: 5323017681158167286a27e7c26df3781b547b7b
4
- data.tar.gz: 4ab1a1397d8452202ecc02abbb3a484160b9c7f7
3
+ metadata.gz: ae52e67709cf5e65ec3a4dad4c3cd7f88a40b538
4
+ data.tar.gz: 29dfc74ba61458cc74ba029c1a4bc9941d8cbd89
5
5
  SHA512:
6
- metadata.gz: 5e528096108f7b0536aad09ce7ef073c3774766cf506a797cf8807b887d126c8a216490dfbfab4b32ac736a0c7278a6001bd609d635bc570368d04b91e9b6e41
7
- data.tar.gz: 6b9897eae69205b5d1e4f6723ca092569fe348775c265c3a6b38e5531e91abe52c7464cd09e0f87f79791752a289d96e0b6299901711da1e45c6d05b0ad1badf
6
+ metadata.gz: 08a1895d8a8e4c2c5324efa071d7635b214cebd99a1619fa3620072a3d876c9953fe191db353a8a2b78ed13f55fcc5e969366ae70975870da48d6acddb1f9f6d
7
+ data.tar.gz: 3255c8264fa47faf23980a903042a43dc155875a48a1dfc5eddae57c6bc7f61f2b650c4ca9b60be56939aa002b30550aa57a10deeb7c8bbdbb615c4d7af2e6b4
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ # .travis.yml
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ script:
6
+ - bundle exec rake test
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # OpenXml::Package
2
2
 
3
- A Ruby implementation of [DocumentFormat.OpenXml.Packaging.OpenXmlPackage](http://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.openxmlpackage_members(v=office.14).aspx) from Microsoft's Open XML SDK.
3
+ [![Gem Version](https://badge.fury.io/rb/openxml-package.svg)](https://rubygems.org/gems/openxml-package)
4
+ [![Code Climate](https://codeclimate.com/github/openxml/openxml-package.svg)](https://codeclimate.com/github/openxml/openxml-package)
5
+ [![Build Status](https://travis-ci.org/openxml/openxml-package.svg)](https://travis-ci.org/openxml/openxml-package)
4
6
 
5
- The base class for [Docx::Package](https://github.com/openxml/openxml-docx/blob/master/lib/openxml/docx/package.rb), [Xlsx::Package](https://github.com/openxml/openxml-xlsx/blob/master/lib/openxml/xlsx/package.rb), and [Pptx::Package](https://github.com/openxml/openxml-pptx).
7
+ A Ruby implementation of [DocumentFormat.OpenXml.Packaging.OpenXmlPackage](https://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.openxmlpackage_members.aspx) from Microsoft's Open XML SDK.
8
+
9
+ The base class for [OpenXml::Docx::Package](https://github.com/openxml/openxml-docx/blob/master/lib/openxml/docx/package.rb), [OpenXml::Xlsx::Package](https://github.com/openxml/openxml-xlsx/blob/master/lib/openxml/xlsx/package.rb), and [OpenXml::Pptx::Package](https://github.com/openxml/openxml-pptx/blob/master/lib/openxml/xlsx/package.rb).
6
10
 
7
11
 
8
12
  ## Installation
@@ -40,7 +44,7 @@ package.write_to "~/Desktop/output.zip"
40
44
  You can read the contents of an Open XML Package:
41
45
 
42
46
  ```ruby
43
- OpenXmlPackage.open("~/Desktop/output.zip") do |package|
47
+ OpenXml::Package.open("~/Desktop/output.zip") do |package|
44
48
  package.parts.keys # => ["content/document.xml", "media/image.png"]
45
49
  end
46
50
  ```
@@ -1,3 +1,3 @@
1
1
  module OpenXmlPackage
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -9,17 +9,17 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Bob Lail"]
10
10
  spec.email = ["bob.lailfamily@gmail.com"]
11
11
 
12
- spec.summary = %q{A Ruby implementation of OpenXmlPackage}
13
- spec.description = %q{A Ruby implementation of OpenXmlPackage}
14
- spec.license = "MIT"
12
+ spec.summary = %q{A Ruby implementation of OpenXmlPackage from Microsoft's Open XML SDK}
13
+ spec.description = %q{A Ruby implementation of OpenXmlPackage from Microsoft's Open XML SDK}
15
14
  spec.homepage = "https://github.com/openxml/openxml-package"
15
+ spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "rubyzip", "~> 1.1.0"
22
+ spec.add_dependency "rubyzip", "~> 1.2.1"
23
23
  spec.add_dependency "nokogiri"
24
24
  spec.add_dependency "ox"
25
25
 
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 1.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -198,7 +198,7 @@ dependencies:
198
198
  - - ">="
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
- description: A Ruby implementation of OpenXmlPackage
201
+ description: A Ruby implementation of OpenXmlPackage from Microsoft's Open XML SDK
202
202
  email:
203
203
  - bob.lailfamily@gmail.com
204
204
  executables: []
@@ -206,6 +206,7 @@ extensions: []
206
206
  extra_rdoc_files: []
207
207
  files:
208
208
  - ".gitignore"
209
+ - ".travis.yml"
209
210
  - Gemfile
210
211
  - LICENSE.txt
211
212
  - README.md
@@ -225,14 +226,6 @@ files:
225
226
  - lib/openxml/rubyzip_fix.rb
226
227
  - lib/openxml/types.rb
227
228
  - openxml-package.gemspec
228
- - test/content_types_test.rb
229
- - test/element_test.rb
230
- - test/package_test.rb
231
- - test/part_test.rb
232
- - test/rels_test.rb
233
- - test/support/external_hyperlink.docx
234
- - test/support/sample.docx
235
- - test/test_helper.rb
236
229
  - tmp/.keep
237
230
  homepage: https://github.com/openxml/openxml-package
238
231
  licenses:
@@ -254,16 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
247
  version: '0'
255
248
  requirements: []
256
249
  rubyforge_project:
257
- rubygems_version: 2.4.5.1
250
+ rubygems_version: 2.5.1
258
251
  signing_key:
259
252
  specification_version: 4
260
- summary: A Ruby implementation of OpenXmlPackage
261
- test_files:
262
- - test/content_types_test.rb
263
- - test/element_test.rb
264
- - test/package_test.rb
265
- - test/part_test.rb
266
- - test/rels_test.rb
267
- - test/support/external_hyperlink.docx
268
- - test/support/sample.docx
269
- - test/test_helper.rb
253
+ summary: A Ruby implementation of OpenXmlPackage from Microsoft's Open XML SDK
254
+ test_files: []
@@ -1,34 +0,0 @@
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
data/test/element_test.rb DELETED
@@ -1,38 +0,0 @@
1
- require "test_helper"
2
-
3
- class ElementTest < ActiveSupport::TestCase
4
- attr_reader :element
5
-
6
- setup do
7
- @element = OpenXml::Builder::Element.new("tag")
8
- end
9
-
10
- context "The element" do
11
- should "correctly assign attributes" do
12
- element[:attribute] = "value"
13
- element["namespaced:attribute"] = "value"
14
- dump = Ox.dump(element.__getobj__)
15
- assert_equal "\n<tag attribute=\"value\" namespaced:attribute=\"value\"/>\n", dump
16
- end
17
-
18
- should "parse out available namespace prefixes from namespace definition attributes" do
19
- nsdef_prefix = "xmlns:namespace"
20
- nsdef_uri = "http://schema.somenamespace.org/"
21
- element[nsdef_prefix] = nsdef_uri
22
- assert_equal [:namespace], element.namespaces
23
- end
24
-
25
- should "only parse namespace definition attributes with a prefix" do
26
- element["xmlns"] = "http://schema.somenamespace.org/"
27
- assert element.namespaces.empty?
28
- end
29
-
30
- should "correctly use a namespace prefix" do
31
- element.namespace = "namespace"
32
- dump = Ox.dump(element.__getobj__)
33
- assert_equal "\n<namespace:tag/>\n", dump
34
- end
35
- end
36
-
37
-
38
- end
data/test/package_test.rb DELETED
@@ -1,163 +0,0 @@
1
- require "test_helper"
2
- require "fileutils"
3
- require "set"
4
-
5
- class OpenXmlPackageTest < ActiveSupport::TestCase
6
- attr_reader :package, :temp_file
7
-
8
-
9
-
10
- context "#add_part" do
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
16
- end
17
- end
18
-
19
-
20
-
21
- context "Writing" do
22
- setup do
23
- @temp_file = expand_path "../tmp/test.zip"
24
- FileUtils.rm temp_file, force: true
25
- end
26
-
27
- context "Given a simple part" do
28
- setup do
29
- @package = OpenXml::Package.new
30
- package.add_part "content/document.xml", OpenXml::Parts::UnparsedPart.new(document_content)
31
- end
32
-
33
- should "write a valid zip file with the expected parts" do
34
- package.write_to temp_file
35
- assert File.exists?(temp_file), "Expected the file #{temp_file.inspect} to have been created"
36
- assert_equal %w{[Content_Types].xml _rels/.rels content/document.xml},
37
- Zip::File.open(temp_file).entries.map(&:name)
38
- end
39
- end
40
- end
41
-
42
-
43
-
44
- context "Reading" do
45
- context "Given a sample Word document" do
46
- setup do
47
- @temp_file = expand_path "./support/sample.docx"
48
- @expected_contents = Set[
49
- "[Content_Types].xml",
50
- "_rels/.rels",
51
- "docProps/app.xml",
52
- "docProps/core.xml",
53
- "docProps/thumbnail.jpeg",
54
- "word/_rels/document.xml.rels",
55
- "word/document.xml",
56
- "word/fontTable.xml",
57
- "word/media/image1.png",
58
- "word/settings.xml",
59
- "word/styles.xml",
60
- "word/stylesWithEffects.xml",
61
- "word/theme/theme1.xml",
62
- "word/webSettings.xml" ]
63
- end
64
-
65
- context ".open" do
66
- setup do
67
- @package = OpenXml::Package.open(temp_file)
68
- end
69
-
70
- teardown do
71
- package.close
72
- end
73
-
74
- should "discover the expected parts" do
75
- assert_equal @expected_contents, package.parts.keys.to_set
76
- end
77
-
78
- should "read their content on-demand" do
79
- assert_equal web_settings_content, package.get_part("word/webSettings.xml").content
80
- end
81
- end
82
-
83
- context ".from_stream" do
84
- setup do
85
- @package = OpenXml::Package.from_stream(File.open(temp_file, "rb", &:read))
86
- end
87
-
88
- should "also discover the expected parts" do
89
- assert_equal @expected_contents, package.parts.keys.to_set
90
- end
91
-
92
- should "read their content" do
93
- assert_equal web_settings_content, package.get_part("word/webSettings.xml").content
94
- end
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
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
141
- end
142
-
143
-
144
-
145
- private
146
-
147
- def document_content
148
- <<-STR
149
- <document>
150
- <body>Works!</body>
151
- </document>
152
- STR
153
- end
154
-
155
- def web_settings_content
156
- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n<w:webSettings xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" mc:Ignorable=\"w14\"><w:allowPNG/><w:doNotSaveAsSingleFile/></w:webSettings>"
157
- end
158
-
159
- def expand_path(path)
160
- File.expand_path(File.join(File.dirname(__FILE__), path))
161
- end
162
-
163
- end
data/test/part_test.rb DELETED
@@ -1,91 +0,0 @@
1
- require "test_helper"
2
- require "fileutils"
3
- require "set"
4
-
5
- class PartTest < ActiveSupport::TestCase
6
- attr_reader :part, :builder
7
-
8
-
9
-
10
- context "Building" do
11
- setup do
12
- @part = OpenXml::Part.new
13
- end
14
-
15
- context "Given simple xml for one part" do
16
- setup do
17
- @builder = @part.build_xml do |xml|
18
- xml.document do |xml|
19
- 2.times { xml.child(attribute: "value", other_attr: "other value") }
20
- end
21
- end
22
- end
23
-
24
- should "build the expected xml" do
25
- assert_equal basic_xml, builder.to_s(debug: true)
26
- end
27
- end
28
-
29
- context "Given namespaced xml for one part" do
30
- setup do
31
- @builder = @part.build_xml do |xml|
32
- xml.document("xmlns:ns" => "some:namespace:uri") do
33
- 2.times { xml["ns"].child(attribute: "value", other_attr: "other value") }
34
- end
35
- end
36
- end
37
-
38
- should "build the expected xml" do
39
- assert_equal namespaced_xml, builder.to_s(debug: true)
40
- end
41
- end
42
-
43
- context "For a standalone XML element" do
44
- setup do
45
- @builder = @part.build_standalone_xml do |xml|
46
- xml.document do
47
- xml.child(attribute: "value", other_attr: "other value")
48
- end
49
- end
50
- end
51
-
52
- should "build the expected xml" do
53
- assert_equal standalone_xml, builder.to_s(debug: true)
54
- end
55
- end
56
- end
57
-
58
-
59
-
60
- private
61
-
62
- def basic_xml
63
- <<-STR.strip
64
- <?xml version="1.0" encoding="utf-8"?>
65
- <document>
66
- <child attribute="value" other_attr="other value"/>
67
- <child attribute="value" other_attr="other value"/>
68
- </document>
69
- STR
70
- end
71
-
72
- def namespaced_xml
73
- <<-STR.strip
74
- <?xml version="1.0" encoding="utf-8"?>
75
- <document xmlns:ns="some:namespace:uri">
76
- <ns:child attribute="value" other_attr="other value"/>
77
- <ns:child attribute="value" other_attr="other value"/>
78
- </document>
79
- STR
80
- end
81
-
82
- def standalone_xml
83
- <<-STR.strip
84
- <?xml version="1.0" encoding="utf-8" standalone="yes"?>
85
- <document>
86
- <child attribute="value" other_attr="other value"/>
87
- </document>
88
- STR
89
- end
90
-
91
- end
data/test/rels_test.rb DELETED
@@ -1,15 +0,0 @@
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
Binary file
Binary file
data/test/test_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- require "rubygems"
2
-
3
- require "simplecov"
4
- SimpleCov.start do
5
- add_filter "test/"
6
- end
7
-
8
- require "rails"
9
- require "rails/test_help"
10
- require "pry"
11
- require "rr"
12
- require "shoulda/context"
13
- require "minitest/reporters/turn_reporter"
14
- MiniTest::Reporters.use! Minitest::Reporters::TurnReporter.new
15
-
16
- require "openxml/package"