epub-maker 0.0.2 → 0.0.3

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: 0f7686e5d9b95fd78315282adc67a221417f66c6
4
- data.tar.gz: d8c453ee610a382d3bd313c8faee92c5c3e2d86a
3
+ metadata.gz: b0bd5ce3c4ef3e3461c4148891ec762164f635b7
4
+ data.tar.gz: a102f5e8bfb4743d2e585127d7174dae326abb7b
5
5
  SHA512:
6
- metadata.gz: 73ff726291b887c4de99e76e169e02a3e0f1cc9dc15491f527ff1604b563bae295982e3805c3e70801377462b48c62e56a30c61f351fb0fa6e259dc0a1172469
7
- data.tar.gz: 840a22921fdfa05a16e85a5a08d778812e341d4d36d2dd5d05b4c4a687681148da473aea105129d1b50193fe22c382938fe1f6b54879b30ac0c4f386055a19ba
6
+ metadata.gz: 33e8be24da60d5eafb31c24784d0cf51440c3660e9ce6e86047d2c4a89b83e5dbed14efff60ff4148ed1224b2a3eb7c1008d17d99eba5a98466a70b302962987
7
+ data.tar.gz: 1a2272a5ad1f6a09e2e353fc7dc0c65bad265e2921c63cac2a9c8ddf14e2e3344e0a30661de2570be8823f8988350d0d1a8048a0a58ffba86a3476068d60a04b
@@ -1,3 +1,9 @@
1
+ 0.0.3
2
+ -----
3
+
4
+ * Bump up required Ruby version: >= 2.0.0 -> >= 2.1.0
5
+ * Use PhysicalContainer to save contents into EPUB file
6
+
1
7
  0.0.2
2
8
  -----
3
9
 
