-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepub_create
48 lines (40 loc) · 1.24 KB
/
epub_create
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# frozen_string_literal: true
# HELIO-3510, generate basic HTML instance from an EPUB,
# either reflowable or fixed layout.
require 'optparse'
require 'ostruct'
# Process the script parameters.
options = OpenStruct.new
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} dirpath [dirpath...]"
opts.on_tail('-h', '--help', 'Print this help message') do
puts opts
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 1
puts option_parser.help
return
end
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
#root_dir = File.dirname(script_dir)
root_dir = File.expand_path(File.join(script_dir, ".."))
dirpath_list = ARGV
require_relative File.join(root_dir, "lib", "epub")
dirpath_list.each do |dirpath|
dirpath = File.expand_path(dirpath)
unless File.directory?(dirpath)
puts "Error: invalid directory path #{dirpath}."
next
end
puts "Directory: #{dirpath + File::SEPARATOR}"
epub_file = File.join(File.dirname(dirpath), File.basename(dirpath) + "_created.epub")
puts "Creating EPUB #{File.basename(epub_file)}"
UMPTG::EPUB::Util.create(
directory: dirpath,
epub_file: epub_file
)
end