epub_tools 0.2.2 → 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 +5 -0
- data/lib/epub_tools/compile_book.rb +5 -2
- data/lib/epub_tools/version.rb +1 -1
- data/test/cli_version_test.rb +20 -0
- data/test/epub_initializer_test.rb +64 -0
- metadata +2 -1
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
|
|
@@ -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
@@ -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
|