@@ -133,8 +133,8 @@ For APIs of parsed EPUB book, see [EPUB Parser's documentation][epub-parser-doc]
133
133
 
134
134
  Requirements
135
135
  ------------
136
- * Ruby 2.0 or later
137
- * C compiler to build zipruby and Nokogiri gems
136
+ * Ruby 2.1 or later
137
+ * C compiler to build Nokogiri gems
138
138
 
139
139
  Todo
140
140
  ----
@@ -145,6 +145,9 @@ Todo
145
145
 
146
146
  Recent Changes
147
147
  --------------
148
+ ### 0.0.3
149
+ * Bump up required Ruby version: >= 2.0.0 -> >= 2.1.0
150
+
148
151
  ### 0.0.2
149
152
  * Detect media type of files more strictly
150
153
  * Keep temporary directory remained on error in `EPUB::Maker.make`
@@ -18,9 +18,8 @@ Gem::Specification.new do |gem|
18
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
20
  gem.require_paths = ["lib"]
21
- gem.required_ruby_version = '>= 2.0.0'
21
+ gem.required_ruby_version = '>= 2.1.0'
22
22
 
23
- gem.add_runtime_dependency 'zipruby'
24
23
  gem.add_runtime_dependency 'epub-parser', '>= 0.2.0'
25
24
  gem.add_runtime_dependency 'pathname-common_prefix'
26
25
  gem.add_runtime_dependency 'mimemagic'
@@ -29,14 +28,13 @@ Gem::Specification.new do |gem|
29
28
  gem.add_runtime_dependency 'rake'
30
29
  gem.add_runtime_dependency 'addressable', '>= 2.3.5'
31
30
 
32
- gem.add_development_dependency 'test-unit-full'
31
+ gem.add_development_dependency 'zipruby'
32
+ gem.add_development_dependency 'test-unit'
33
+ gem.add_development_dependency 'test-unit-notify'
33
34
  gem.add_development_dependency 'epubcheck'
34
35
  gem.add_development_dependency 'epzip'
35
36
  gem.add_development_dependency 'simplecov'
36
37
  gem.add_development_dependency 'pry'
37
38
  gem.add_development_dependency 'pry-doc'
38
39
  gem.add_development_dependency 'yard'
39
- gem.add_development_dependency 'redcarpet'
40
- gem.add_development_dependency 'gem-man'
41
- gem.add_development_dependency 'ronn'
42
40
  end
@@ -35,16 +35,16 @@ module EPUB
35
35
  archive.add_entry file
36
36
  end
37
37
 
38
- Zip::Archive.open temp_path.to_path do |archive|
39
- yield book if block_given?
40
- book.save archive
41
- end
38
+ book.epub_file = temp_path.to_path
39
+ yield book if block_given?
40
+ book.save
42
41
 
43
42
  path.open 'wb' do |file|
44
43
  raise Error, "File locked by other process: #{path}" unless file.flock File::LOCK_SH|File::LOCK_NB
45
44
  ($VERBOSE ? ::FileUtils::Verbose : ::FileUtils).move temp_path.to_path, path.to_path
46
45
  end
47
46
  dir.remove_entry_secure
47
+ book.epub_file = path.to_path
48
48
  book
49
49
 
50
50
  # validate
@@ -78,12 +78,12 @@ module EPUB
78
78
  package
79
79
  end
80
80
 
81
- # @param archive [Zip::Archive]
82
- def save(archive)
83
- ocf.save archive
84
- package.save archive
81
+ # @param archive [OCF::PhysicalContainer]
82
+ def save
83
+ ocf.save
84
+ package.save
85
85
  resources.each do |item|
86
- item.save archive
86
+ item.save
87
87
  end
88
88
  end
89
89
  end
@@ -115,14 +115,6 @@ class Pathname
115
115
  FileUtils.remove_entry_secure to_path
116
116
  end
117
117
 
118
- unless method_defined? :write
119
- def write(string, mode='w', perm=0666)
120
- open mode, perm do |file|
121
- file << string
122
- end
123
- end
124
- end
125
-
126
118
  unless method_defined? :/
127
119
  alias / +
128
120
  end
@@ -1,4 +1,5 @@
1
1
  require 'epub/ocf'
2
+ require 'epub/maker/ocf/physical_container'
2
3
 
3
4
  # @todo Use refinement
4
5
  module EPUB
@@ -10,9 +11,8 @@ module EPUB
10
11
  self
11
12
  end
12
13
 
13
- # @param archive [Zip::Archive] path to archive file
14
- def save(archive)
15
- self.container.save archive if self.container
14
+ def save
15
+ book.container_adapter.save book.epub_file, File.join(DIRECTORY, Container::FILE), self.container.to_xml if self.container
16
16
  end
17
17
 
18
18
  # @overload make_container
@@ -41,11 +41,6 @@ module EPUB
41
41
  }.to_xml
42
42
  end
43
43
 
44
- # @param archive [Zip::Archive]
45
- def save(archive)
46
- archive.add_buffer File.join(DIRECTORY, Container::FILE), to_xml
47
- end
48
-
49
44
  # @option full_path [String|nil] full path to package document file in container such like "OPS/content.opf"
50
45
  # @option media_type [String] media type
51
46
  # @yield [Rootfile] rootfile
