bin/review-compile in review-2.0.0.beta1 vs bin/review-compile in review-2.0.0
- old
+ new
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
#
# $Id: review-compile 4326 2010-01-12 14:10:17Z kmuto $
#
-# Copyright (c) 2008-2014 Kenshi Muto, Masayoshi Takahashi, KADO Masanori, Minero Aoki
+# Copyright (c) 2008-2016 Kenshi Muto, Masayoshi Takahashi, KADO Masanori, Minero Aoki
# Copyright (c) 1999-2007 Minero Aoki
#
# 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.
@@ -15,16 +15,16 @@
bindir = Pathname.new(__FILE__).realpath.dirname
$LOAD_PATH.unshift((bindir + '../lib').realpath)
require 'review'
-require 'review/compiler'
-require 'review/book'
-require 'review/i18n'
require 'fileutils'
require 'optparse'
+require 'yaml'
+DEFAULT_CONFIG_FILENAME = "config.yml"
+
def main
Signal.trap(:INT) { exit 1 }
if RUBY_PLATFORM !~ /mswin(?!ce)|mingw|cygwin|bccwin/
Signal.trap(:PIPE, 'IGNORE')
end
@@ -32,12 +32,10 @@
rescue Errno::EPIPE
exit 0
end
def _main
- $KCODE = 'UTF-8' unless defined?(Encoding)
-
mode = :files
basedir = nil
if /\Areview2/ =~ File.basename($0)
target = File.basename($0, '.rb').sub(/review2/, '')
else
@@ -45,50 +43,23 @@
end
check_only = false
output_filename = nil
config = ReVIEW::Configure.values
- config.merge!({
- "secnolevel" => 2, # for IDGXML and HTML
- "tableopt" => nil, # for IDGXML
- "nolf" => nil, # for IDGXML
- "chapref" => nil, # for IDGXML
- "structuredxml" => nil, # for IDGXML
- "inencoding" => "UTF-8",
- "outencoding" => "UTF-8",
- "stylesheet" => [], # for HTML
- "mathml" => nil, # for HTML
- "language" => "ja", # for HTML
- "deprecated-blocklines" => nil,
- "footnotetext" => false,
- "htmlext" => "html",
- "htmlversion" => 4,
- })
opts = OptionParser.new
opts.version = ReVIEW::VERSION
opts.banner = "Usage: #{File.basename($0)} [--target=FMT]"
- opts.on('--yaml=YAML', 'Read configurations from YAML file.') do |yaml|
- require 'yaml'
- config = config.merge(YAML.load_file(yaml))
- end
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc| config["inencoding"] = enc }
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc| config["outencoding"] = enc }
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') {|yaml| config["yaml"] = yaml}
opts.on('-c', '--check', 'Check manuscript') { check_only = true }
opts.on('--level=LVL', 'Section level to append number.') {|lvl| config["secnolevel"] = lvl.to_i }
opts.on('--toclevel=LVL', 'Section level to append number.') {|lvl| config["toclevel"] = lvl.to_i }
opts.on('--nolfinxml', 'Do not insert LF in XML. (idgxml)') { config["nolf"] = true }
opts.on('--structuredxml', 'Produce XML with structured sections. (idgxml)') { config["structuredxml"] = true }
opts.on('--table=WIDTH', 'Default table width. (idgxml)') {|tbl| config["tableopt"] = tbl }
opts.on('--listinfo', 'Append listinfo tag to lists to indicate begin/end. (idgxml)') { config["listinfo"] = true }
- opts.on('--chapref="before,middle,after"', 'Chapref decoration.') {|cdec| config["chapref"] = cdec }
- opts.on('--subdirmode', 'Use chapter/id.ext path style to find images. (deprecated)') do
- STDERR.puts "Warning: --subdirmode is deprecated. Images are automatically detected."
- end
- opts.on('--singledirmode', 'Use id.ext path style to find images. (deprecated)') do
- STDERR.puts "Warning: --singledirmode is deprecated. Images are automatically detected."
- end
+ opts.on('--chapref="before,middle,after"', 'Chapref decoration. (idgxml)') {|cdec| config["chapref"] = cdec }
opts.on('--chapterlink', 'make chapref hyperlink') { config["chapterlink"] = true }
opts.on('--stylesheet=file', 'Stylesheet file for HTML (comma separated)') {|files| config["stylesheet"] = files.split(/\s*,\s*/) }
opts.on('--mathml', 'Use MathML for TeX equation in HTML') do
config["mathml"] = true
end
@@ -98,22 +69,16 @@
end
opts.on('--epubversion=VERSION', 'EPUB version.') do |v|
v = v.to_i
config["epubversion"] = v if v == 2 || v == 3
end
- opts.on('--hdnumberingmode', 'Output numbering headlines. (deprecated)') { config["hdnumberingmode"] = true }
- opts.on('--deprecated-blocklines', 'Disable paragrahs in block tags. Treat physical line as a paragraph. (deprecated)') { config["deprecated-blocklines"] = true }
opts.on('--target=FMT', 'Target format.') {|fmt| target = fmt } unless target
opts.on('--footnotetext',
'Use footnotetext and footnotemark instead of footnote (latex)') {
config["footnotetext"] = true
}
opts.on('--draft', 'use draft mode(inline comment)') { config["draft"] = true }
- opts.on('-a', '--all', 'Compile all chapters.') do
- mode = :dir
- basedir = nil
- end
opts.on('--directory=DIR', 'Compile all chapters in DIR.') do |path|
mode = :dir
basedir = path
end
opts.on('--output-file=FILENAME', 'Write all results into file instead of stdout.') do |filename|
@@ -141,13 +106,31 @@
$stderr.puts opts.help
exit 1
end
begin
+ loader = ReVIEW::YAMLLoader.new
+ if config["yaml"]
+ config.deep_merge!(loader.load_file(config["yaml"]))
+ else
+ if File.exist?(DEFAULT_CONFIG_FILENAME)
+ config.deep_merge!(loader.load_file(DEFAULT_CONFIG_FILENAME))
+ end
+ end
+
config["builder"] = target
ReVIEW::I18n.setup(config["language"])
+ begin
+ config.check_version(ReVIEW::VERSION)
+ rescue ReVIEW::ConfigError => e
+ warn e.message
+ end
+ if ARGV.blank?
+ mode = :dir
+ end
+
case mode
when :files
if ARGV.empty?
error 'no input'
exit 1
@@ -171,15 +154,15 @@
book = basedir ? ReVIEW::Book.load(basedir) : ReVIEW::Book::Base.load
book.config = config
compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
book.chapters.each do |chap|
str = compiler.compile(chap)
- write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
+ write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
end
# PART
book.parts_in_file.each do |part|
str = compiler.compile(part)
- write "#{part.name}#{compiler.strategy.extname}", str unless check_only
+ write "#{part.name}#{compiler.strategy.extname}", str unless check_only
end
else
raise "must not happen: #{mode}"
end
rescue ReVIEW::ApplicationError => err