epub_tools 0.2.1 → 0.3.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 +4 -4
- data/bin/epub-tools +7 -2
- data/epub_tools.gemspec +5 -1
- data/lib/epub_tools/compile_book.rb +5 -2
- data/lib/epub_tools/version.rb +1 -1
- data/lib/epub_tools.rb +1 -0
- data/test/cli_version_test.rb +20 -0
- data/test/epub_initializer_test.rb +64 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbc80ed0690251633b8f12d80fa256922cac6092c12d3a910cd998e61ce38ea0
|
4
|
+
data.tar.gz: b0da7dd401516d3a1074268c7495d02d1a3532ea3e6f4bd9b49b9e62772e280c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66de9b943051874b87a1a32bf7fba1391eefad09e21a20f1e5a9265cdcb77d65bc453342787dc25944a265a81cf1119ecfe37a78713221d6d869aae4896982d9
|
7
|
+
data.tar.gz: db68ab8011facd49ef7314d1b6e7ce0c2b645a62a3a4ae213048af2500546622b55153cc4598747d234a972c05738927ec7f9b9efb047feb0c60c3022a6f21fa
|
data/bin/epub-tools
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
require_relative '../lib/epub_tools'
|
3
3
|
|
4
4
|
prog = File.basename($PROGRAM_NAME)
|
5
|
+
# Global version flag: print version and exit if invoked as `epub-tools -v/--version`
|
6
|
+
if ARGV[0] == '-v' || ARGV[0] == '--version'
|
7
|
+
puts EpubTools::VERSION
|
8
|
+
exit 0
|
9
|
+
end
|
5
10
|
script_dir = File.expand_path(File.join(__dir__, '..'))
|
6
11
|
commands = %w[add extract init split pack unpack compile]
|
7
12
|
|
@@ -90,7 +95,7 @@ when 'unpack'
|
|
90
95
|
opts.on('-o DIR', '--output-dir DIR', 'Output directory to extract into (default: basename of epub)') { |v| o[:output_dir] = v }
|
91
96
|
opts.on('-q', '--quiet', 'Run quietly (default: verbose)') { |v| o[:verbose] = !v }
|
92
97
|
end
|
93
|
-
EpubTools::UnpackEbook.new(options[:epub_file], verbose: options[:verbose]).run
|
98
|
+
EpubTools::UnpackEbook.new(options[:epub_file], options[:output_dir], verbose: options[:verbose]).run
|
94
99
|
|
95
100
|
when 'compile'
|
96
101
|
options = {verbose: true}
|
@@ -103,5 +108,5 @@ when 'compile'
|
|
103
108
|
opts.on('-c PATH', '--cover PATH', 'Cover image file path (optional)') { |v| o[:cover_image] = v }
|
104
109
|
opts.on('-q', '--quiet', 'Run quietly (default: verbose)') { |v| o[:verbose] = !v }
|
105
110
|
end
|
106
|
-
EpubTools::CompileBook.new(
|
111
|
+
EpubTools::CompileBook.new(**options).run
|
107
112
|
end
|
data/epub_tools.gemspec
CHANGED
@@ -6,12 +6,16 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.summary = 'Tools to extract, split, and compile EPUB books'
|
7
7
|
spec.authors = ['Jaime Rodas']
|
8
8
|
spec.email = ['rodas@hey.com']
|
9
|
-
spec.homepage = 'https://
|
9
|
+
spec.homepage = 'https://github.com/jaimerodas/epub_tools'
|
10
10
|
spec.license = 'MIT'
|
11
11
|
spec.files = `git ls-files`.split("\n")
|
12
12
|
spec.require_paths = ['lib']
|
13
13
|
spec.executables = ['epub-tools']
|
14
14
|
spec.required_ruby_version = ">= 3.0"
|
15
|
+
spec.metadata = {
|
16
|
+
"source_code_uri" => "https://github.com/jaimerodas/epub_tools/tree/main",
|
17
|
+
"homepage_uri" => "https://github.com/jaimerodas/epub_tools"
|
18
|
+
}
|
15
19
|
|
16
20
|
spec.add_dependency 'nokogiri', '~> 1.18'
|
17
21
|
spec.add_dependency 'rubyzip', '~> 2.4'
|
@@ -1,7 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fileutils'
|
3
|
-
|
4
|
-
|
3
|
+
require_relative 'xhtml_extractor'
|
4
|
+
require_relative 'split_chapters'
|
5
|
+
require_relative 'epub_initializer'
|
6
|
+
require_relative 'add_chapters_to_epub'
|
7
|
+
require_relative 'pack_ebook'
|
5
8
|
|
6
9
|
module EpubTools
|
7
10
|
# Orchestrates extraction, splitting, validation, and packaging of book EPUBs
|
data/lib/epub_tools/version.rb
CHANGED
data/lib/epub_tools.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require_relative '../lib/epub_tools/version'
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
class CLIVersionTest < Minitest::Test
|
6
|
+
def test_version_flag
|
7
|
+
# Path to the CLI executable under the project root
|
8
|
+
project_root = File.expand_path('..', __dir__)
|
9
|
+
cli = File.join(project_root, 'bin', 'epub-tools')
|
10
|
+
# Run with --version
|
11
|
+
out, status = Open3.capture2(cli, '--version')
|
12
|
+
assert_equal "#{EpubTools::VERSION}\n", out
|
13
|
+
assert status.success?, "Expected exit status 0, got #{status.exitstatus}"
|
14
|
+
|
15
|
+
# Run with -v
|
16
|
+
out2, status2 = Open3.capture2(cli, '-v')
|
17
|
+
assert_equal "#{EpubTools::VERSION}\n", out2
|
18
|
+
assert status2.success?, "Expected exit status 0, got #{status2.exitstatus}"
|
19
|
+
end
|
20
|
+
end
|
@@ -52,4 +52,68 @@ class EpubInitializerTest < Minitest::Test
|
|
52
52
|
assert_includes opf, '<item id="cover-page"'
|
53
53
|
assert_includes opf, '<itemref idref="cover-page"'
|
54
54
|
end
|
55
|
+
|
56
|
+
def test_run_with_cover_jpg
|
57
|
+
cover = File.join(@tmp, 'cover.jpg')
|
58
|
+
File.write(cover, 'JPGDATA')
|
59
|
+
EpubTools::EpubInitializer.new(@title, @author, @dest, cover).run
|
60
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.jpg'))
|
61
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
62
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
63
|
+
assert_includes opf, "<item id=\"cover-image\" href=\"cover.jpg\" media-type=\"image/jpeg\""
|
64
|
+
assert_includes opf, '<item id="cover-page"'
|
65
|
+
assert_includes opf, '<itemref idref="cover-page"'
|
66
|
+
cover_xhtml = File.read(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
67
|
+
assert_includes cover_xhtml, 'src="cover.jpg"'
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_run_with_cover_jpeg
|
71
|
+
cover = File.join(@tmp, 'cover.jpeg')
|
72
|
+
File.write(cover, 'JPEGDATA')
|
73
|
+
EpubTools::EpubInitializer.new(@title, @author, @dest, cover).run
|
74
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.jpeg'))
|
75
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
76
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
77
|
+
assert_includes opf, "<item id=\"cover-image\" href=\"cover.jpeg\" media-type=\"image/jpeg\""
|
78
|
+
cover_xhtml = File.read(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
79
|
+
assert_includes cover_xhtml, 'src="cover.jpeg"'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_run_with_cover_gif
|
83
|
+
cover = File.join(@tmp, 'cover.gif')
|
84
|
+
File.write(cover, 'GIFDATA')
|
85
|
+
EpubTools::EpubInitializer.new(@title, @author, @dest, cover).run
|
86
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.gif'))
|
87
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
88
|
+
assert_includes opf, "<item id=\"cover-image\" href=\"cover.gif\" media-type=\"image/gif\""
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_run_with_cover_svg
|
92
|
+
cover = File.join(@tmp, 'cover.svg')
|
93
|
+
File.write(cover, '<svg/>')
|
94
|
+
EpubTools::EpubInitializer.new(@title, @author, @dest, cover).run
|
95
|
+
assert File.exist?(File.join(@dest, 'OEBPS', 'cover.svg'))
|
96
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
97
|
+
assert_includes opf, "<item id=\"cover-image\" href=\"cover.svg\" media-type=\"image/svg+xml\""
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_run_with_unsupported_cover_image
|
101
|
+
cover = File.join(@tmp, 'cover.bmp')
|
102
|
+
File.write(cover, 'BMPDATA')
|
103
|
+
ei = EpubTools::EpubInitializer.new(@title, @author, @dest, cover)
|
104
|
+
assert_output("", /unsupported cover image type/) { ei.run }
|
105
|
+
refute File.exist?(File.join(@dest, 'OEBPS', 'cover.bmp'))
|
106
|
+
refute File.exist?(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
107
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
108
|
+
refute_includes opf, 'cover-image'
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_run_without_cover_but_declaring_cover
|
112
|
+
cover = File.join(@tmp, 'cover.bmp')
|
113
|
+
ei = EpubTools::EpubInitializer.new(@title, @author, @dest, cover)
|
114
|
+
assert_output("", /not found/) { ei.run }
|
115
|
+
refute File.exist?(File.join(@dest, 'OEBPS', 'cover.xhtml'))
|
116
|
+
opf = File.read(File.join(@dest, 'OEBPS', 'package.opf'))
|
117
|
+
refute_includes opf, 'cover-image'
|
118
|
+
end
|
55
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epub_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime Rodas
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/epub_tools/xhtml_extractor.rb
|
111
111
|
- style.css
|
112
112
|
- test/add_chapters_to_epub_test.rb
|
113
|
+
- test/cli_version_test.rb
|
113
114
|
- test/compile_book_test.rb
|
114
115
|
- test/epub_initializer_test.rb
|
115
116
|
- test/pack_ebook_test.rb
|
@@ -119,10 +120,12 @@ files:
|
|
119
120
|
- test/unpack_ebook_test.rb
|
120
121
|
- test/xhtml_cleaner_test.rb
|
121
122
|
- test/xhtml_extractor_test.rb
|
122
|
-
homepage: https://
|
123
|
+
homepage: https://github.com/jaimerodas/epub_tools
|
123
124
|
licenses:
|
124
125
|
- MIT
|
125
|
-
metadata:
|
126
|
+
metadata:
|
127
|
+
source_code_uri: https://github.com/jaimerodas/epub_tools/tree/main
|
128
|
+
homepage_uri: https://github.com/jaimerodas/epub_tools
|
126
129
|
rdoc_options: []
|
127
130
|
require_paths:
|
128
131
|
- lib
|