epub-parser 0.4.8 → 0.5.0

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
  SHA256:
3
- metadata.gz: 33ec17f68d55ead850d39f0df0ec73f0d9cda4901cdc4ee83612ebd95c0b1927
4
- data.tar.gz: 580741918f923319e665203b8334725e48afb1c69bdb2fe7ca412cefed3477d6
3
+ metadata.gz: ae67229ef10676e051fcac1f01f8c96bdfba667cc36c53584475795f3b9dbd82
4
+ data.tar.gz: 798548f2139eb8a807b95cabab3478a1d477b50ee3511d923f3f6a00b343d559
5
5
  SHA512:
6
- metadata.gz: 7683c526bc654bf55556db4d2be9efeccebc25ad29524ab14f264c85513649c0741b6b281eaa100e0cdbf93706ab1115ffca4522408299964cf1ef36136bc3be
7
- data.tar.gz: 7522670e7f7126a33a1ea19a89577382b5f25d0555974cf1b014184d30a44be5a475467b95772f2d5386ac76f2ab4fc6720cea91f68c7ae07e562a1c3229e186
6
+ metadata.gz: eb2a311ed69638f05b5d6e9e553e284825ee5bf48db54b0cec418042c221298c1e1c15f070aecd334b2ea6ddcdff8f351b8c190ffa59379fc84a4c00874d986d
7
+ data.tar.gz: 67c0e4e3eaaae19b2bcdb9d7e0f2fb93b0f9f0410ff36ddd47d1f8b2ea56ec509121226217ec46c96cc1ed122eba5eb310e3544cc573e920121c4b45c6bf9c93
data/.gitignore CHANGED
@@ -8,6 +8,9 @@ coverage/*
8
8
  samples/*
9
9
  doc/*
10
10
  html/*
11
+ man/*
12
+ !man/epubinfo.1.ronn
11
13
  NOTE
12
14
  test/fixtures/book.epub
13
15
  *~
16
+ /.gem_rbs_collection/
data/.gitlab-ci.yml CHANGED
@@ -1,67 +1,36 @@
1
1
  before_script:
2
+ - apt update -y && apt install -y clang
3
+ - curl https://sh.rustup.rs -sSf | sh -s -- -y
4
+ - . "$HOME/.cargo/env"
2
5
  - ruby -v
3
6
  - which ruby
4
- - gem install bundler --no-document
5
- - bundle install --jobs=$(nproc) --path=deps "${FLAGS[@]}"
7
+ - bundle config --local build.zipruby "--with-zlib-include=/usr/include --with-cflags='-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types'"
8
+ - bundle install --jobs=$(nproc) --path=deps "${FLAGS[@]}" || (cat deps/ruby/3.4.0/extensions/x86_64-linux/3.4.0/zipruby-*/mkmf.log && exit 1)
6
9
  - bundle clean
7
10
 
8
- test:2.6:
9
- image: ruby:2.6
10
- 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
- except:
12
- - tags
13
- cache:
14
- key: ruby:2.6
15
- paths:
16
- - deps
17
-
18
- test:2.7:
19
- image: ruby:2.7
20
- 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
- except:
22
- - tags
23
- cache:
24
- key: ruby:2.7
25
- paths:
26
- - deps
27
-
28
- test:3.0:
29
- image: ruby:3.0
30
- 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
- except:
32
- - tags
33
- cache:
34
- key: ruby:3.0
35
- paths:
36
- - deps
37
-
38
- test:3.1:
39
- image: ruby:3.1
40
- 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
41
- except:
42
- - tags
43
- cache:
44
- key: ruby:3.1
45
- paths:
46
- - deps
47
-
48
- test:3.2:
49
- image: ruby:3.2
50
- 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
+ test:
12
+ image: ruby:$RUBY_VERSION
13
+ script:
14
+ - bundle exec rake test XML_BACKEND=REXML 2>/dev/null
15
+ - bundle exec rake test XML_BACKEND=Oga 2>/dev/null
16
+ - bundle exec rake test XML_BACKEND=Nokogiri 2>/dev/null
51
17
  except:
52
18
  - tags
53
19
  cache:
54
- key: ruby:3.2
20
+ key: ruby:$RUBY_VERSION
55
21
  paths:
56
22
  - deps
23
+ parallel:
24
+ matrix:
25
+ - RUBY_VERSION: ["3.1", "3.2", "3.3", "3.4"]
57
26
 
58
27
  pages:
59
28
  stage: deploy
60
- image: ruby:2.7
29
+ image: ruby:3.4
61
30
  dependencies:
62
- - test:2.6
31
+ - test
63
32
  script:
64
- - bundle exec rake test doc:yard
33
+ - bundle exec rake test:test doc:yard
65
34
  - mv doc public
