diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index e6b55149c..9edea3ba2 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -1,4 +1,4 @@ -# 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 @@ -73,6 +73,7 @@ def self.execute(*args) def parse_opts(args) cmd_config = {} opts = OptionParser.new + @buildonly = nil opts.banner = 'Usage: review-epubmaker [options] configfile [export_filename]' opts.version = ReVIEW::VERSION @@ -81,6 +82,7 @@ def parse_opts(args) 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 @@ -394,6 +396,11 @@ def build_chap(chap, base_path, basetmpdir, ispart) 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}.") diff --git a/lib/review/pdfmaker.rb b/lib/review/pdfmaker.rb index 6f40a1b93..a812ef206 100644 --- a/lib/review/pdfmaker.rb +++ b/lib/review/pdfmaker.rb @@ -100,6 +100,7 @@ def self.execute(*args) def parse_opts(args) cmd_config = {} opts = OptionParser.new + @buildonly = nil opts.banner = 'Usage: review-pdfmaker configfile' opts.version = ReVIEW::VERSION @@ -109,6 +110,7 @@ def parse_opts(args) end opts.on('--[no-]debug', 'Keep temporary files.') { |debug| cmd_config['debug'] = debug } opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true } + 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 @@ -172,8 +174,13 @@ def make_input_files(book) if part.name.present? @config['use_part'] = true if part.file? - output_chaps(part.name) - input_files['CHAPS'] << %Q(\\input{#{part.name}.tex}\n) + if @buildonly && !@buildonly.include?(part.name) + warn "skip #{part.name}.re" + input_files['CHAPS'] << %Q(\\part{}\n) + else + output_chaps(part.name) + input_files['CHAPS'] << %Q(\\input{#{part.name}.tex}\n) + end else input_files['CHAPS'] << %Q(\\part{#{part.name}}\n) end @@ -181,11 +188,18 @@ def make_input_files(book) part.chapters.each do |chap| filename = File.basename(chap.path, '.*') - output_chaps(filename) - input_files['PREDEF'] << "\\input{#{filename}.tex}\n" if chap.on_predef? - input_files['CHAPS'] << "\\input{#{filename}.tex}\n" if chap.on_chaps? - input_files['APPENDIX'] << "\\input{#{filename}.tex}\n" if chap.on_appendix? - input_files['POSTDEF'] << "\\input{#{filename}.tex}\n" if chap.on_postdef? + entry = "\\input{#{filename}.tex}\n" + if @buildonly && !@buildonly.include?(filename) + warn "skip #{filename}.re" + entry = "\\chapter{}\n" + else + output_chaps(filename) + end + + input_files['PREDEF'] << entry if chap.on_predef? + input_files['CHAPS'] << entry if chap.on_chaps? + input_files['APPENDIX'] << entry if chap.on_appendix? + input_files['POSTDEF'] << entry if chap.on_postdef? end end diff --git a/lib/review/textmaker.rb b/lib/review/textmaker.rb index 7661da586..12f8c3bab 100644 --- a/lib/review/textmaker.rb +++ b/lib/review/textmaker.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2019 Kenshi Muto +# Copyright (c) 2018-2020 Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -45,10 +45,12 @@ def self.execute(*args) def parse_opts(args) cmd_config = {} opts = OptionParser.new + @buildonly = nil opts.banner = 'Usage: review-textmaker [-n] configfile' opts.version = ReVIEW::VERSION opts.on('-n', 'No decoration.') { @plaintext = true } + opts.on('-y', '--only file1,file2,...', 'Build only specified files.') { |v| @buildonly = v.split(/\s*,\s*/).map { |m| m.strip.sub(/\.re\Z/, '') } } opts.on('--help', 'Prints this message and quit.') do puts opts.help exit 0 @@ -154,6 +156,10 @@ def build_chap(chap, base_path, basetmpdir, ispart) filename = Pathname.new(chap.path).relative_path_from(base_path).to_s end id = File.basename(filename).sub(/\.re\Z/, '') + if @buildonly && !@buildonly.include?(id) + warn "skip #{id}.re" + return + end textfile = "#{id}.txt" diff --git a/lib/review/webmaker.rb b/lib/review/webmaker.rb index 9f140b0d4..70cdfc18c 100644 --- a/lib/review/webmaker.rb +++ b/lib/review/webmaker.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2018 Masayoshi Takahashi, Masanori Kado, Kenshi Muto +# Copyright (c) 2016-2020 Masayoshi Takahashi, Masanori Kado, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -50,6 +50,7 @@ def self.execute(*args) def parse_opts(args) cmd_config = {} opts = OptionParser.new + @buildonly = nil opts.banner = 'Usage: review-webmaker [option] configfile' opts.version = ReVIEW::VERSION @@ -58,6 +59,7 @@ def parse_opts(args) exit 0 end opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true } + 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 @@ -186,6 +188,11 @@ def build_chap(chap, base_path, basetmpdir, ispart) end id = File.basename(filename).sub(/\.re\Z/, '') + if @buildonly && !@buildonly.include?(id) + warn "skip #{id}.re" + return + end + htmlfile = "#{id}.#{@config['htmlext']}" if @config['params'].present? diff --git a/samples/sample-book/src/lib/tasks/review.rake b/samples/sample-book/src/lib/tasks/review.rake index c03fa258e..4633abe87 100644 --- a/samples/sample-book/src/lib/tasks/review.rake +++ b/samples/sample-book/src/lib/tasks/review.rake @@ -1,4 +1,4 @@ -# Copyright (c) 2006-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado. +# Copyright (c) 2006-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,11 @@ WEBROOT = ENV['REVIEW_WEBROOT'] || 'webroot' TEXTROOT = BOOK + '-text' TOPROOT = BOOK + '-text' IDGXMLROOT = BOOK + '-idgxml' +PDF_OPTIONS = ENV['REVIEW_PDF_OPTIONS'] || '' +EPUB_OPTIONS = ENV['REVIEW_EPUB_OPTIONS'] || '' +WEB_OPTIONS = ENV['REVIEW_WEB_OPTIONS'] || '' IDGXML_OPTIONS = ENV['REVIEW_IDGXML_OPTIONS'] || '' +TEXT_OPTIONS = ENV['REVIEW_TEXT_OPTIONS'] || '' def build(mode, chapter) sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp") @@ -76,12 +80,12 @@ task web: WEBROOT desc 'generate text file (without decoration)' task plaintext: TEXTROOT do - sh "review-textmaker -n #{CONFIG_FILE}" + sh "review-textmaker #{TEXT_OPTIONS} -n #{CONFIG_FILE}" end desc 'generate (decorated) text file' task text: TOPROOT do - sh "review-textmaker #{CONFIG_FILE}" + sh "review-textmaker #{TEXT_OPTIONS} #{CONFIG_FILE}" end desc 'generate IDGXML file' @@ -100,17 +104,17 @@ SRC_PDF = FileList['layouts/*.erb', 'sty/**/*.sty'] file BOOK_PDF => SRC + SRC_PDF do FileUtils.rm_rf([BOOK_PDF, BOOK, BOOK + '-pdf']) - sh "review-pdfmaker #{CONFIG_FILE}" + sh "review-pdfmaker #{PDF_OPTIONS} #{CONFIG_FILE}" end file BOOK_EPUB => SRC + SRC_EPUB do FileUtils.rm_rf([BOOK_EPUB, BOOK, BOOK + '-epub']) - sh "review-epubmaker #{CONFIG_FILE}" + sh "review-epubmaker #{EPUB_OPTIONS} #{CONFIG_FILE}" end file WEBROOT => SRC do FileUtils.rm_rf([WEBROOT]) - sh "review-webmaker #{CONFIG_FILE}" + sh "review-webmaker #{WEB_OPTIONS} #{CONFIG_FILE}" end file TEXTROOT => SRC do diff --git a/samples/syntax-book/lib/tasks/review.rake b/samples/syntax-book/lib/tasks/review.rake index 6cfc3eae5..559469ec6 100644 --- a/samples/syntax-book/lib/tasks/review.rake +++ b/samples/syntax-book/lib/tasks/review.rake @@ -1,4 +1,4 @@ -# Copyright (c) 2006-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado. +# Copyright (c) 2006-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,11 @@ WEBROOT = ENV['REVIEW_WEBROOT'] || 'webroot' TEXTROOT = BOOK + '-text' TOPROOT = BOOK + '-text' IDGXMLROOT = BOOK + '-idgxml' +PDF_OPTIONS = ENV['REVIEW_PDF_OPTIONS'] || '' +EPUB_OPTIONS = ENV['REVIEW_EPUB_OPTIONS'] || '' +WEB_OPTIONS = ENV['REVIEW_WEB_OPTIONS'] || '' IDGXML_OPTIONS = ENV['REVIEW_IDGXML_OPTIONS'] || '' +TEXT_OPTIONS = ENV['REVIEW_TEXT_OPTIONS'] || '' def build(mode, chapter) sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp") @@ -76,12 +80,12 @@ task web: WEBROOT desc 'generate text file (without decoration)' task plaintext: TEXTROOT do - sh "review-textmaker -n #{CONFIG_FILE}" + sh "review-textmaker #{TEXT_OPTIONS} -n #{CONFIG_FILE}" end desc 'generate (decorated) text file' task text: TOPROOT do - sh "review-textmaker #{CONFIG_FILE}" + sh "review-textmaker #{TEXT_OPTIONS} #{CONFIG_FILE}" end desc 'generate IDGXML file' @@ -100,17 +104,17 @@ SRC_PDF = FileList['layouts/*.erb', 'sty/**/*.sty'] file BOOK_PDF => SRC + SRC_PDF do FileUtils.rm_rf([BOOK_PDF, BOOK, BOOK + '-pdf']) - sh "review-pdfmaker #{CONFIG_FILE}" + sh "review-pdfmaker #{PDF_OPTIONS} #{CONFIG_FILE}" end file BOOK_EPUB => SRC + SRC_EPUB do FileUtils.rm_rf([BOOK_EPUB, BOOK, BOOK + '-epub']) - sh "review-epubmaker #{CONFIG_FILE}" + sh "review-epubmaker #{EPUB_OPTIONS} #{CONFIG_FILE}" end file WEBROOT => SRC do FileUtils.rm_rf([WEBROOT]) - sh "review-webmaker #{CONFIG_FILE}" + sh "review-webmaker #{WEB_OPTIONS} #{CONFIG_FILE}" end file TEXTROOT => SRC do diff --git a/test/test_pdfmaker_cmd.rb b/test/test_pdfmaker_cmd.rb index de1281020..6f8aadc86 100644 --- a/test/test_pdfmaker_cmd.rb +++ b/test/test_pdfmaker_cmd.rb @@ -20,7 +20,7 @@ def teardown ENV['RUBYLIB'] = @old_rubylib end - def common_buildpdf(bookdir, templatedir, configfile, targetpdffile) + def common_buildpdf(bookdir, templatedir, configfile, targetpdffile, option = nil) if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM config = prepare_samplebook(@tmpdir1, bookdir, templatedir, configfile) builddir = File.join(@tmpdir1, config['bookname'] + '-pdf') @@ -28,7 +28,7 @@ def common_buildpdf(bookdir, templatedir, configfile, targetpdffile) ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) Dir.chdir(@tmpdir1) do - _o, e, s = Open3.capture3("#{ruby_cmd} -S #{REVIEW_PDFMAKER} #{configfile}") + _o, e, s = Open3.capture3("#{ruby_cmd} -S #{REVIEW_PDFMAKER} #{option} #{configfile}") if !e.empty? && !s.success? STDERR.puts e end @@ -88,6 +88,16 @@ def test_pdfmaker_cmd_syntax_jsbook_print common_buildpdf('syntax-book', 'review-jsbook', 'config-print.yml', 'syntax-book.pdf') end + def test_pdfmaker_cmd_syntax_jsbook_print_buildonly + begin + `uplatex -v` + rescue + $stderr.puts 'skip test_pdfmaker_cmd_syntax_jsbook_print_buildonly' + return true + end + common_buildpdf('syntax-book', 'review-jsbook', 'config-print.yml', 'syntax-book.pdf', '-y ch01') + end + def test_pdfmaker_cmd_syntax_jsbook_ebook begin `uplatex -v`