@@ -0,0 +1,24 @@
1
+ require 'tmpdir'
2
+ require 'epub/ocf/physical_container'
3
+ [
4
+ [:ArchiveZip, 'archive_zip'],
5
+ [:Zipruby, 'zipruby']
6
+ ].each do |(class_name, feature_name)|
7
+ if EPUB::OCF::PhysicalContainer.const_defined? class_name
8
+ require "epub/maker/ocf/physical_container/#{feature_name}"
9
+ end
10
+ end
11
+
12
+ module EPUB
13
+ class OCF
14
+ class PhysicalContainer
15
+ class << self
16
+ def save(container_path, path_name, content)
17
+ open(container_path) {|container|
18
+ container.save(path_name, content)
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'epub/ocf/physical_container/archive_zip'
2
+
3
+ module EPUB
4
+ class OCF
5
+ class PhysicalContainer
6
+ class ArchiveZip < self
7
+ def save(path_name, content)
8
+ ::Dir.mktmpdir do |dir|
9
+ path = ::File.join(dir, ::File.basename(path_name))
10
+ ::File.write path, content
11
+ Archive::Zip.archive @container_path, path, path_prefix: ::File.dirname(path_name)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'epub/ocf/physical_container/zipruby'
2
+
3
+ module EPUB
4
+ class OCF
5
+ class PhysicalContainer
6
+ class Zipruby < self
7
+ def save(path_name, content)
8
+ if @archive
9
+ @archive.add_or_replace_buffer path_name, content
10
+ else
11
+ open {|container| container.save(path_name, content)}
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -40,15 +40,9 @@ module EPUB
40
40
  self
41
41
  end
42
42
 
43
- def edit(archive=nil)
43
+ def edit
44
44
  yield self if block_given?
45
- if archive
46
- save archive
47
- else
48
- Zip::Archive.open manifest.package.book.epub_file do |archive|
49
- save archive
50
- end
51
- end
45
+ save
52
46
  end
53
47
 
54
48
  def make_metadata
@@ -83,8 +77,8 @@ module EPUB
83
77
  bindings
84
78
  end
85
79
 
86
- def save(archive)
87
- archive.add_or_replace_buffer book.rootfile_path, to_xml
80
+ def save
81
+ book.container_adapter.save book.epub_file, book.rootfile_path, to_xml
88
82
  end
89
83
 
90
84
  module ContentModel
@@ -255,22 +249,19 @@ module EPUB
255
249
  class Item
256
250
  attr_accessor :content, :content_file
257
251
 
258
- # @param archive [Zip::Archive|nil] archive to save content. If nil, open archive in this method
259
252
  # @raise StandardError when no content nor content_file
260
- def save(archive=nil)
261
- if archive
253
+ # @todo Don't read content from file when +content_file+ exists. If container adapter is Archive::Zip, it writes content to file twice.
254
+ def save
255
+ content_to_save =
262
256
  if content
263
- archive.add_or_replace_buffer entry_name, content
257
+ content
264
258
  elsif content_file
265
- archive.add_or_replace_file entry_name, content_file
259
+ File.read(content_file)
266
260
  else
267
261
  raise 'no content nor content_file'
268
262
  end
269
- else
270
- Zip::Archive.open manifest.package.book.epub_file do |archive|
271
- save archive
272
- end
273
- end
263
+ book = manifest.package.book
264
+ book.container_adapter.save book.epub_file, entry_name, content_to_save
274
265
  end
275
266
 
276
267
  # Save document into EPUB archive when block ended
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  module Maker
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -3,7 +3,8 @@ SimpleCov.start do
3
3
  add_filter '/test|deps/'
4
4
  end
5
5
 
6
- require 'test/unit/full'
6
+ require 'test/unit'
7
+ require 'test/unit/notify'
7
8
  require 'open3'
8
9
  require 'shellwords'
9
10
  require 'pry'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-04 00:00:00.000000000 Z
11
+ date: 2016-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: zipruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: epub-parser
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -123,21 +109,7 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: 2.3.5
125
111
  - !ruby/object:Gem::Dependency
126
- name: test-unit-full
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: epubcheck
112
+ name: zipruby
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - ">="
@@ -151,7 +123,7 @@ dependencies:
151
123
  - !ruby/object:Gem::Version
152
124
  version: '0'
153
125
  - !ruby/object:Gem::Dependency
154
- name: epzip
126
+ name: test-unit
155
127
  requirement: !ruby/object:Gem::Requirement
156
128
  requirements:
157
129
  - - ">="
@@ -165,7 +137,7 @@ dependencies:
165
137
  - !ruby/object:Gem::Version
166
138
  version: '0'
167
139
  - !ruby/object:Gem::Dependency
168
- name: simplecov
140
+ name: test-unit-notify
169
141
  requirement: !ruby/object:Gem::Requirement
170
142
  requirements:
171
143
  - - ">="
@@ -179,7 +151,7 @@ dependencies:
179
151
  - !ruby/object:Gem::Version
180
152
  version: '0'
181
153
  - !ruby/object:Gem::Dependency
182
- name: pry
154
+ name: epubcheck
183
155
  requirement: !ruby/object:Gem::Requirement
184
156
  requirements:
185
157
  - - ">="
@@ -193,7 +165,7 @@ dependencies:
193
165
  - !ruby/object:Gem::Version
194
166
  version: '0'
195
167
  - !ruby/object:Gem::Dependency
196
- name: pry-doc
168
+ name: epzip
197
169
  requirement: !ruby/object:Gem::Requirement
198
170
  requirements:
199
171
  - - ">="
@@ -207,7 +179,7 @@ dependencies:
207
179
  - !ruby/object:Gem::Version
208
180
  version: '0'
209
181
  - !ruby/object:Gem::Dependency
210
- name: yard
182
+ name: simplecov
211
183
  requirement: !ruby/object:Gem::Requirement
212
184
  requirements:
213
185
  - - ">="
@@ -221,7 +193,7 @@ dependencies:
221
193
  - !ruby/object:Gem::Version
222
194
  version: '0'
223
195
  - !ruby/object:Gem::Dependency
224
- name: redcarpet
196
+ name: pry
225
197
  requirement: !ruby/object:Gem::Requirement
226
198
  requirements:
227
199
  - - ">="
@@ -235,7 +207,7 @@ dependencies:
235
207
  - !ruby/object:Gem::Version
236
208
  version: '0'
237
209
  - !ruby/object:Gem::Dependency
238
- name: gem-man
210
+ name: pry-doc
239
211
  requirement: !ruby/object:Gem::Requirement
240
212
  requirements:
241
213
  - - ">="
@@ -249,7 +221,7 @@ dependencies:
249
221
  - !ruby/object:Gem::Version
250
222
  version: '0'
251
223
  - !ruby/object:Gem::Dependency
252
- name: ronn
224
+ name: yard
253
225
  requirement: !ruby/object:Gem::Requirement
254
226
  requirements:
255
227
  - - ">="
@@ -265,8 +237,7 @@ dependencies:
265
237
  description: This library supports making and editing EPUB books
266
238
  email:
267
239
  - KitaitiMakoto@gmail.com
268
- executables:
269
- - epub-maker
240
+ executables: []
270
241
  extensions: []
271
242
  extra_rdoc_files: []
272
243
  files:
@@ -276,11 +247,13 @@ files:
276
247
  - LICENSE.txt
277
248
  - README.markdown
278
249
  - Rakefile
279
- - bin/epub-maker
280
250
  - epub-maker.gemspec
281
251
  - lib/epub/maker.rb
282
252
  - lib/epub/maker/content_document.rb
283
253
  - lib/epub/maker/ocf.rb
254
+ - lib/epub/maker/ocf/physical_container.rb
255
+ - lib/epub/maker/ocf/physical_container/archive_zip.rb
256
+ - lib/epub/maker/ocf/physical_container/zipruby.rb
284
257
  - lib/epub/maker/publication.rb
285
258
  - lib/epub/maker/task.rb
286
259
  - lib/epub/maker/version.rb
@@ -313,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
313
286
  requirements:
314
287
  - - ">="
315
288
  - !ruby/object:Gem::Version
316
- version: 2.0.0
289
+ version: 2.1.0
317
290
  required_rubygems_version: !ruby/object:Gem::Requirement
318
291
  requirements:
319
292
  - - ">="
@@ -321,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
294
  version: '0'
322
295
  requirements: []
323
296
  rubyforge_project:
324
- rubygems_version: 2.4.6
297
+ rubygems_version: 2.5.1
325
298
  signing_key:
326
299
  specification_version: 4
327
300
  summary: EPUB Maker
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'epub-maker'