66
35
  - mv coverage public/
67
36
  artifacts:
@@ -70,6 +39,6 @@ pages:
70
39
  only:
71
40
  - master
72
41
  cache:
73
- key: ruby:2.7
42
+ key: ruby:3.4
74
43
  paths:
75
44
  - deps
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,17 @@
1
1
  = CHANGELOG
2
2
 
3
+ == 0.5.0
4
+
5
+ * Add RuZip adapter
6
+
7
+ == 0.4.9
8
+
9
+ * Restructure test
10
+ * Restructure Rake tasks
11
+ * Update required Ruby version to 2.6
12
+ * Follow Ruby 3.5 inspection change
13
+ * Follow Archive::Zip API change
14
+
3
15
  == 0.4.8
4
16
 
5
17
  * Add Rubyzip adapter
data/Gemfile CHANGED
@@ -1,12 +1,20 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- if ENV['EDGE_MAKER'] == '1'
5
- group :development do
6
- gem 'epub-maker', path: '../epub-maker'
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
- if RUBY_PLATFORM.match /darwin/
11
- gem 'terminal-notifier'
18
+ group :development, :test do
19
+ gem "ffi", "~> 1.16.3" if RbConfig::CONFIG["MAJOR"] == "2"
12
20
  end
data/README.adoc CHANGED
@@ -176,19 +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.8
179
+ === 0.5.0
180
180
 
181
- * Add Rubyzip adapter
181
+ * Add RuZip adapter
182
182
 
183
- === 0.4.7
183
+ === 0.4.9
184
184
 
185
- * [BUG FIX]Fix a bug that epubinfo doesn't handle navigation properly
185
+ * Restructure test
186
+ * Restructure Rake tasks
187
+ * Update required Ruby version to 2.6
188
+ * Follow Ruby 3.5 inspection change
189
+ * Follow Archive::Zip API change
186
190
 
187
- === 0.4.6
191
+ === 0.4.8
188
192
 
189
- * [BUG FIX]Prevent epubinfo tool raise exception when no nav elements
190
- * Tiny modifcation on Zip archive manipulation
191
- * Remove version specification from Nokogiri to migrate to Ruby 3.1
193
+ * Add Rubyzip adapter
192
194
 
193
195
  See {file:CHANGELOG.adoc} for older changelogs and details.
194
196
 
data/Rakefile CHANGED
@@ -1,60 +1,6 @@
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
- namespace :test do
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
60
- task :build => :clean
6
+ Gem::Tasks.new
data/docs/Searcher.adoc CHANGED
@@ -77,7 +77,7 @@ You can also use *restricted* searcher, which means that it can search from only
77
77
  </html>
78
78
  ----
79
79
 
80
- But cannot from document below:
80
+ But cannot do so from document below:
81
81
 
82
82
  ----
83
83
  <html>
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.3'
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,10 +27,9 @@ 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' unless RUBY_PLATFORM.match /mingw|arm64-darwin/
31
- s.add_development_dependency 'rubyzip', '>= 3.0.0.alpha'
32
- s.add_development_dependency 'pry'
33
- s.add_development_dependency 'pry-doc'
30
+ s.add_development_dependency 'zipruby'
31
+ s.add_development_dependency 'rubyzip', '>= 2.0.0'
32
+ s.add_development_dependency "ruzip"
34
33
  s.add_development_dependency 'test-unit'
35
34
  s.add_development_dependency 'test-unit-rr'
36
35
  s.add_development_dependency 'test-unit-notify'
@@ -38,14 +37,14 @@ Gem::Specification.new do |s|
38
37
  s.add_development_dependency 'yard'
39
38
  s.add_development_dependency 'gem-man'
40
39
  s.add_development_dependency 'ronn-ng'
41
- s.add_development_dependency 'pretty_backtrace'
42
40
  s.add_development_dependency 'epub-maker'
43
41
  s.add_development_dependency 'asciidoctor'
44
42
  s.add_development_dependency 'nokogiri'
45
43
  s.add_development_dependency 'oga', '>= 2.16'
46
44
  s.add_development_dependency 'packnga'
45
+ s.add_development_dependency "steep"
47
46
 
48
- s.add_runtime_dependency 'archive-zip'
47
+ s.add_runtime_dependency 'archive-zip', ">= 0.13.0"
49
48
  s.add_runtime_dependency 'rexml'
50
49
  s.add_runtime_dependency 'addressable', '>= 2.3.5'
51
50
  s.add_runtime_dependency 'rchardet', '>= 1.6.1'
@@ -3,8 +3,6 @@ require "set"
3
3
  module EPUB
4
4
  module ContentDocument
5
5
  module Typable
6
- attr_reader :types
7
-
8
6
  def types
9
7
  @types ||= Set.new
10
8
  end
@@ -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.file_data.read
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.file_data.read
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,31 @@
1
+ require "ruzip"
2
+
3
+ module EPUB
4
+ class OCF
5
+ class PhysicalContainer
6
+ class RuZip < self
7
+ def open
8
+ @monitor.synchronize do
9
+ @archive = ::RuZip::Archive.new(@container_path)
10
+ begin
11
+ yield self
12
+ ensure
13
+ @archive = nil
14
+ end
15
+ end
16
+ end
17
+
18
+ def read(path_name)
19
+ if @archive
20
+ file = @archive.by_name(path_name)
21
+ raise NoEntry.new(path_name) unless file
22
+
23
+ file.read
24
+ else
25
+ open {|container| container.read(path_name)}
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -21,8 +21,8 @@ module EPUB
21
21
  class << self
22
22
  def find_adapter(adapter)
23
23
  return adapter if adapter.instance_of? Class
24
- if adapter == :Zipruby && ! const_defined?(adapter)
25
- require 'epub/ocf/physical_container/zipruby'
24
+ if (adapter == :Zipruby || adapter == :RuZip) && ! const_defined?(adapter)
25
+ require "epub/ocf/physical_container/#{adapter.downcase}"
26
26
  end
27
27
  const_get adapter
28
28
  end
@@ -28,7 +28,7 @@ module EPUB
28
28
  language = build_model(child, :DCMES, ['id'])
29
29
  metadata.languages << language
30
30
  language
31
- when 'title', 'contributor', 'coverage', 'creator', 'date', 'description', 'format', 'publisher', 'relation', 'source', 'subject', 'rights', 'type'
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
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  class Parser
3
- VERSION = "0.4.8"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -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
@@ -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 {'content'}
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 %Q|@prefix={"foaf"=>"http://xmlns.com/foaf/spec/"}|, @package.inspect
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,12 @@
1
1
  # coding: utf-8
2
- require_relative 'helper'
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"
3
+ require "epub/ocf/physical_container/ruzip"
11
4
 
5
+ class TestOCFPhysicalContainer < TestOCFPhysicalContainerBase
12
6
  def test_read
13
7
  assert_equal @content, EPUB::OCF::PhysicalContainer.read(@container_path, @path).force_encoding('UTF-8')
14
8
  end
15
9
 
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
10
  class TestUnpackedDirectory < self
62
11
  include ConcreteContainer
63
12
 
@@ -86,13 +35,12 @@ class TestOCFPhysicalContainer < Test::Unit::TestCase
86
35
  end
87
36
  end
88
37
 
89
- require "epub/ocf/physical_container/rubyzip"
90
- class TestRubyzip < self
38
+ class TestRuZip < self
91
39
  include ConcreteContainer
92
40
 
93
41
  def setup
94
42
  super
95
- @class = EPUB::OCF::PhysicalContainer::Rubyzip
43
+ @class = EPUB::OCF::PhysicalContainer::RuZip
96
44
  @container = @class.new(@container_path)
97
45
  end
98
46
  end
@@ -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
@@ -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.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -39,35 +38,35 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: rubyzip
41
+ name: zipruby
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: 3.0.0.alpha
46
+ version: '0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
- version: 3.0.0.alpha
53
+ version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: pry
55
+ name: rubyzip
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: '0'
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: '0'
67
+ version: 2.0.0
69
68
  - !ruby/object:Gem::Dependency
70
- name: pry-doc
69
+ name: ruzip
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
@@ -179,7 +178,7 @@ dependencies:
179
178
  - !ruby/object:Gem::Version
180
179
  version: '0'
181
180
  - !ruby/object:Gem::Dependency
182
- name: pretty_backtrace
181
+ name: epub-maker
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: epub-maker
195
+ name: asciidoctor
197
196
  requirement: !ruby/object:Gem::Requirement
198
197
  requirements:
199
198
  - - ">="
@@ -207,7 +206,7 @@ dependencies:
207
206
  - !ruby/object:Gem::Version
208
207
  version: '0'
209
208
  - !ruby/object:Gem::Dependency
210
- name: asciidoctor
209
+ name: nokogiri
211
210
  requirement: !ruby/object:Gem::Requirement
212
211
  requirements:
213
212
  - - ">="
@@ -221,35 +220,35 @@ dependencies:
221
220
  - !ruby/object:Gem::Version
222
221
  version: '0'
223
222
  - !ruby/object:Gem::Dependency
224
- name: nokogiri
223
+ name: oga
225
224
  requirement: !ruby/object:Gem::Requirement
226
225
  requirements:
