epub-maker 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0bd5ce3c4ef3e3461c4148891ec762164f635b7
4
- data.tar.gz: a102f5e8bfb4743d2e585127d7174dae326abb7b
3
+ metadata.gz: 6317049b8e2e449885ad8eb99584c4d50b926250
4
+ data.tar.gz: c5418890d270746471835b7bba2a83fc1ece45a8
5
5
  SHA512:
6
- metadata.gz: 33e8be24da60d5eafb31c24784d0cf51440c3660e9ce6e86047d2c4a89b83e5dbed14efff60ff4148ed1224b2a3eb7c1008d17d99eba5a98466a70b302962987
7
- data.tar.gz: 1a2272a5ad1f6a09e2e353fc7dc0c65bad265e2921c63cac2a9c8ddf14e2e3344e0a30661de2570be8823f8988350d0d1a8048a0a58ffba86a3476068d60a04b
6
+ metadata.gz: c897619e13826f2f3eab0d170bb499f3a55005b519f7892dba768825ea2bf62e9ffdd0340726ea033d7498ff88fea109f1517b4ea2e7c41008b3641aca578116
7
+ data.tar.gz: 80b88d8cbdf531bee5c5d8ce1f5352c85a69d449076711dea1882d3a4070073f1a5698e4a1d7d099f45dc184cc7fd3d5f347d7fdbd12ae35bf1d8857cbbd53d3
@@ -1,3 +1,10 @@
1
+ 0.0.4
2
+ -----
3
+
4
+ * API change: #save -> #write for PhysicalContainer classes
5
+ * Bump required EPUB Parser version: 0.2.0 -> 0.2.6
6
+ * Deprecate `EPUB::OCF::PhysicalContainer.save`
7
+
1
8
  0.0.3
2
9
  -----
3
10
 
@@ -145,6 +145,11 @@ Todo
145
145
 
146
146
  Recent Changes
147
147
  --------------
148
+ ### 0.0.4
149
+ * API change: #save -> #write for PhysicalContainer classes
150
+ * Bump required EPUB Parser version: 0.2.0 -> 0.2.6
151
+ * Deprecate `EPUB::OCF::PhysicalContainer.save`
152
+
148
153
  ### 0.0.3
149
154
  * Bump up required Ruby version: >= 2.0.0 -> >= 2.1.0
150
155
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake/testtask'
2
2
  require 'rake/clean'
3
3
  require 'yard'
4
- require "bundler/gem_tasks"
4
+ require "rubygems/tasks"
5
5
 
6
6
  task :default => :test
7
7
 
@@ -9,3 +9,4 @@ CLEAN.include 'README.html'
9
9
 
10
10
  Rake::TestTask.new
11
11
  YARD::Rake::YardocTask.new
12
+ Gem::Tasks.new
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.require_paths = ["lib"]
21
21
  gem.required_ruby_version = '>= 2.1.0'
22
22
 
23
- gem.add_runtime_dependency 'epub-parser', '>= 0.2.0'
23
+ gem.add_runtime_dependency 'epub-parser', '>= 0.2.6'
24
24
  gem.add_runtime_dependency 'pathname-common_prefix'
25
25
  gem.add_runtime_dependency 'mimemagic'
26
26
  gem.add_runtime_dependency 'ruby-uuid'
@@ -37,4 +37,5 @@ Gem::Specification.new do |gem|
37
37
  gem.add_development_dependency 'pry'
38
38
  gem.add_development_dependency 'pry-doc'
39
39
  gem.add_development_dependency 'yard'
40
+ gem.add_development_dependency 'rubygems-tasks'
40
41
  end
@@ -56,7 +56,9 @@ module EPUB
56
56
  error.message,
57
57
  "[#{self}]Working directory remained at: #{dir}"
58
58
  ].join($RS))
59
- backtrace.unshift("#{__FILE__}:#{__LINE__}:in `rescue in #{__method__}'"); error.set_backtrace backtrace; raise error
59
+ backtrace.unshift("#{__FILE__}:#{__LINE__}:in `rescue in #{__method__}'")
60
+ error.set_backtrace backtrace
61
+ raise error
60
62
  end
61
63
  end
62
64
  end
@@ -71,10 +73,13 @@ module EPUB
71
73
  end
72
74
 
73
75
  def make_package
74
- self.package = Publication::Package.new
76
+ package = Publication::Package.new
77
+ package.book = self
75
78
  package.make do |package|
76
79
  yield package if block_given?
77
80
  end
81
+ no_package_rootfile = rootfiles.find {|rf| rf.package.nil?}
82
+ no_package_rootfile.package = package if no_package_rootfile
78
83
  package
79
84
  end
80
85
 
@@ -12,7 +12,7 @@ module EPUB
12
12
  end
13
13
 
14
14
  def save
