epub-parser 0.4.7 → 0.4.9
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 +4 -4
- data/.gitignore +3 -0
- data/.gitlab-ci.yml +21 -25
- data/CHANGELOG.adoc +12 -0
- data/Gemfile +13 -5
- data/README.adoc +10 -24
- data/Rakefile +1 -54
- data/docs/Searcher.adoc +1 -1
- data/epub-parser.gemspec +4 -5
- data/lib/epub/content_document/typable.rb +0 -2
- data/lib/epub/ocf/physical_container/archive_zip.rb +16 -2
- data/lib/epub/ocf/physical_container/rubyzip.rb +38 -0
- data/lib/epub/parser/metadata.rb +1 -1
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/searcher/publication.rb +1 -2
- data/rakelib/doc.rake +30 -0
- data/rakelib/test.rake +45 -0
- data/rbs_collection.yaml +19 -0
- data/test/helper.rb +30 -5
- data/test/test_content_document.rb +10 -1
- data/test/test_inspect.rb +1 -1
- data/test/test_ocf_physical_container.rb +2 -54
- data/test/test_ocf_physical_container_base.rb +10 -0
- data/test/test_ocf_physical_container_rubyzip.rb +13 -0
- data/test/test_ocf_physical_container_zipruby.rb +16 -0
- data/test/test_parser_ocf.rb +4 -4
- metadata +28 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 399a60256947a87d2dc3ada4b348cffeb99ac9d3ed9dcbe5159b4d6ca02d1dff
|
4
|
+
data.tar.gz: f9ed100e463cc3a60071b7074ebc4a6dd141fac397762697b39b549bb13025f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f320d4d2ed30d1d2b65db4bf67f4c66dfb4aea66911bd2de9b1b6b8d93e1caa093f4c4cf9c1d595d81744633c4333f5e126c0ae3f6573d9b7fb9c3702987bf3
|
7
|
+
data.tar.gz: 95cf359e907036d9f4046c4eb7c1bc8eec577c3c78ef31629cae8b9cfd3b8f8c81190ac18b7d639918ccaabc054ca2c5dcddf7f05733c2e05f7b9170463e9bbd
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -1,78 +1,74 @@
|
|
1
1
|
before_script:
|
2
2
|
- ruby -v
|
3
3
|
- which ruby
|
4
|
-
- gem install bundler --no-document
|
5
4
|
- bundle install --jobs=$(nproc) --path=deps "${FLAGS[@]}"
|
6
5
|
- bundle clean
|
7
6
|
|
8
|
-
test:2.
|
9
|
-
image: ruby:2.
|
7
|
+
test:2.7:
|
8
|
+
image: ruby:2.7
|
10
9
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
11
10
|
except:
|
12
11
|
- tags
|
13
12
|
cache:
|
14
|
-
key: ruby:2.
|
13
|
+
key: ruby:2.7
|
15
14
|
paths:
|
16
15
|
- deps
|
17
16
|
|
18
|
-
test:
|
19
|
-
image: ruby:
|
17
|
+
test:3.0:
|
18
|
+
image: ruby:3.0
|
20
19
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
21
20
|
except:
|
22
21
|
- tags
|
23
22
|
cache:
|
24
|
-
key: ruby:
|
23
|
+
key: ruby:3.0
|
25
24
|
paths:
|
26
25
|
- deps
|
27
26
|
|
28
|
-
test:
|
29
|
-
image: ruby:
|
27
|
+
test:3.1:
|
28
|
+
image: ruby:3.1
|
30
29
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
31
30
|
except:
|
32
31
|
- tags
|
33
|
-
artifacts:
|
34
|
-
paths:
|
35
|
-
- coverage
|
36
32
|
cache:
|
37
|
-
key: ruby:
|
33
|
+
key: ruby:3.1
|
38
34
|
paths:
|
39
35
|
- deps
|
40
36
|
|
41
|
-
test:2
|
42
|
-
image: ruby:2
|
37
|
+
test:3.2:
|
38
|
+
image: ruby:3.2
|
43
39
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
44
40
|
except:
|
45
41
|
- tags
|
46
42
|
cache:
|
47
|
-
key: ruby:2
|
43
|
+
key: ruby:3.2
|
48
44
|
paths:
|
49
45
|
- deps
|
50
46
|
|
51
|
-
test:
|
52
|
-
image: ruby:
|
47
|
+
test:3.3:
|
48
|
+
image: ruby:3.3
|
53
49
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
54
50
|
except:
|
55
51
|
- tags
|
56
52
|
cache:
|
57
|
-
key: ruby:
|
53
|
+
key: ruby:3.3
|
58
54
|
paths:
|
59
55
|
- deps
|
60
56
|
|
61
|
-
test:3.
|
62
|
-
image: ruby:3.
|
57
|
+
test:3.4:
|
58
|
+
image: ruby:3.4
|
63
59
|
script: bundle exec rake test XML_BACKEND=REXML 2>/dev/null && bundle exec rake test XML_BACKEND=Oga 2>/dev/null && bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
|
64
60
|
except:
|
65
61
|
- tags
|
66
62
|
cache:
|
67
|
-
key: ruby:3.
|
63
|
+
key: ruby:3.4
|
68
64
|
paths:
|
69
65
|
- deps
|
70
66
|
|
71
67
|
pages:
|
72
68
|
stage: deploy
|
73
|
-
image: ruby:
|
69
|
+
image: ruby:3.4
|
74
70
|
dependencies:
|
75
|
-
- test:
|
71
|
+
- test:3.4
|
76
72
|
script:
|
77
73
|
- bundle exec rake test doc:yard
|
78
74
|
- mv doc public
|
@@ -83,6 +79,6 @@ pages:
|
|
83
79
|
only:
|
84
80
|
- master
|
85
81
|
cache:
|
86
|
-
key: ruby:
|
82
|
+
key: ruby:3.4
|
87
83
|
paths:
|
88
84
|
- deps
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= CHANGELOG
|
2
2
|
|
3
|
+
== 0.4.9
|
4
|
+
|
5
|
+
* Restructure test
|
6
|
+
* Restructure Rake tasks
|
7
|
+
* Update required Ruby version to 2.6
|
8
|
+
* Follow Ruby 3.5 inspection change
|
9
|
+
* Follow Archive::Zip API change
|
10
|
+
|
11
|
+
== 0.4.8
|
12
|
+
|
13
|
+
* Add Rubyzip adapter
|
14
|
+
|
3
15
|
== 0.4.7
|
4
16
|
|
5
17
|
* [BUG FIX]Fix a bug that epubinfo doesn't handle navigation properly
|
data/Gemfile
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
gem
|
4
|
+
group :development do
|
5
|
+
if ENV["EPUB_CFI_PATH"]
|
6
|
+
gem "epub-cfi", path: ENV["EPUB_CFI_PATH"]
|
7
|
+
end
|
8
|
+
|
9
|
+
if ENV['EPUB_MAKER_PATH']
|
10
|
+
gem 'epub-maker', path: ENV["EPUB_MAKER_PATH"]
|
11
|
+
end
|
12
|
+
|
13
|
+
if RUBY_PLATFORM.match /darwin/
|
14
|
+
gem 'terminal-notifier'
|
7
15
|
end
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
gem
|
18
|
+
group :development, :test do
|
19
|
+
gem "ffi", "~> 1.16.3" if RbConfig::CONFIG["MAJOR"] == "2"
|
12
20
|
end
|
data/README.adoc
CHANGED
@@ -176,35 +176,21 @@ If you find other gems, please tell me or request a pull request.
|
|
176
176
|
|
177
177
|
== RECENT CHANGES
|
178
178
|
|
179
|
-
=== 0.4.
|
180
|
-
|
181
|
-
* [BUG FIX]Fix a bug that epubinfo doesn't handle navigation properly
|
182
|
-
|
183
|
-
=== 0.4.6
|
184
|
-
|
185
|
-
* [BUG FIX]Prevent epubinfo tool raise exception when no nav elements
|
186
|
-
* Tiny modifcation on Zip archive manipulation
|
187
|
-
* Remove version specification from Nokogiri to migrate to Ruby 3.1
|
188
|
-
|
189
|
-
=== 0.4.5
|
179
|
+
=== 0.4.9
|
190
180
|
|
191
|
-
*
|
181
|
+
* Restructure test
|
182
|
+
* Restructure Rake tasks
|
183
|
+
* Update required Ruby version to 2.6
|
184
|
+
* Follow Ruby 3.5 inspection change
|
185
|
+
* Follow Archive::Zip API change
|
192
186
|
|
193
|
-
=== 0.4.
|
187
|
+
=== 0.4.8
|
194
188
|
|
195
|
-
*
|
196
|
-
* Add feature to show navigations to `epubinfo` command-line tool
|
189
|
+
* Add Rubyzip adapter
|
197
190
|
|
198
|
-
=== 0.4.
|
199
|
-
|
200
|
-
* Encode file name passed from file system on Unix
|
201
|
-
|
202
|
-
=== 0.4.2
|
203
|
-
|
204
|
-
* [BUG FIX]Fix a bug that epub-cover refers out of scope variable
|
191
|
+
=== 0.4.7
|
205
192
|
|
206
|
-
* [BUG FIX]Fix a bug that
|
207
|
-
* [BUG FIX]Fix a bug that REXML::Element#content ignores descendant nodes
|
193
|
+
* [BUG FIX]Fix a bug that epubinfo doesn't handle navigation properly
|
208
194
|
|
209
195
|
See {file:CHANGELOG.adoc} for older changelogs and details.
|
210
196
|
|
data/Rakefile
CHANGED
@@ -1,60 +1,7 @@
|
|
1
1
|
require 'rake/clean'
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'rubygems/tasks'
|
4
|
-
require 'yard'
|
5
|
-
require 'rdoc/task'
|
6
|
-
require 'archive/zip'
|
7
|
-
require 'epub/maker'
|
8
|
-
require "tmpdir"
|
9
3
|
|
10
4
|
task :default => :test
|
11
|
-
task :test => 'test:default'
|
12
5
|
|
13
|
-
|
14
|
-
task :default => [:build, :test]
|
15
|
-
|
16
|
-
desc 'Build test fixture EPUB file'
|
17
|
-
task :build => [:clean, "test/fixtures/book.epub"]
|
18
|
-
|
19
|
-
file "test/fixtures/book.epub" => "test/fixtures/book" do |task|
|
20
|
-
EPUB::Maker.archive task.source
|
21
|
-
# We cannot include "CASE-SENSITIVE.xhtml" in Git repository because
|
22
|
-
# macOS remove it or case-sensitive.xhtml from file system.
|
23
|
-
small_file = File.read("#{task.source}/OPS/case-sensitive.xhtml")
|
24
|
-
Dir.mktmpdir do |dir|
|
25
|
-
upcase_file_path = File.join(dir, "CASE-SENSITIVE.xhtml")
|
26
|
-
File.write upcase_file_path, small_file.sub('small file name', 'LARGE FILE NAME')
|
27
|
-
Archive::Zip.archive task.name, upcase_file_path, path_prefix: "OPS"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
CLEAN.include "test/fixtures/book.epub"
|
31
|
-
|
32
|
-
Rake::TestTask.new do |task|
|
33
|
-
task.test_files = FileList['test/**/test_*.rb']
|
34
|
-
task.warning = true
|
35
|
-
task.options = '--no-show-detail-immediately --verbose'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
task :doc => 'doc:default'
|
40
|
-
|
41
|
-
namespace :doc do
|
42
|
-
task :default => [:yard, :rdoc]
|
43
|
-
|
44
|
-
YARD::Rake::YardocTask.new
|
45
|
-
Rake::RDocTask.new do |rdoc|
|
46
|
-
rdoc.rdoc_files.include %w[
|
47
|
-
lib/**/*.rb
|
48
|
-
README.adoc
|
49
|
-
CHANGELOG.adoc
|
50
|
-
MIT-LICENSE
|
51
|
-
docs/**/*.adoc
|
52
|
-
docs/**/*.md
|
53
|
-
]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
Gem::Tasks.new do |tasks|
|
58
|
-
tasks.console.command = 'pry'
|
59
|
-
end
|
6
|
+
Gem::Tasks.new
|
60
7
|
task :build => :clean
|
data/docs/Searcher.adoc
CHANGED
data/epub-parser.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{EPUB 3 Parser}
|
12
12
|
s.description = %q{Parse EPUB 3 book loosely}
|
13
13
|
s.license = 'MIT'
|
14
|
-
s.required_ruby_version = '>= 2.
|
14
|
+
s.required_ruby_version = '>= 2.6'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
.push('test/fixtures/book/OPS/ルートファイル.opf')
|
@@ -27,9 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.add_development_dependency 'rake'
|
29
29
|
s.add_development_dependency 'rubygems-tasks'
|
30
|
-
s.add_development_dependency 'zipruby'
|
31
|
-
s.add_development_dependency '
|
32
|
-
s.add_development_dependency 'pry-doc'
|
30
|
+
s.add_development_dependency 'zipruby'
|
31
|
+
s.add_development_dependency 'rubyzip', '>= 2.0.0'
|
33
32
|
s.add_development_dependency 'test-unit'
|
34
33
|
s.add_development_dependency 'test-unit-rr'
|
35
34
|
s.add_development_dependency 'test-unit-notify'
|
@@ -37,12 +36,12 @@ Gem::Specification.new do |s|
|
|
37
36
|
s.add_development_dependency 'yard'
|
38
37
|
s.add_development_dependency 'gem-man'
|
39
38
|
s.add_development_dependency 'ronn-ng'
|
40
|
-
s.add_development_dependency 'pretty_backtrace'
|
41
39
|
s.add_development_dependency 'epub-maker'
|
42
40
|
s.add_development_dependency 'asciidoctor'
|
43
41
|
s.add_development_dependency 'nokogiri'
|
44
42
|
s.add_development_dependency 'oga', '>= 2.16'
|
45
43
|
s.add_development_dependency 'packnga'
|
44
|
+
s.add_development_dependency "steep"
|
46
45
|
|
47
46
|
s.add_runtime_dependency 'archive-zip'
|
48
47
|
s.add_runtime_dependency 'rexml'
|
@@ -29,7 +29,7 @@ module EPUB
|
|
29
29
|
@archive.each.with_index do |entry, index|
|
30
30
|
if target_index
|
31
31
|
if target_index == index
|
32
|
-
return entry
|
32
|
+
return read_content(entry)
|
33
33
|
else
|
34
34
|
next
|
35
35
|
end
|
@@ -40,7 +40,7 @@ module EPUB
|
|
40
40
|
@entries[entry_path] = index
|
41
41
|
@last_iterated_entry_index = index
|
42
42
|
if entry_path == path_name
|
43
|
-
return entry
|
43
|
+
return read_content(entry)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,6 +49,20 @@ module EPUB
|
|
49
49
|
open {|container| container.read(path_name)}
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def read_content(entry)
|
56
|
+
file_data = entry.file_data
|
57
|
+
content = ""
|
58
|
+
begin
|
59
|
+
loop do
|
60
|
+
content << file_data.read(8192)
|
61
|
+
end
|
62
|
+
rescue EOFError
|
63
|
+
end
|
64
|
+
content
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
54
68
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "zip"
|
2
|
+
|
3
|
+
module EPUB
|
4
|
+
class OCF
|
5
|
+
class PhysicalContainer
|
6
|
+
class Rubyzip < self
|
7
|
+
def open
|
8
|
+
orig_encoding = Zip.force_entry_names_encoding
|
9
|
+
begin
|
10
|
+
Zip.force_entry_names_encoding = "UTF-8"
|
11
|
+
Zip::File.open @container_path do |archive|
|
12
|
+
@monitor.synchronize do
|
13
|
+
@archive = archive
|
14
|
+
begin
|
15
|
+
yield self
|
16
|
+
ensure
|
17
|
+
@archive = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
ensure
|
22
|
+
Zip.force_entry_names_encoding = orig_encoding
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def read(path_name)
|
27
|
+
if @archive
|
28
|
+
@archive.read(path_name)
|
29
|
+
else
|
30
|
+
open {|container| container.read(path_name)}
|
31
|
+
end
|
32
|
+
rescue Errno::ENOENT => error
|
33
|
+
raise NoEntry.from_error(error)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/epub/parser/metadata.rb
CHANGED
@@ -28,7 +28,7 @@ module EPUB
|
|
28
28
|
language = build_model(child, :DCMES, ['id'])
|
29
29
|
metadata.languages << language
|
30
30
|
language
|
31
|
-
when '
|
31
|
+
when 'contributor', 'coverage', 'creator', 'date', 'description', 'format', 'publisher', 'relation', 'source', 'subject', 'rights', 'type'
|
32
32
|
attr = elem_name == 'rights' ? elem_name : elem_name + 's'
|
33
33
|
dcmes = build_model(child)
|
34
34
|
metadata.__send__(attr) << dcmes
|
data/lib/epub/parser/version.rb
CHANGED
@@ -91,6 +91,7 @@ module EPUB
|
|
91
91
|
# @param [EPUB::CFI] cfi
|
92
92
|
# @return [Array] Path in EPUB Rendition
|
93
93
|
def search_by_cfi(cfi)
|
94
|
+
raise NotImplementedError, "Currently, #{__method__} doesn't support deeper DOM tree such as including <iframe>" if cfi.paths[2]
|
94
95
|
path_in_package = cfi.paths.first
|
95
96
|
spine = @package.spine
|
96
97
|
model = [@package.metadata, @package.manifest, spine, @package.guide, @package.bindings].compact[path_in_package.steps.first.value / 2 - 1]
|
@@ -119,8 +120,6 @@ module EPUB
|
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
|
-
raise NotImplementedError, "Currently, #{__method__} doesn't support deeper DOM tree such as including <iframe>" if cfi.paths[2]
|
123
|
-
|
124
123
|
[itemref, current_node]
|
125
124
|
end
|
126
125
|
|
data/rakelib/doc.rake
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yard'
|
2
|
+
require 'rdoc/task'
|
3
|
+
|
4
|
+
task :doc => 'doc:default'
|
5
|
+
|
6
|
+
namespace :doc do
|
7
|
+
task :default => [:yard, :rdoc]
|
8
|
+
|
9
|
+
YARD::Rake::YardocTask.new
|
10
|
+
Rake::RDocTask.new do |rdoc|
|
11
|
+
rdoc.rdoc_files.include %w[
|
12
|
+
lib/**/*.rb
|
13
|
+
README.adoc
|
14
|
+
CHANGELOG.adoc
|
15
|
+
MIT-LICENSE
|
16
|
+
docs/**/*.adoc
|
17
|
+
docs/**/*.md
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Build man page for epubinfo command"
|
22
|
+
file "man/epubinfo.1" => :ronn
|
23
|
+
|
24
|
+
desc "Build HTML man page for epubinfo command"
|
25
|
+
file "man/epubinfo.1.html" => :ronn
|
26
|
+
|
27
|
+
task ronn: "man/epubinfo.1.ronn" do |t|
|
28
|
+
sh "ronn #{t.source}"
|
29
|
+
end
|
30
|
+
end
|
data/rakelib/test.rake
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'epub/maker'
|
4
|
+
require "tmpdir"
|
5
|
+
require 'archive/zip'
|
6
|
+
|
7
|
+
task :test => 'test:default'
|
8
|
+
|
9
|
+
namespace :test do
|
10
|
+
task :default => [:test, :test_ocf_physical_container_zipruby, :test_ocf_physical_container_rubyzip]
|
11
|
+
|
12
|
+
desc 'Build test fixture EPUB file'
|
13
|
+
task :build => [:clean, "test/fixtures/book.epub"]
|
14
|
+
|
15
|
+
file "test/fixtures/book.epub" => "test/fixtures/book" do |task|
|
16
|
+
EPUB::Maker.archive task.source
|
17
|
+
# We cannot include "CASE-SENSITIVE.xhtml" in Git repository because
|
18
|
+
# macOS remove it or case-sensitive.xhtml from file system.
|
19
|
+
small_file = File.read("#{task.source}/OPS/case-sensitive.xhtml")
|
20
|
+
Dir.mktmpdir do |dir|
|
21
|
+
upcase_file_path = File.join(dir, "CASE-SENSITIVE.xhtml")
|
22
|
+
File.write upcase_file_path, small_file.sub('small file name', 'LARGE FILE NAME')
|
23
|
+
Archive::Zip.archive task.name, upcase_file_path, path_prefix: "OPS"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
CLEAN.include "test/fixtures/book.epub"
|
27
|
+
|
28
|
+
Rake::TestTask.new test: :build do |task|
|
29
|
+
task.test_files = FileList['test/**/test_*.rb'].exclude "test/test_ocf_physical_container_*.rb"
|
30
|
+
task.warning = true
|
31
|
+
task.options = '--no-show-detail-immediately --verbose'
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::TestTask.new test_ocf_physical_container_zipruby: :build do |task|
|
35
|
+
task.test_files = FileList["test/test_ocf_physical_container_zipruby.rb"]
|
36
|
+
task.warning = true
|
37
|
+
task.options = "--no-show-detail-immediately --verbose"
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::TestTask.new test_ocf_physical_container_rubyzip: :build do |task|
|
41
|
+
task.test_files = FileList["test/test_ocf_physical_container_rubyzip.rb"]
|
42
|
+
task.warning = true
|
43
|
+
task.options = "--no-show-detail-immediately --verbose"
|
44
|
+
end
|
45
|
+
end
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
# gems:
|
17
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
18
|
+
# - name: GEM_NAME
|
19
|
+
# ignore: true
|
data/test/helper.rb
CHANGED
@@ -8,13 +8,38 @@ require 'pp'
|
|
8
8
|
require 'test/unit'
|
9
9
|
require 'test/unit/rr'
|
10
10
|
require 'test/unit/notify'
|
11
|
-
require 'pry'
|
12
|
-
if ENV["PRETTY_BACKTRACE"]
|
13
|
-
require 'pretty_backtrace'
|
14
|
-
PrettyBacktrace.enable
|
15
|
-
end
|
16
11
|
|
17
12
|
require 'epub/parser'
|
18
13
|
if ENV["XML_BACKEND"]
|
19
14
|
EPUB::Parser::XMLDocument.backend = ENV["XML_BACKEND"].to_sym
|
20
15
|
end
|
16
|
+
|
17
|
+
module ConcreteContainer
|
18
|
+
def test_class_method_open
|
19
|
+
@class.open @container_path do |container|
|
20
|
+
assert_instance_of @class, container
|
21
|
+
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
22
|
+
assert_equal File.read('test/fixtures/book/OPS/日本語.xhtml'), container.read('OPS/日本語.xhtml').force_encoding('UTF-8')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_class_method_read
|
27
|
+
assert_equal @content, @class.read(@container_path, @path).force_encoding('UTF-8')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_open_yields_over_container_with_opened_archive
|
31
|
+
@container.open do |container|
|
32
|
+
assert_instance_of @class, container
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_container_in_open_block_can_readable
|
37
|
+
@container.open do |container|
|
38
|
+
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_read
|
43
|
+
assert_equal @content, @container.read(@path).force_encoding('UTF-8')
|
44
|
+
end
|
45
|
+
end
|
@@ -47,7 +47,16 @@ class TestContentDocument < Test::Unit::TestCase
|
|
47
47
|
|
48
48
|
def test_title_returns_empty_string_when_title_element_not_exist
|
49
49
|
content_doc = XHTML.new
|
50
|
-
stub(content_doc).raw_document {
|
50
|
+
stub(content_doc).raw_document {
|
51
|
+
<<~EOS
|
52
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
53
|
+
<!DOCTYPE html>
|
54
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
|
55
|
+
<head></head>
|
56
|
+
<body></body>
|
57
|
+
</html>
|
58
|
+
EOS
|
59
|
+
}
|
51
60
|
assert_equal '', content_doc.title
|
52
61
|
end
|
53
62
|
|
data/test/test_inspect.rb
CHANGED
@@ -18,7 +18,7 @@ class TestInspect < Test::Unit::TestCase
|
|
18
18
|
@package.prefix = {'foaf' => 'http://xmlns.com/foaf/spec/'}
|
19
19
|
|
20
20
|
assert_match %Q|@xml_lang="zh"|, @package.inspect
|
21
|
-
assert_match %
|
21
|
+
assert_match %r|@prefix={"foaf"\s*=>\s*"http://xmlns.com/foaf/spec/"}|, @package.inspect
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_package_inspects_content_models
|
@@ -1,63 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require_relative
|
3
|
-
require 'epub/ocf/physical_container'
|
4
|
-
|
5
|
-
class TestOCFPhysicalContainer < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@container_path = 'test/fixtures/book.epub'
|
8
|
-
@path = 'OPS/nav.xhtml'
|
9
|
-
@content = File.read(File.join('test/fixtures/book', @path))
|
10
|
-
end
|
2
|
+
require_relative "test_ocf_physical_container_base"
|
11
3
|
|
4
|
+
class TestOCFPhysicalContainer < TestOCFPhysicalContainerBase
|
12
5
|
def test_read
|
13
6
|
assert_equal @content, EPUB::OCF::PhysicalContainer.read(@container_path, @path).force_encoding('UTF-8')
|
14
7
|
end
|
15
8
|
|
16
|
-
module ConcreteContainer
|
17
|
-
def test_class_method_open
|
18
|
-
@class.open @container_path do |container|
|
19
|
-
assert_instance_of @class, container
|
20
|
-
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
21
|
-
assert_equal File.read('test/fixtures/book/OPS/日本語.xhtml'), container.read('OPS/日本語.xhtml').force_encoding('UTF-8')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_class_method_read
|
26
|
-
assert_equal @content, @class.read(@container_path, @path).force_encoding('UTF-8')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_open_yields_over_container_with_opened_archive
|
30
|
-
@container.open do |container|
|
31
|
-
assert_instance_of @class, container
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_container_in_open_block_can_readable
|
36
|
-
@container.open do |container|
|
37
|
-
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_read
|
42
|
-
assert_equal @content, @container.read(@path).force_encoding('UTF-8')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
begin
|
47
|
-
require 'epub/ocf/physical_container/zipruby'
|
48
|
-
class TestZipruby < self
|
49
|
-
include ConcreteContainer
|
50
|
-
|
51
|
-
def setup
|
52
|
-
super
|
53
|
-
@class = EPUB::OCF::PhysicalContainer::Zipruby
|
54
|
-
@container = @class.new(@container_path)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
rescue LoadError
|
58
|
-
warn "Skip TestOPFPhysicalContainer::TestZipRuby"
|
59
|
-
end
|
60
|
-
|
61
9
|
class TestUnpackedDirectory < self
|
62
10
|
include ConcreteContainer
|
63
11
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require "epub/ocf/physical_container"
|
3
|
+
|
4
|
+
class TestOCFPhysicalContainerBase < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@container_path = 'test/fixtures/book.epub'
|
7
|
+
@path = 'OPS/nav.xhtml'
|
8
|
+
@content = File.read(File.join('test/fixtures/book', @path))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "test_ocf_physical_container_base"
|
3
|
+
require "epub/ocf/physical_container/rubyzip"
|
4
|
+
|
5
|
+
class TestRubyzip < TestOCFPhysicalContainerBase
|
6
|
+
include ConcreteContainer
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@class = EPUB::OCF::PhysicalContainer::Rubyzip
|
11
|
+
@container = @class.new(@container_path)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require "epub/ocf/physical_container/zipruby"
|
3
|
+
require_relative "test_ocf_physical_container_base"
|
4
|
+
|
5
|
+
class TestZipruby < TestOCFPhysicalContainerBase
|
6
|
+
include ConcreteContainer
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@class = EPUB::OCF::PhysicalContainer::Zipruby
|
11
|
+
@container = @class.new(@container_path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn "Skip TestOPFPhysicalContainer::TestZipruby"
|
16
|
+
end
|
data/test/test_parser_ocf.rb
CHANGED
@@ -22,15 +22,15 @@ class TestParserOCF < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_parse_encryption_do_nothing_excluding_to_have_content
|
25
|
-
encryption = @parser.parse_encryption('content')
|
25
|
+
encryption = @parser.parse_encryption('<root>content</root>')
|
26
26
|
|
27
|
-
assert_equal 'content', encryption.content
|
27
|
+
assert_equal '<root>content</root>', encryption.content
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_parse_metadata_with_unknown_format_do_nothing_excluding_to_have_content
|
31
|
-
metadata = @parser.parse_metadata('content')
|
31
|
+
metadata = @parser.parse_metadata('<root>content</root>')
|
32
32
|
|
33
|
-
assert_equal 'content', metadata.content
|
33
|
+
assert_equal '<root>content</root>', metadata.content
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_parse_metadata_with_multiple_rendition_format_returns_metadata
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epub-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rake
|
@@ -39,7 +38,7 @@ dependencies:
|
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
41
|
+
name: zipruby
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ">="
|
@@ -53,19 +52,19 @@ dependencies:
|
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0'
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
55
|
+
name: rubyzip
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
60
|
+
version: 2.0.0
|
62
61
|
type: :development
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
65
|
- - ">="
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
67
|
+
version: 2.0.0
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
69
|
name: test-unit
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +164,7 @@ dependencies:
|
|
165
164
|
- !ruby/object:Gem::Version
|
166
165
|
version: '0'
|
167
166
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
167
|
+
name: epub-maker
|
169
168
|
requirement: !ruby/object:Gem::Requirement
|
170
169
|
requirements:
|
171
170
|
- - ">="
|
@@ -179,7 +178,7 @@ dependencies:
|
|
179
178
|
- !ruby/object:Gem::Version
|
180
179
|
version: '0'
|
181
180
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
181
|
+
name: asciidoctor
|
183
182
|
requirement: !ruby/object:Gem::Requirement
|
184
183
|
requirements:
|
185
184
|
- - ">="
|
@@ -193,7 +192,7 @@ dependencies:
|
|
193
192
|
- !ruby/object:Gem::Version
|
194
193
|
version: '0'
|
195
194
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
195
|
+
name: nokogiri
|
197
196
|
requirement: !ruby/object:Gem::Requirement
|
198
197
|
requirements:
|
199
198
|
- - ">="
|
@@ -207,35 +206,35 @@ dependencies:
|
|
207
206
|
- !ruby/object:Gem::Version
|
208
207
|
version: '0'
|
209
208
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
209
|
+
name: oga
|
211
210
|
requirement: !ruby/object:Gem::Requirement
|
212
211
|
requirements:
|
213
212
|
- - ">="
|
214
213
|
- !ruby/object:Gem::Version
|
215
|
-
version: '
|
214
|
+
version: '2.16'
|
216
215
|
type: :development
|
217
216
|
prerelease: false
|
218
217
|
version_requirements: !ruby/object:Gem::Requirement
|
219
218
|
requirements:
|
220
219
|
- - ">="
|
221
220
|
- !ruby/object:Gem::Version
|
222
|
-
version: '
|
221
|
+
version: '2.16'
|
223
222
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
223
|
+
name: packnga
|
225
224
|
requirement: !ruby/object:Gem::Requirement
|
226
225
|
requirements:
|
227
226
|
- - ">="
|
228
227
|
- !ruby/object:Gem::Version
|
229
|
-
version: '
|
228
|
+
version: '0'
|
230
229
|
type: :development
|
231
230
|
prerelease: false
|
232
231
|
version_requirements: !ruby/object:Gem::Requirement
|
233
232
|
requirements:
|
234
233
|
- - ">="
|
235
234
|
- !ruby/object:Gem::Version
|
236
|
-
version: '
|
235
|
+
version: '0'
|
237
236
|
- !ruby/object:Gem::Dependency
|
238
|
-
name:
|
237
|
+
name: steep
|
239
238
|
requirement: !ruby/object:Gem::Requirement
|
240
239
|
requirements:
|
241
240
|
- - ">="
|
@@ -378,6 +377,7 @@ files:
|
|
378
377
|
- lib/epub/ocf/metadata.rb
|
379
378
|
- lib/epub/ocf/physical_container.rb
|
380
379
|
- lib/epub/ocf/physical_container/archive_zip.rb
|
380
|
+
- lib/epub/ocf/physical_container/rubyzip.rb
|
381
381
|
- lib/epub/ocf/physical_container/unpacked_directory.rb
|
382
382
|
- lib/epub/ocf/physical_container/unpacked_uri.rb
|
383
383
|
- lib/epub/ocf/physical_container/zipruby.rb
|
@@ -406,6 +406,9 @@ files:
|
|
406
406
|
- lib/epub/searcher/result.rb
|
407
407
|
- lib/epub/searcher/xhtml.rb
|
408
408
|
- man/epubinfo.1.ronn
|
409
|
+
- rakelib/doc.rake
|
410
|
+
- rakelib/test.rake
|
411
|
+
- rbs_collection.yaml
|
409
412
|
- sig/epub-parser.rbs
|
410
413
|
- test/fixtures/book/META-INF/container.xml
|
411
414
|
- test/fixtures/book/META-INF/metadata.xml
|
@@ -432,6 +435,9 @@ files:
|
|
432
435
|
- test/test_fixed_layout.rb
|
433
436
|
- test/test_inspect.rb
|
434
437
|
- test/test_ocf_physical_container.rb
|
438
|
+
- test/test_ocf_physical_container_base.rb
|
439
|
+
- test/test_ocf_physical_container_rubyzip.rb
|
440
|
+
- test/test_ocf_physical_container_zipruby.rb
|
435
441
|
- test/test_parser.rb
|
436
442
|
- test/test_parser_content_document.rb
|
437
443
|
- test/test_parser_fixed_layout.rb
|
@@ -445,7 +451,6 @@ licenses:
|
|
445
451
|
- MIT
|
446
452
|
metadata:
|
447
453
|
yard.run: yard
|
448
|
-
post_install_message:
|
449
454
|
rdoc_options: []
|
450
455
|
require_paths:
|
451
456
|
- lib
|
@@ -453,15 +458,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
453
458
|
requirements:
|
454
459
|
- - ">="
|
455
460
|
- !ruby/object:Gem::Version
|
456
|
-
version: '2.
|
461
|
+
version: '2.6'
|
457
462
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
458
463
|
requirements:
|
459
464
|
- - ">="
|
460
465
|
- !ruby/object:Gem::Version
|
461
466
|
version: '0'
|
462
467
|
requirements: []
|
463
|
-
rubygems_version: 3.
|
464
|
-
signing_key:
|
468
|
+
rubygems_version: 3.6.7
|
465
469
|
specification_version: 4
|
466
470
|
summary: EPUB 3 Parser
|
467
471
|
test_files:
|
@@ -471,6 +475,9 @@ test_files:
|
|
471
475
|
- test/test_fixed_layout.rb
|
472
476
|
- test/test_inspect.rb
|
473
477
|
- test/test_ocf_physical_container.rb
|
478
|
+
- test/test_ocf_physical_container_base.rb
|
479
|
+
- test/test_ocf_physical_container_rubyzip.rb
|
480
|
+
- test/test_ocf_physical_container_zipruby.rb
|
474
481
|
- test/test_parser.rb
|
475
482
|
- test/test_parser_content_document.rb
|
476
483
|
- test/test_parser_fixed_layout.rb
|