227
226
  - - ">="
228
227
  - !ruby/object:Gem::Version
229
- version: '0'
228
+ version: '2.16'
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: '0'
235
+ version: '2.16'
237
236
  - !ruby/object:Gem::Dependency
238
- name: oga
237
+ name: packnga
239
238
  requirement: !ruby/object:Gem::Requirement
240
239
  requirements:
241
240
  - - ">="
242
241
  - !ruby/object:Gem::Version
243
- version: '2.16'
242
+ version: '0'
244
243
  type: :development
245
244
  prerelease: false
246
245
  version_requirements: !ruby/object:Gem::Requirement
247
246
  requirements:
248
247
  - - ">="
249
248
  - !ruby/object:Gem::Version
250
- version: '2.16'
249
+ version: '0'
251
250
  - !ruby/object:Gem::Dependency
252
- name: packnga
251
+ name: steep
253
252
  requirement: !ruby/object:Gem::Requirement
254
253
  requirements:
255
254
  - - ">="
@@ -268,14 +267,14 @@ dependencies:
268
267
  requirements:
269
268
  - - ">="
270
269
  - !ruby/object:Gem::Version
271
- version: '0'
270
+ version: 0.13.0
272
271
  type: :runtime
273
272
  prerelease: false
274
273
  version_requirements: !ruby/object:Gem::Requirement
275
274
  requirements:
276
275
  - - ">="
277
276
  - !ruby/object:Gem::Version
278
- version: '0'
277
+ version: 0.13.0
279
278
  - !ruby/object:Gem::Dependency
280
279
  name: rexml
281
280
  requirement: !ruby/object:Gem::Requirement
@@ -393,6 +392,7 @@ files:
393
392
  - lib/epub/ocf/physical_container.rb
394
393
  - lib/epub/ocf/physical_container/archive_zip.rb
395
394
  - lib/epub/ocf/physical_container/rubyzip.rb
395
+ - lib/epub/ocf/physical_container/ruzip.rb
396
396
  - lib/epub/ocf/physical_container/unpacked_directory.rb
397
397
  - lib/epub/ocf/physical_container/unpacked_uri.rb
398
398
  - lib/epub/ocf/physical_container/zipruby.rb
@@ -421,6 +421,9 @@ files:
421
421
  - lib/epub/searcher/result.rb
422
422
  - lib/epub/searcher/xhtml.rb
423
423
  - man/epubinfo.1.ronn
424
+ - rakelib/doc.rake
425
+ - rakelib/test.rake
426
+ - rbs_collection.yaml
424
427
  - sig/epub-parser.rbs
425
428
  - test/fixtures/book/META-INF/container.xml
426
429
  - test/fixtures/book/META-INF/metadata.xml
@@ -447,6 +450,9 @@ files:
447
450
  - test/test_fixed_layout.rb
448
451
  - test/test_inspect.rb
449
452
  - test/test_ocf_physical_container.rb
453
+ - test/test_ocf_physical_container_base.rb
454
+ - test/test_ocf_physical_container_rubyzip.rb
455
+ - test/test_ocf_physical_container_zipruby.rb
450
456
  - test/test_parser.rb
451
457
  - test/test_parser_content_document.rb
452
458
  - test/test_parser_fixed_layout.rb
@@ -460,7 +466,6 @@ licenses:
460
466
  - MIT
461
467
  metadata:
462
468
  yard.run: yard
463
- post_install_message:
464
469
  rdoc_options: []
465
470
  require_paths:
466
471
  - lib
@@ -468,15 +473,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
468
473
  requirements:
469
474
  - - ">="
470
475
  - !ruby/object:Gem::Version
471
- version: '2.3'
476
+ version: '2.6'
472
477
  required_rubygems_version: !ruby/object:Gem::Requirement
473
478
  requirements:
474
479
  - - ">="
475
480
  - !ruby/object:Gem::Version
476
481
  version: '0'
477
482
  requirements: []
478
- rubygems_version: 3.4.22
479
- signing_key:
483
+ rubygems_version: 3.7.2
480
484
  specification_version: 4
481
485
  summary: EPUB 3 Parser
482
486
  test_files:
@@ -486,6 +490,9 @@ test_files:
486
490
  - test/test_fixed_layout.rb
487
491
  - test/test_inspect.rb
488
492
  - test/test_ocf_physical_container.rb
493
+ - test/test_ocf_physical_container_base.rb
494
+ - test/test_ocf_physical_container_rubyzip.rb
495
+ - test/test_ocf_physical_container_zipruby.rb
489
496
  - test/test_parser.rb
490
497
  - test/test_parser_content_document.rb
491
498
  - test/test_parser_fixed_layout.rb