15
- book.container_adapter.save book.epub_file, File.join(DIRECTORY, Container::FILE), self.container.to_xml if self.container
15
+ book.container_adapter.write 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
@@ -13,11 +13,16 @@ module EPUB
13
13
  class OCF
14
14
  class PhysicalContainer
15
15
  class << self
16
- def save(container_path, path_name, content)
16
+ def write(container_path, path_name, content)
17
17
  open(container_path) {|container|
18
- container.save(path_name, content)
18
+ container.write(path_name, content)
19
19
  }
20
20
  end
21
+
22
+ def save(container_path, path_name, content)
23
+ warn "EPUB::OCF::PhysicalContainer.#{__method__} is deprecated. Use .write instead"
24
+ write(container_path, path_name, content)
25
+ end
21
26
  end
22
27
  end
23
28
  end
@@ -4,11 +4,34 @@ module EPUB
4
4
  class OCF
5
5
  class PhysicalContainer
6
6
  class ArchiveZip < self
7
- def save(path_name, content)
7
+ # @todo Write multiple files at once
8
+ def write(path_name, content)
8
9
  ::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)
10
+ tmp_archive_path = ::File.join(dir, ::File.basename(@container_path) + '.tmp')
11
+ ::File.open @container_path do |archive_in|
12
+ ::File.open tmp_archive_path, 'w' do |archive_out|
13
+ archive_out.binmode
14
+ Archive::Zip.open archive_in, :r do |z_in|
15
+ Archive::Zip.open archive_out, :w do |z_out|
16
+ updated = false
17
+ z_in.each do |entry|
18
+ if entry.zip_path == path_name
19
+ entry.file_data = StringIO.new(content)
20
+ updated = true
21
+ end
22
+ z_out << entry
23
+ end
24
+ unless updated
25
+ entry = Archive::Zip::Entry::File.new(path_name)
26
+ entry.file_data = StringIO.new(content)
27
+ z_out << entry
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ ::File.chmod 0666 & ~::File.umask, tmp_archive_path
34
+ ::File.rename tmp_archive_path, @container_path
12
35
  end
13
36
  end
14
37
  end
@@ -4,7 +4,7 @@ module EPUB
4
4
  class OCF
5
5
  class PhysicalContainer
6
6
  class Zipruby < self
7
- def save(path_name, content)
7
+ def write(path_name, content)
8
8
  if @archive
9
9
  @archive.add_or_replace_buffer path_name, content
10
10
  else
@@ -78,7 +78,7 @@ module EPUB
78
78
  end
79
79
 
80
80
  def save
81
- book.container_adapter.save book.epub_file, book.rootfile_path, to_xml
81
+ book.container_adapter.write book.epub_file, book.rootfile_path, to_xml
82
82
  end
83
83
 
84
84
  module ContentModel
@@ -261,7 +261,7 @@ module EPUB
261
261
  raise 'no content nor content_file'
262
262
  end
263
263
  book = manifest.package.book
264
- book.container_adapter.save book.epub_file, entry_name, content_to_save
264
+ book.container_adapter.write book.epub_file, entry_name, content_to_save
265
265
  end
266
266
 
267
267
  # Save document into EPUB archive when block ended
@@ -59,6 +59,8 @@ module EPUB
59
59
 
60
60
  if make_rootfiles
61
61
  book.make_package do |package|
62
+ book.ocf.container.rootfile.package = package
63
+
62
64
  package.dir = package_direction
63
65
 
64
66
  package.make_metadata do |metadata|
@@ -109,7 +111,7 @@ module EPUB
109
111
  else
110
112
  raise 'No rootfile set' if @rootfiles.empty?
111
113
  rf = rootfiles.first
112
- book.package = EPUB::Parser::Publication.new(File.read(rf), file_map[rf]).parse
114
+ book.package = EPUB::Parser::Publication.new(File.read(rf)).parse
113
115
  end
114
116
  end
115
117
  end
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  module Maker
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ class TestMakerPublication < Test::Unit::TestCase
7
7
  def setup
8
8
  rootfile = 'OPS/ルートファイル.opf'
9
9
  @opf = File.read(File.expand_path("../fixtures/book/#{rootfile}", __FILE__))
10
- @package = EPUB::Parser::Publication.new(@opf, rootfile).parse
10
+ @package = EPUB::Parser::Publication.new(@opf).parse
11
11
  end
12
12
 
13
13
  def test_to_xml_attribute
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-16 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: epub-parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.2.6
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: 0.2.0
26
+ version: 0.2.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pathname-common_prefix
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rubygems-tasks
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  description: This library supports making and editing EPUB books
238
252
  email:
239
253
  - KitaitiMakoto@gmail.com
@@ -317,4 +331,3 @@ test_files:
317
331
  - test/test_maker_ocf.rb
318
332
  - test/test_maker_publication.rb
319
333
  - test/test_task.rb
320
- has_rdoc: