lib/review/epubmaker.rb in review-4.0.0 vs lib/review/epubmaker.rb in review-4.1.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2010-2019 Kenshi Muto and Masayoshi Takahashi
+# Copyright (c) 2010-2020 Kenshi Muto and Masayoshi Takahashi
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
@@ -71,18 +71,20 @@
end
def parse_opts(args)
cmd_config = {}
opts = OptionParser.new
+ @buildonly = nil
opts.banner = 'Usage: review-epubmaker [options] configfile [export_filename]'
opts.version = ReVIEW::VERSION
opts.on('--help', 'Prints this message and quit.') do
puts opts.help
exit 0
end
opts.on('--[no-]debug', 'Keep temporary files.') { |debug| cmd_config['debug'] = debug }
+ opts.on('-y', '--only file1,file2,...', 'Build only specified files.') { |v| @buildonly = v.split(/\s*,\s*/).map { |m| m.strip.sub(/\.re\Z/, '') } }
opts.parse!(args)
if args.size < 1 || args.size > 2
puts opts.help
exit 0
@@ -392,10 +394,15 @@
@bodycount += 1
id = sprintf('chap%02d', @bodycount)
end
end
+ if @buildonly && !@buildonly.include?(id)
+ warn "skip #{id}.re"
+ return
+ end
+
htmlfile = "#{id}.#{@config['htmlext']}"
write_buildlogtxt(basetmpdir, htmlfile, filename)
log("Create #{htmlfile} from #{filename}.")
if @config['params'].present?
@@ -443,10 +450,17 @@
def write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil)
headlines = []
path = File.join(basetmpdir, filename)
htmlio = File.new(path)
Document.parse_stream(htmlio, ReVIEWHeaderListener.new(headlines))
+ htmlio.close
+
+ if headlines.empty?
+ warn "#{filename} is discarded because there is no heading. Use `=[notoc]' or `=[nodisp]' to exclude headlines from the table of contents."
+ return
+ end
+
properties = detect_properties(path)
if properties.present?
prop_str = ',properties=' + properties.join(' ')
else
prop_str = ''
@@ -470,10 +484,9 @@
chaptype: chaptype + prop_str,
notoc: headline['notoc'] })
first = nil
end
end
- htmlio.close
end
def push_contents(_basetmpdir)
@htmltoc.each_item do |level, file, title, args|
next if level.to_i > @config['toclevel'] && args[:force_include].nil?