epub-maker 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +10 -0
- data/CHANGELOG.markdown +7 -1
- data/README.markdown +6 -5
- data/Rakefile +6 -0
- data/epub-maker.gemspec +1 -0
- data/lib/epub/maker/ocf/physical_container.rb +20 -2
- data/lib/epub/maker/ocf/physical_container/archive_zip.rb +8 -2
- data/lib/epub/maker/publication.rb +5 -1
- data/lib/epub/maker/version.rb +1 -1
- data/test/helper.rb +6 -0
- data/test/test_inplace_editing.rb +24 -1
- data/test/test_maker.rb +0 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aeffa7298ad5bb22c54beaa0eaafc0f46cbcd724a950202d917ef9186345a5c
|
4
|
+
data.tar.gz: ea10fe12472421d4585636290c814df4eab87d9d4fc466a480d94d229174d3c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef569b71794f317b6a05136bd94ff9dcee19caa0993d58ab7f1f4d5b03bba2edc9836300892e5b1780ce0afe1b1498b84bfcbd884c9d6fe4ad9e82b1ef191a4
|
7
|
+
data.tar.gz: 39e9011f7bcac33805936f1842959a697bbf8b72d415b7b6cdd82b0dc782548316f369951e7aac68c299f1f50f40058239316868bd55de4841dc92da81775c23
|
data/.gitlab-ci.yml
CHANGED
data/CHANGELOG.markdown
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
0.1.5
|
2
|
+
-----
|
3
|
+
|
4
|
+
* [BUG FIX]Compare path name in the same encoding when finding file in ZIP archive
|
5
|
+
* Add `PhysicalContaienr.mtime` API to set mtime of files in EPUB archive
|
6
|
+
|
1
7
|
0.1.4
|
2
8
|
-----
|
3
9
|
|
4
|
-
* Add `
|
10
|
+
* Add `Publication::Package::Metadata#modified=` method
|
5
11
|
* Rescue Errno::EXDEV on renaming temporary EPUB file
|
6
12
|
|
7
13
|
0.1.3
|
data/README.markdown
CHANGED
@@ -178,19 +178,20 @@ Todo
|
|
178
178
|
Recent Changes
|
179
179
|
--------------
|
180
180
|
|
181
|
+
### 0.1.5
|
182
|
+
|
183
|
+
* [BUG FIX]Compare path name in the same encoding when finding file in ZIP archive
|
184
|
+
* Add `PhysicalContaienr.mtime` API to set mtime of files in EPUB archive
|
185
|
+
|
181
186
|
### 0.1.4
|
182
187
|
|
183
|
-
* Add `
|
188
|
+
* Add `Publication::Package::Metadata#modified=` method
|
184
189
|
* Rescue Errno::EXDEV on renaming temporary EPUB file
|
185
190
|
|
186
191
|
### 0.1.3
|
187
192
|
|
188
193
|
* Add workaround Window file renaming problem
|
189
194
|
|
190
|
-
### 0.1.2
|
191
|
-
|
192
|
-
* Close temp file when archiving EPUB file
|
193
|
-
|
194
195
|
Contributing
|
195
196
|
------------
|
196
197
|
|
data/Rakefile
CHANGED
@@ -2,11 +2,17 @@ require 'rake/testtask'
|
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'yard'
|
4
4
|
require "rubygems/tasks"
|
5
|
+
require "open-uri"
|
5
6
|
|
6
7
|
task :default => :test
|
7
8
|
|
8
9
|
CLEAN.include 'README.html'
|
9
10
|
|
11
|
+
VALID_EPUB = "test/fixtures/accessible_epub_3.epub"
|
12
|
+
file VALID_EPUB do |t|
|
13
|
+
File.write t.name, URI("https://github.com/IDPF/epub3-samples/releases/download/20170606/accessible_epub_3.epub").read
|
14
|
+
end
|
10
15
|
Rake::TestTask.new
|
16
|
+
task test: VALID_EPUB
|
11
17
|
YARD::Rake::YardocTask.new
|
12
18
|
Gem::Tasks.new
|
data/epub-maker.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.add_runtime_dependency 'archive-zip'
|
26
26
|
gem.add_runtime_dependency 'rake'
|
27
27
|
gem.add_runtime_dependency 'addressable', '>= 2.3.5'
|
28
|
+
gem.add_runtime_dependency 'rexml'
|
28
29
|
gem.add_runtime_dependency "nokogiri", ">= 1.6.0", "< 1.11"
|
29
30
|
|
30
31
|
gem.add_development_dependency 'zipruby'
|
@@ -13,15 +13,33 @@ module EPUB
|
|
13
13
|
class OCF
|
14
14
|
class PhysicalContainer
|
15
15
|
class << self
|
16
|
+
@@mtime = nil
|
17
|
+
|
18
|
+
def mtime
|
19
|
+
@@mtime
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets +mtime+, which is used when setting mtime of file in EPUB(ZIP) archive.
|
23
|
+
# Currently supported for only {ArchiveZip} adapter
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# EPUB::OCF::PhysicalCotainer.adapter = :ArchiveZip
|
27
|
+
# EPUB::OCF::PhysicalCotainer.mtime = Time.new(2020, 1, 1)
|
28
|
+
#
|
29
|
+
# @return [Time]
|
30
|
+
def mtime=(time)
|
31
|
+
@@mtime = time
|
32
|
+
end
|
33
|
+
|
16
34
|
def write(container_path, path_name, content)
|
17
35
|
open(container_path) {|container|
|
18
|
-
container.write(path_name, content)
|
36
|
+
container.write(path_name, content, mtime: mtime)
|
19
37
|
}
|
20
38
|
end
|
21
39
|
|
22
40
|
def save(container_path, path_name, content)
|
23
41
|
warn "EPUB::OCF::PhysicalContainer.#{__method__} is deprecated. Use .write instead"
|
24
|
-
write(container_path, path_name, content)
|
42
|
+
write(container_path, path_name, content, mtime: mtime)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
end
|
@@ -5,7 +5,7 @@ module EPUB
|
|
5
5
|
class PhysicalContainer
|
6
6
|
class ArchiveZip < self
|
7
7
|
# @todo Write multiple files at once
|
8
|
-
def write(path_name, content)
|
8
|
+
def write(path_name, content, mtime: nil)
|
9
9
|
::Dir.mktmpdir do |dir|
|
10
10
|
tmp_archive_path = ::File.join(dir, ::File.basename(@container_path) + '.tmp')
|
11
11
|
::File.open @container_path do |archive_in|
|
@@ -15,15 +15,21 @@ module EPUB
|
|
15
15
|
Archive::Zip.open archive_out, :w do |z_out|
|
16
16
|
updated = false
|
17
17
|
z_in.each do |entry|
|
18
|
-
if entry.zip_path == path_name
|
18
|
+
if entry.zip_path == path_name.force_encoding('ASCII-8BIT')
|
19
19
|
entry.file_data = StringIO.new(content)
|
20
20
|
updated = true
|
21
21
|
end
|
22
|
+
if mtime
|
23
|
+
entry.mtime = mtime
|
24
|
+
end
|
22
25
|
z_out << entry
|
23
26
|
end
|
24
27
|
unless updated
|
25
28
|
entry = Archive::Zip::Entry::File.new(path_name)
|
26
29
|
entry.file_data = StringIO.new(content)
|
30
|
+
if mtime
|
31
|
+
entry.mtime = mtime
|
32
|
+
end
|
27
33
|
z_out << entry
|
28
34
|
end
|
29
35
|
end
|
@@ -288,7 +288,11 @@ module EPUB
|
|
288
288
|
elsif content_file
|
289
289
|
File.read(content_file)
|
290
290
|
else
|
291
|
-
|
291
|
+
begin
|
292
|
+
read
|
293
|
+
rescue OCF::PhysicalContainer::NoEntry
|
294
|
+
raise 'no content nor content_file'
|
295
|
+
end
|
292
296
|
end
|
293
297
|
book = manifest.package.book
|
294
298
|
book.container_adapter.write book.epub_file, entry_name, content_to_save
|
data/lib/epub/maker/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -11,6 +11,12 @@ class Test::Unit::TestCase
|
|
11
11
|
def assert_valid_epub(file)
|
12
12
|
assert_true Epubcheck::Ruby::CLI.new.execute(file)
|
13
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_epub
|
18
|
+
Pathname.new("test/fixtures/accessible_epub_3.epub")
|
19
|
+
end
|
14
20
|
end
|
15
21
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
16
22
|
require 'epub'
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
require 'epub/maker'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestInplaceEditing < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@assets_dir = Pathname(__dir__)/'fixtures'/'book'
|
7
7
|
@dir = Pathname.mktmpdir('epub-maker-test')
|
8
8
|
@file = @dir/'book.epub'
|
9
9
|
EPUB::Maker.archive @assets_dir, @file
|
10
10
|
@book = EPUB::Parser.parse(@file)
|
11
|
+
@valid_epub = @dir/valid_epub.basename
|
12
|
+
FileUtils.cp valid_epub, @valid_epub
|
11
13
|
end
|
12
14
|
|
13
15
|
def teardown
|
@@ -57,4 +59,25 @@ class TestImplaceEditing < Test::Unit::TestCase
|
|
57
59
|
|
58
60
|
assert_match '<title>Edited Title</title>', item.read
|
59
61
|
end
|
62
|
+
|
63
|
+
def test_edit_without_change
|
64
|
+
epub = EPUB::Parser.parse(@valid_epub)
|
65
|
+
epub.save
|
66
|
+
assert_equal epub.release_identifier, EPUB::Parser.parse(@valid_epub).release_identifier
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_specify_mtime
|
70
|
+
# Currently, only ArchiveZip supports this API
|
71
|
+
EPUB::OCF::PhysicalContainer.adapter = :ArchiveZip
|
72
|
+
mtime = EPUB::OCF::PhysicalContainer.mtime = Time.new(2020, 1, 1)
|
73
|
+
epub = EPUB::Parser.parse(@valid_epub)
|
74
|
+
epub.metadata.unique_identifier.content = "new-unique-identifier"
|
75
|
+
epub.package.save
|
76
|
+
|
77
|
+
Archive::Zip.open @valid_epub.to_path do |z|
|
78
|
+
z.each do |entry|
|
79
|
+
assert_equal mtime, entry.mtime
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
60
83
|
end
|
data/test/test_maker.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: epub-parser
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.3.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rexml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: nokogiri
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -288,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
302
|
- !ruby/object:Gem::Version
|
289
303
|
version: '0'
|
290
304
|
requirements: []
|
291
|
-
rubygems_version: 3.1.
|
305
|
+
rubygems_version: 3.1.4
|
292
306
|
signing_key:
|
293
307
|
specification_version: 4
|
294
308
|
summary: EPUB Maker
|