openxml-package 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebd723d50d1a88422429fd1400221b2ea4b0fc84
4
+ data.tar.gz: a661bbe8b35316ae02a92de3fcff0dfd38b0d712
5
+ SHA512:
6
+ metadata.gz: a5c67e98dff68d23c8366f12aa78229029a2c55c3ebbbc9578d8e63383f175a625717ff4518e55c982dcb5ebf2bae35546548a29de0ce4ca80c961ba1b115ae5
7
+ data.tar.gz: 20c6d31e69f7d078489d90668c0ab9402699e950aee772571a3cd3be882161235d95ba93ef502b5858d0be348563a29f7537284e7ac7867260779694d7c4a4e7
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .ruby-version
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -1,3 +1,3 @@
1
1
  module OpenXmlPackage
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -11,19 +11,24 @@ module OpenXml
11
11
  attr_reader :parent
12
12
 
13
13
  def initialize(options={})
14
- @options = {
15
- with_xml: true,
16
- encoding: "utf-8"
17
- }.merge(options)
18
- @options[:with_xml] = !!@options[:with_xml] || @options[:standalone] == :yes
14
+ @to_s_options = { with_xml: true }
19
15
 
20
- @document = Ox::Document.new({version: "1.0"}.merge(@options))
16
+ @document = Ox::Document.new(
17
+ encoding: "utf-8",
18
+ version: "1.0",
19
+ standalone: options[:standalone])
21
20
  @parent = @document
22
21
  yield self if block_given?
23
22
  end
24
23
 
25
- def to_s
26
- Ox.dump @document, @options
24
+ def to_s(args={})
25
+ options = @to_s_options
26
+
27
+ # Unless we would like to debug the files,
28
+ # don't add whitespace during generation.
29
+ options = options.merge(indent: -1) unless args[:debug]
30
+
31
+ Ox.dump(@document, options).strip
27
32
  end
28
33
  alias :to_xml :to_s
29
34
 
@@ -4,15 +4,15 @@ module OpenXml
4
4
  class Part
5
5
 
6
6
  def build_xml(options={})
7
- OpenXml::Builder.new(options) { |xml| yield xml }.to_xml
7
+ OpenXml::Builder.new(options) { |xml| yield xml }
8
8
  end
9
9
 
10
10
  def build_standalone_xml(&block)
11
- build_xml({ standalone: :yes }, &block)
11
+ build_xml(standalone: :yes, &block)
12
12
  end
13
13
 
14
14
  def read
15
- strip_whitespace to_xml
15
+ to_xml.to_s
16
16
  end
17
17
  alias :content :read
18
18
 
@@ -20,11 +20,5 @@ module OpenXml
20
20
  raise NotImplementedError
21
21
  end
22
22
 
23
- protected
24
-
25
- def strip_whitespace(xml)
26
- xml.lines.map(&:strip).join
27
- end
28
-
29
23
  end
30
24
  end
@@ -2,7 +2,7 @@ require "test_helper"
2
2
  require "fileutils"
3
3
  require "set"
4
4
 
5
- class OpenXmlPartTest < ActiveSupport::TestCase
5
+ class PartTest < ActiveSupport::TestCase
6
6
  attr_reader :part, :builder
7
7
 
8
8
 
@@ -16,39 +16,51 @@ class OpenXmlPartTest < ActiveSupport::TestCase
16
16
  setup do
17
17
  @builder = @part.build_xml do |xml|
18
18
  xml.document do |xml|
19
- 2.times { xml.child({ attribute: "value", other_attr: "other value" }) }
19
+ 2.times { xml.child(attribute: "value", other_attr: "other value") }
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
24
  should "build the expected xml" do
25
- assert_equal basic_xml, builder.to_s
25
+ assert_equal basic_xml, builder.to_s(debug: true)
26
26
  end
27
27
  end
28
28
 
29
29
  context "Given namespaced xml for one part" do
30
30
  setup do
31
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" }) }
32
+ xml.document("xmlns:ns" => "some:namespace:uri") do
33
+ 2.times { xml["ns"].child(attribute: "value", other_attr: "other value") }
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
38
  should "build the expected xml" do
39
- assert_equal namespaced_xml, builder.to_s
39
+ assert_equal namespaced_xml, builder.to_s(debug: true)
40
40
  end
41
41
  end
42
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
43
56
  end
44
57
 
45
58
 
46
59
 
47
60
  private
48
61
 
49
-
50
62
  def basic_xml
51
- <<-STR
63
+ <<-STR.strip
52
64
  <?xml version="1.0" encoding="utf-8"?>
53
65
  <document>
54
66
  <child attribute="value" other_attr="other value"/>
@@ -58,7 +70,7 @@ private
58
70
  end
59
71
 
60
72
  def namespaced_xml
61
- <<-STR
73
+ <<-STR.strip
62
74
  <?xml version="1.0" encoding="utf-8"?>
63
75
  <document xmlns:ns="some:namespace:uri">
64
76
  <ns:child attribute="value" other_attr="other value"/>
@@ -67,5 +79,13 @@ private
67
79
  STR
68
80
  end
69
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
70
90
 
71
91
  end
metadata CHANGED
@@ -1,228 +1,201 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openxml-package
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bob Lail
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rubyzip
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: nokogiri
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: ox
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '1.6'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '1.6'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rails
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '3.2'
102
- - - <
90
+ - - "<"
103
91
  - !ruby/object:Gem::Version
104
92
  version: '5.0'
105
93
  type: :development
106
94
  prerelease: false
107
95
  version_requirements: !ruby/object:Gem::Requirement
108
- none: false
109
96
  requirements:
110
- - - ! '>='
97
+ - - ">="
111
98
  - !ruby/object:Gem::Version
112
99
  version: '3.2'
113
- - - <
100
+ - - "<"
114
101
  - !ruby/object:Gem::Version
115
102
  version: '5.0'
116
103
  - !ruby/object:Gem::Dependency
117
104
  name: minitest
118
105
  requirement: !ruby/object:Gem::Requirement
119
- none: false
120
106
  requirements:
121
- - - ! '>='
107
+ - - ">="
122
108
  - !ruby/object:Gem::Version
123
109
  version: '0'
124
110
  type: :development
125
111
  prerelease: false
126
112
  version_requirements: !ruby/object:Gem::Requirement
127
- none: false
128
113
  requirements:
129
- - - ! '>='
114
+ - - ">="
130
115
  - !ruby/object:Gem::Version
131
116
  version: '0'
132
117
  - !ruby/object:Gem::Dependency
133
118
  name: minitest-reporters
134
119
  requirement: !ruby/object:Gem::Requirement
135
- none: false
136
120
  requirements:
137
- - - ! '>='
121
+ - - ">="
138
122
  - !ruby/object:Gem::Version
139
123
  version: '0'
140
124
  type: :development
141
125
  prerelease: false
142
126
  version_requirements: !ruby/object:Gem::Requirement
143
- none: false
144
127
  requirements:
145
- - - ! '>='
128
+ - - ">="
146
129
  - !ruby/object:Gem::Version
147
130
  version: '0'
148
131
  - !ruby/object:Gem::Dependency
149
132
  name: minitest-reporters-turn_reporter
150
133
  requirement: !ruby/object:Gem::Requirement
151
- none: false
152
134
  requirements:
153
- - - ! '>='
135
+ - - ">="
154
136
  - !ruby/object:Gem::Version
155
137
  version: '0'
156
138
  type: :development
157
139
  prerelease: false
158
140
  version_requirements: !ruby/object:Gem::Requirement
159
- none: false
160
141
  requirements:
161
- - - ! '>='
142
+ - - ">="
162
143
  - !ruby/object:Gem::Version
163
144
  version: '0'
164
145
  - !ruby/object:Gem::Dependency
165
146
  name: pry
166
147
  requirement: !ruby/object:Gem::Requirement
167
- none: false
168
148
  requirements:
169
- - - ! '>='
149
+ - - ">="
170
150
  - !ruby/object:Gem::Version
171
151
  version: '0'
172
152
  type: :development
173
153
  prerelease: false
174
154
  version_requirements: !ruby/object:Gem::Requirement
175
- none: false
176
155
  requirements:
177
- - - ! '>='
156
+ - - ">="
178
157
  - !ruby/object:Gem::Version
179
158
  version: '0'
180
159
  - !ruby/object:Gem::Dependency
181
160
  name: rr
182
161
  requirement: !ruby/object:Gem::Requirement
183
- none: false
184
162
  requirements:
185
- - - ! '>='
163
+ - - ">="
186
164
  - !ruby/object:Gem::Version
187
165
  version: '0'
188
166
  type: :development
189
167
  prerelease: false
190
168
  version_requirements: !ruby/object:Gem::Requirement
191
- none: false
192
169
  requirements:
193
- - - ! '>='
170
+ - - ">="
194
171
  - !ruby/object:Gem::Version
195
172
  version: '0'
196
173
  - !ruby/object:Gem::Dependency
197
174
  name: simplecov
198
175
  requirement: !ruby/object:Gem::Requirement
199
- none: false
200
176
  requirements:
201
- - - ! '>='
177
+ - - ">="
202
178
  - !ruby/object:Gem::Version
203
179
  version: '0'
204
180
  type: :development
205
181
  prerelease: false
206
182
  version_requirements: !ruby/object:Gem::Requirement
207
- none: false
208
183
  requirements:
209
- - - ! '>='
184
+ - - ">="
210
185
  - !ruby/object:Gem::Version
211
186
  version: '0'
212
187
  - !ruby/object:Gem::Dependency
213
188
  name: shoulda-context
214
189
  requirement: !ruby/object:Gem::Requirement
215
- none: false
216
190
  requirements:
217
- - - ! '>='
191
+ - - ">="
218
192
  - !ruby/object:Gem::Version
219
193
  version: '0'
220
194
  type: :development
221
195
  prerelease: false
222
196
  version_requirements: !ruby/object:Gem::Requirement
223
- none: false
224
197
  requirements:
225
- - - ! '>='
198
+ - - ">="
226
199
  - !ruby/object:Gem::Version
227
200
  version: '0'
228
201
  description: A Ruby implementation of OpenXmlPackage
@@ -232,7 +205,7 @@ executables: []
232
205
  extensions: []
233
206
  extra_rdoc_files: []
234
207
  files:
235
- - .gitignore
208
+ - ".gitignore"
236
209
  - Gemfile
237
210
  - LICENSE.txt
238
211
  - README.md
@@ -262,33 +235,26 @@ files:
262
235
  homepage: https://github.com/openxml/openxml-package
263
236
  licenses:
264
237
  - MIT
238
+ metadata: {}
265
239
  post_install_message:
266
240
  rdoc_options: []
267
241
  require_paths:
268
242
  - lib
269
243
  required_ruby_version: !ruby/object:Gem::Requirement
270
- none: false
271
244
  requirements:
272
- - - ! '>='
245
+ - - ">="
273
246
  - !ruby/object:Gem::Version
274
247
  version: '0'
275
- segments:
276
- - 0
277
- hash: 281021661309613493
278
248
  required_rubygems_version: !ruby/object:Gem::Requirement
279
- none: false
280
249
  requirements:
281
- - - ! '>='
250
+ - - ">="
282
251
  - !ruby/object:Gem::Version
283
252
  version: '0'
284
- segments:
285
- - 0
286
- hash: 281021661309613493
287
253
  requirements: []
288
254
  rubyforge_project:
289
- rubygems_version: 1.8.23.2
255
+ rubygems_version: 2.4.5.1
290
256
  signing_key:
291
- specification_version: 3
257
+ specification_version: 4
292
258
  summary: A Ruby implementation of OpenXmlPackage
293
259
  test_files:
294
260
  - test/content_types_test.rb