Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

章を選択してビルド実行できるようにする #1467

Merged
merged 6 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -394,6 +396,11 @@ def build_chap(chap, base_path, basetmpdir, ispart)
end
end

if @buildonly && [email protected]?(id)
warn "skip #{id}.re"
return
end

htmlfile = "#{id}.#{@config['htmlext']}"
write_buildlogtxt(basetmpdir, htmlfile, filename)
log("Create #{htmlfile} from #{filename}.")
Expand Down
28 changes: 21 additions & 7 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -172,20 +174,32 @@ 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 && [email protected]?(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
end

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 && [email protected]?(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

Expand Down
8 changes: 7 additions & 1 deletion lib/review/textmaker.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 && [email protected]?(id)
warn "skip #{id}.re"
return
end

textfile = "#{id}.txt"

Expand Down
9 changes: 8 additions & 1 deletion lib/review/webmaker.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -186,6 +188,11 @@ def build_chap(chap, base_path, basetmpdir, ispart)
end
id = File.basename(filename).sub(/\.re\Z/, '')

if @buildonly && [email protected]?(id)
warn "skip #{id}.re"
return
end

htmlfile = "#{id}.#{@config['htmlext']}"

if @config['params'].present?
Expand Down
16 changes: 10 additions & 6 deletions samples/sample-book/src/lib/tasks/review.rake
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions samples/syntax-book/lib/tasks/review.rake
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions test/test_pdfmaker_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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')
assert !File.exist?(builddir)

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
Expand Down Expand Up @@ -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`
Expand Down