review 2.5.0 → 3.0.0.preview1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -10
- data/.travis.yml +11 -2
- data/NEWS.ja.md +89 -17
- data/NEWS.md +92 -0
- data/README.md +1 -1
- data/Rakefile +0 -13
- data/bin/review-catalog-converter +83 -37
- data/bin/review-check +17 -5
- data/bin/review-compile +1 -1
- data/bin/review-index +6 -0
- data/bin/review-init +3 -155
- data/bin/review-preproc +0 -5
- data/bin/review-validate +21 -7
- data/bin/review-vol +13 -5
- data/doc/config.yml.sample +12 -7
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +39 -3
- data/doc/format.md +39 -3
- data/doc/format_idg.ja.md +0 -4
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/doc/sample.css +7 -0
- data/lib/epubmaker/content.rb +31 -12
- data/lib/epubmaker/epubcommon.rb +10 -3
- data/lib/epubmaker/epubv2.rb +11 -3
- data/lib/epubmaker/epubv3.rb +11 -3
- data/lib/epubmaker/producer.rb +55 -20
- data/lib/review/book/base.rb +63 -48
- data/lib/review/book/chapter.rb +19 -7
- data/lib/review/book/compilable.rb +5 -20
- data/lib/review/book/image_finder.rb +10 -3
- data/lib/review/book/index.rb +30 -9
- data/lib/review/book/part.rb +9 -6
- data/lib/review/book.rb +0 -14
- data/lib/review/builder.rb +110 -18
- data/lib/review/catalog.rb +24 -4
- data/lib/review/compiler.rb +3 -1
- data/lib/review/configure.rb +43 -9
- data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
- data/lib/review/epubmaker.rb +129 -85
- data/lib/review/htmlbuilder.rb +76 -58
- data/lib/review/htmlutils.rb +20 -13
- data/lib/review/i18n.rb +6 -2
- data/lib/review/idgxmlbuilder.rb +52 -41
- data/lib/review/init.rb +194 -0
- data/lib/review/latexbuilder.rb +118 -34
- data/lib/review/latexutils.rb +5 -5
- data/lib/review/logger.rb +2 -1
- data/lib/review/makerhelper.rb +1 -1
- data/lib/review/markdownbuilder.rb +66 -6
- data/lib/review/md2inaobuilder.rb +2 -2
- data/lib/review/pdfmaker.rb +74 -22
- data/lib/review/plaintextbuilder.rb +8 -4
- data/lib/review/preprocessor.rb +14 -17
- data/lib/review/sec_counter.rb +8 -2
- data/lib/review/textmaker.rb +2 -2
- data/lib/review/textutils.rb +9 -2
- data/lib/review/tocparser.rb +7 -4
- data/lib/review/tocprinter.rb +3 -1
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +19 -7
- data/lib/review/webtocprinter.rb +8 -4
- data/review.gemspec +4 -3
- data/templates/latex/config.erb +84 -0
- data/templates/latex/layout.tex.erb +76 -361
- data/templates/latex/review-jlreq/README.md +22 -0
- data/templates/latex/review-jlreq/review-base.sty +178 -0
- data/templates/latex/review-jlreq/review-custom.sty +1 -0
- data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
- data/templates/latex/review-jlreq/review-style.sty +149 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
- data/templates/latex/review-jsbook/jumoline.sty +310 -0
- data/templates/latex/review-jsbook/plistings.sty +326 -0
- data/templates/latex/review-jsbook/review-base.sty +405 -0
- data/templates/latex/review-jsbook/review-custom.sty +1 -0
- data/templates/latex/review-jsbook/review-style.sty +38 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
- data/templates/latex-compat2/layout.tex.erb +387 -0
- data/test/assets/test_template.tex +105 -235
- data/test/assets/test_template_backmatter.tex +133 -14
- data/test/book_test_helper.rb +1 -1
- data/test/run_test.rb +2 -0
- data/test/sample-book/src/Rakefile +11 -6
- data/test/sample-book/src/config.yml +2 -2
- data/test/sample-book/src/sty/reviewmacro.sty +1 -39
- data/test/sample-book/src/style.css +6 -0
- data/test/syntax-book/config.yml +1 -1
- data/test/test_book.rb +13 -16
- data/test/test_book_chapter.rb +4 -10
- data/test/test_book_part.rb +4 -3
- data/test/test_catalog.rb +15 -4
- data/test/test_helper.rb +2 -2
- data/test/test_htmlbuilder.rb +78 -10
- data/test/test_htmlutils.rb +12 -5
- data/test/test_idgxmlbuilder.rb +1 -1
- data/test/test_latexbuilder.rb +94 -49
- data/test/test_latexbuilder_v2.rb +1077 -0
- data/test/test_logger.rb +20 -0
- data/test/test_markdownbuilder.rb +10 -0
- data/test/test_pdfmaker.rb +6 -7
- data/test/test_plaintextbuilder.rb +1 -1
- data/test/test_review_ext.rb +0 -1
- data/test/test_rstbuilder.rb +1 -1
- data/test/test_topbuilder.rb +19 -7
- data/test/test_webtocprinter.rb +14 -14
- data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
- data/vendor/plistings/.gitignore +9 -0
- data/vendor/plistings/LICENSE +21 -0
- data/vendor/plistings/README.md +18 -0
- data/vendor/plistings/plistings.sty +326 -0
- data/vendor/plistings/test1.tex +174 -0
- data/vendor/plistings/test2.tex +54 -0
- metadata +48 -19
- data/lib/review/unfold.rb +0 -129
- data/test/CHAPS +0 -2
- data/test/bib.re +0 -13
- data/test/test.re +0 -43
data/lib/review/pdfmaker.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2018 Kenshi Muto and Masayoshi Takahashi
|
2
2
|
#
|
3
3
|
# This program is free software.
|
4
4
|
# You can distribute or modify this program under the terms of
|
@@ -10,6 +10,7 @@ require 'yaml'
|
|
10
10
|
require 'fileutils'
|
11
11
|
require 'erb'
|
12
12
|
require 'tmpdir'
|
13
|
+
require 'open3'
|
13
14
|
|
14
15
|
require 'review/i18n'
|
15
16
|
require 'review/book'
|
@@ -35,8 +36,20 @@ module ReVIEW
|
|
35
36
|
@input_files = Hash.new { |h, key| h[key] = '' }
|
36
37
|
end
|
37
38
|
|
39
|
+
def system_with_info(*args)
|
40
|
+
@logger.info args.join(' ')
|
41
|
+
out, status = Open3.capture2e(*args)
|
42
|
+
unless status.success?
|
43
|
+
@logger.error "execution error\n\nError log:\n" + out
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
def system_or_raise(*args)
|
39
|
-
|
48
|
+
@logger.info args.join(' ')
|
49
|
+
out, status = Open3.capture2e(*args)
|
50
|
+
unless status.success?
|
51
|
+
error "failed to run command: #{args.join(' ')}\n\nError log:\n" + out
|
52
|
+
end
|
40
53
|
end
|
41
54
|
|
42
55
|
def error(msg)
|
@@ -59,7 +72,9 @@ module ReVIEW
|
|
59
72
|
def build_path
|
60
73
|
if @config['debug']
|
61
74
|
path = "#{@config['bookname']}-pdf"
|
62
|
-
|
75
|
+
if File.exist?(path)
|
76
|
+
FileUtils.rm_rf(path, secure: true)
|
77
|
+
end
|
63
78
|
Dir.mkdir(path)
|
64
79
|
path
|
65
80
|
else
|
@@ -71,7 +86,7 @@ module ReVIEW
|
|
71
86
|
return unless @compile_errors
|
72
87
|
|
73
88
|
if ignore_errors
|
74
|
-
|
89
|
+
@logger.info 'compile error, but try to generate PDF file'
|
75
90
|
else
|
76
91
|
error 'compile error, No PDF file output.'
|
77
92
|
end
|
@@ -203,7 +218,9 @@ module ReVIEW
|
|
203
218
|
end
|
204
219
|
|
205
220
|
call_hook('hook_beforemakeindex')
|
206
|
-
|
221
|
+
if @config['pdfmaker']['makeindex'] && File.exist?('book.idx')
|
222
|
+
system_or_raise("#{makeindex_command} #{makeindex_options} book")
|
223
|
+
end
|
207
224
|
call_hook('hook_aftermakeindex')
|
208
225
|
|
209
226
|
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
@@ -218,6 +235,7 @@ module ReVIEW
|
|
218
235
|
|
219
236
|
def generate_pdf(yamlfile)
|
220
237
|
remove_old_file
|
238
|
+
erb_config
|
221
239
|
@path = build_path
|
222
240
|
begin
|
223
241
|
@compile_errors = nil
|
@@ -230,10 +248,16 @@ module ReVIEW
|
|
230
248
|
|
231
249
|
check_compile_status(@config['ignore-errors'])
|
232
250
|
|
251
|
+
# for backward compatibility
|
252
|
+
@config['usepackage'] = ''
|
253
|
+
@config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
|
254
|
+
|
233
255
|
copy_images(@config['imagedir'], File.join(@path, @config['imagedir']))
|
234
256
|
copy_sty(File.join(Dir.pwd, 'sty'), @path)
|
235
257
|
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'fd')
|
236
258
|
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'cls')
|
259
|
+
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'erb')
|
260
|
+
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'tex')
|
237
261
|
copy_sty(Dir.pwd, @path, 'tex')
|
238
262
|
|
239
263
|
build_pdf
|
@@ -245,7 +269,7 @@ module ReVIEW
|
|
245
269
|
end
|
246
270
|
|
247
271
|
def output_chaps(filename, _yamlfile)
|
248
|
-
|
272
|
+
@logger.info "compiling #{filename}.tex"
|
249
273
|
begin
|
250
274
|
@converter.convert(filename + '.re', File.join(@path, filename + '.tex'))
|
251
275
|
rescue => e
|
@@ -262,13 +286,13 @@ module ReVIEW
|
|
262
286
|
Dir.mkdir(to)
|
263
287
|
ReVIEW::MakerHelper.copy_images_to_dir(from, to)
|
264
288
|
Dir.chdir(to) do
|
265
|
-
images = Dir.glob('**/*').find_all { |f| File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf|ai|eps|tif)\z/ }
|
289
|
+
images = Dir.glob('**/*').find_all { |f| File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf|ai|eps|tif)\z/i }
|
266
290
|
break if images.empty?
|
267
291
|
if @config['pdfmaker']['bbox']
|
268
|
-
|
292
|
+
system_with_info('extractbb', '-B', @config['pdfmaker']['bbox'], *images)
|
269
293
|
system_or_raise('ebb', '-B', @config['pdfmaker']['bbox'], *images) unless system('extractbb', '-B', @config['pdfmaker']['bbox'], '-m', *images)
|
270
294
|
else
|
271
|
-
|
295
|
+
system_with_info('extractbb', *images)
|
272
296
|
system_or_raise('ebb', *images) unless system('extractbb', '-m', *images)
|
273
297
|
end
|
274
298
|
end
|
@@ -276,7 +300,9 @@ module ReVIEW
|
|
276
300
|
|
277
301
|
def make_custom_page(file)
|
278
302
|
file_sty = file.to_s.sub(/\.[^.]+\Z/, '.tex')
|
279
|
-
|
303
|
+
if File.exist?(file_sty)
|
304
|
+
return File.read(file_sty)
|
305
|
+
end
|
280
306
|
nil
|
281
307
|
end
|
282
308
|
|
@@ -350,21 +376,28 @@ module ReVIEW
|
|
350
376
|
d.strftime(ReVIEW::I18n.t('date_format'))
|
351
377
|
end
|
352
378
|
|
353
|
-
def
|
379
|
+
def erb_config
|
380
|
+
@texcompiler = File.basename(@config['texcommand'], '.*')
|
354
381
|
dclass = @config['texdocumentclass'] || []
|
355
382
|
@documentclass = dclass[0] || 'jsbook'
|
356
383
|
@documentclassoption = dclass[1] || 'uplatex,oneside'
|
384
|
+
if @config['dvicommand'] =~ /dvipdfmx/ && @documentclassoption !~ /dvipdfmx/
|
385
|
+
@documentclassoption = "dvipdfmx,#{@documentclassoption}".sub(/,\Z/, '')
|
386
|
+
end
|
357
387
|
|
358
388
|
@okuduke = make_colophon
|
359
389
|
@authors = make_authors
|
360
390
|
|
361
|
-
@
|
391
|
+
@custom_coverpage = make_custom_page(@config['cover']) || make_custom_page(@config['coverfile'])
|
392
|
+
@custom_titlepage = make_custom_page(@config['titlefile'])
|
362
393
|
@custom_originaltitlepage = make_custom_page(@config['originaltitlefile'])
|
363
394
|
@custom_creditpage = make_custom_page(@config['creditfile'])
|
364
395
|
|
365
396
|
@custom_profilepage = make_custom_page(@config['profile'])
|
366
397
|
@custom_advfilepage = make_custom_page(@config['advfile'])
|
367
|
-
|
398
|
+
if @config['colophon'] && @config['colophon'].is_a?(String)
|
399
|
+
@custom_colophonpage = make_custom_page(@config['colophon'])
|
400
|
+
end
|
368
401
|
@custom_backcoverpage = make_custom_page(@config['backcover'])
|
369
402
|
|
370
403
|
if @config['pubhistory']
|
@@ -390,17 +423,31 @@ module ReVIEW
|
|
390
423
|
@locale_latex['postchaptername'] = chapter_tuple[1]
|
391
424
|
@locale_latex['preappendixname'] = appendix_tuple[0]
|
392
425
|
@locale_latex['postappendixname'] = appendix_tuple[1]
|
426
|
+
end
|
393
427
|
|
394
|
-
|
395
|
-
layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
|
396
|
-
template = layout_file if File.exist?(layout_file)
|
397
|
-
|
428
|
+
def erb_content(file)
|
398
429
|
@texcompiler = File.basename(@config['texcommand'], '.*')
|
399
|
-
|
400
|
-
erb
|
430
|
+
erb = ReVIEW::Template.load(file, '-')
|
431
|
+
@logger.debug "erb processes #{File.basename(file)}" if @config['debug']
|
401
432
|
erb.result(binding)
|
402
433
|
end
|
403
434
|
|
435
|
+
def latex_config
|
436
|
+
erb_content(File.expand_path('./latex/config.erb', ReVIEW::Template::TEMPLATE_DIR))
|
437
|
+
end
|
438
|
+
|
439
|
+
def template_content
|
440
|
+
template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
|
441
|
+
if @config.check_version('2', exception: false)
|
442
|
+
template = File.expand_path('./latex-compat2/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
|
443
|
+
end
|
444
|
+
layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
|
445
|
+
if File.exist?(layout_file)
|
446
|
+
template = layout_file
|
447
|
+
end
|
448
|
+
erb_content(template)
|
449
|
+
end
|
450
|
+
|
404
451
|
def copy_sty(dirname, copybase, extname = 'sty')
|
405
452
|
unless File.directory?(dirname)
|
406
453
|
warn "No such directory - #{dirname}"
|
@@ -408,9 +455,14 @@ module ReVIEW
|
|
408
455
|
end
|
409
456
|
|
410
457
|
Dir.open(dirname) do |dir|
|
411
|
-
dir.each do |fname|
|
412
|
-
|
413
|
-
|
458
|
+
dir.sort.each do |fname|
|
459
|
+
next unless File.extname(fname).downcase == '.' + extname
|
460
|
+
FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
|
461
|
+
if extname == 'erb'
|
462
|
+
File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
|
463
|
+
f.print erb_content(File.join(dirname, fname))
|
464
|
+
end
|
465
|
+
else
|
414
466
|
FileUtils.cp File.join(dirname, fname), copybase
|
415
467
|
end
|
416
468
|
end
|
@@ -260,7 +260,7 @@ module ReVIEW
|
|
260
260
|
rows = adjust_n_cols(rows)
|
261
261
|
|
262
262
|
begin
|
263
|
-
table_header
|
263
|
+
table_header(id, caption) if caption.present?
|
264
264
|
rescue KeyError
|
265
265
|
error "no such table: #{id}"
|
266
266
|
end
|
@@ -298,7 +298,7 @@ module ReVIEW
|
|
298
298
|
|
299
299
|
def imgtable(_lines, id, caption = nil, _metric = nil)
|
300
300
|
blank
|
301
|
-
table_header
|
301
|
+
table_header(id, caption) if caption.present?
|
302
302
|
blank
|
303
303
|
end
|
304
304
|
|
@@ -390,7 +390,9 @@ module ReVIEW
|
|
390
390
|
def inline_hd_chap(chap, id)
|
391
391
|
if chap.number
|
392
392
|
n = chap.headline_index.number(id)
|
393
|
-
|
393
|
+
if @book.config['secnolevel'] >= n.split('.').size
|
394
|
+
return I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
|
395
|
+
end
|
394
396
|
end
|
395
397
|
I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
|
396
398
|
rescue KeyError
|
@@ -624,7 +626,9 @@ module ReVIEW
|
|
624
626
|
chs = ['', '「', '」']
|
625
627
|
if @book.config['chapref']
|
626
628
|
chs2 = @book.config['chapref'].split(',')
|
627
|
-
|
629
|
+
if chs2.size != 3
|
630
|
+
error '--chapsplitter must have exactly 3 parameters with comma.'
|
631
|
+
end
|
628
632
|
chs = chs2
|
629
633
|
end
|
630
634
|
"#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
|
data/lib/review/preprocessor.rb
CHANGED
@@ -43,12 +43,6 @@ module ReVIEW
|
|
43
43
|
class Preprocessor
|
44
44
|
include ErrorUtils
|
45
45
|
|
46
|
-
def self.strip(f)
|
47
|
-
buf = ''
|
48
|
-
Strip.new(f).each { |line| buf << line.rstrip << "\n" }
|
49
|
-
buf
|
50
|
-
end
|
51
|
-
|
52
46
|
class Strip
|
53
47
|
def initialize(f)
|
54
48
|
@f = f
|
@@ -69,12 +63,6 @@ module ReVIEW
|
|
69
63
|
end
|
70
64
|
nil
|
71
65
|
end
|
72
|
-
|
73
|
-
def each
|
74
|
-
@f.each do |line|
|
75
|
-
yield line unless /\A\#@/ =~ line
|
76
|
-
end
|
77
|
-
end
|
78
66
|
end
|
79
67
|
|
80
68
|
def initialize(repo, param)
|
@@ -118,8 +106,11 @@ module ReVIEW
|
|
118
106
|
when /\A\#@mapfile/
|
119
107
|
direc = parse_directive(line, 1, 'eval')
|
120
108
|
path = expand(direc.arg)
|
121
|
-
|
122
|
-
|
109
|
+
if direc['eval']
|
110
|
+
ent = evaluate(path, ent)
|
111
|
+
else
|
112
|
+
ent = @repository.fetch_file(path)
|
113
|
+
end
|
123
114
|
replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
|
124
115
|
|
125
116
|
when /\A\#@map(?:range)?/
|
@@ -155,7 +146,9 @@ module ReVIEW
|
|
155
146
|
def replace_block(f, directive_line, newlines, with_lineno)
|
156
147
|
@f.print directive_line
|
157
148
|
newlines.each do |line|
|
158
|
-
|
149
|
+
if with_lineno
|
150
|
+
print_number line.number
|
151
|
+
end
|
159
152
|
@f.print line.string
|
160
153
|
end
|
161
154
|
skip_list f
|
@@ -404,7 +397,9 @@ module ReVIEW
|
|
404
397
|
case direction
|
405
398
|
when 'begin'
|
406
399
|
key = "#{type}/#{spec}"
|
407
|
-
|
400
|
+
if curr[key]
|
401
|
+
error "begin x2: #{key}"
|
402
|
+
end
|
408
403
|
(repo[type] ||= {})[spec] = curr[key] = []
|
409
404
|
when 'end'
|
410
405
|
curr.delete("#{type}/#{spec}") or
|
@@ -417,7 +412,9 @@ module ReVIEW
|
|
417
412
|
type = check_type($1)
|
418
413
|
spec = check_spec($2)
|
419
414
|
key = "#{type}/#{spec}"
|
420
|
-
|
415
|
+
if curr[key]
|
416
|
+
error "begin x2: #{key}"
|
417
|
+
end
|
421
418
|
(repo[type] ||= {})[spec] = curr[key] = []
|
422
419
|
opened.push [type, spec]
|
423
420
|
|
data/lib/review/sec_counter.rb
CHANGED
@@ -22,12 +22,18 @@ module ReVIEW
|
|
22
22
|
def inc(level)
|
23
23
|
n = level - 2
|
24
24
|
@counter[n] += 1 if n >= 0
|
25
|
-
|
25
|
+
if @counter.size > n
|
26
|
+
(n + 1..@counter.size).each do |i|
|
27
|
+
@counter[i] = 0
|
28
|
+
end
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
def anchor(level)
|
29
33
|
str = @chapter.format_number(false)
|
30
|
-
0.upto(level - 2)
|
34
|
+
0.upto(level - 2) do |i|
|
35
|
+
str << "-#{@counter[i]}"
|
36
|
+
end
|
31
37
|
str
|
32
38
|
end
|
33
39
|
|
data/lib/review/textmaker.rb
CHANGED
@@ -127,7 +127,7 @@ module ReVIEW
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def build_part(part, basetmpdir, textfile)
|
130
|
-
File.open(
|
130
|
+
File.open(File.join(basetmpdir, textfile), 'w') do |f|
|
131
131
|
f.print '■H1■' unless @plaintext
|
132
132
|
f.print ReVIEW::I18n.t('part', part.number)
|
133
133
|
f.print " #{part.name.strip}" if part.name.strip.present?
|
@@ -143,7 +143,7 @@ module ReVIEW
|
|
143
143
|
else
|
144
144
|
filename = Pathname.new(chap.path).relative_path_from(base_path).to_s
|
145
145
|
end
|
146
|
-
id = filename.sub(/\.re\Z/, '')
|
146
|
+
id = File.basename(filename).sub(/\.re\Z/, '')
|
147
147
|
|
148
148
|
textfile = "#{id}.txt"
|
149
149
|
|
data/lib/review/textutils.rb
CHANGED
@@ -26,15 +26,22 @@ module ReVIEW
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
if pre && post
|
30
|
+
blocked_lines.map! { |i| [pre] + i + [post] }
|
31
|
+
end
|
30
32
|
blocked_lines.map(&:join)
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
37
|
+
# remove elements at the back of `lines` if element is empty string
|
38
|
+
# (`lines` should be Array of String.)
|
39
|
+
#
|
35
40
|
def trim_lines(lines)
|
36
41
|
new_lines = lines.dup
|
37
|
-
|
42
|
+
while new_lines[-1] && new_lines[-1].strip.empty?
|
43
|
+
new_lines.pop
|
44
|
+
end
|
38
45
|
new_lines
|
39
46
|
end
|
40
47
|
end
|
data/lib/review/tocparser.rb
CHANGED
@@ -15,8 +15,7 @@ require 'review/textbuilder'
|
|
15
15
|
module ReVIEW
|
16
16
|
class TOCParser
|
17
17
|
def self.parse(chap)
|
18
|
-
|
19
|
-
stream = Preprocessor::Strip.new(f)
|
18
|
+
stream = StringIO.new(chap.content, 'r:BOM|utf-8')
|
20
19
|
new.parse(stream, chap).map do |root|
|
21
20
|
root.number = chap.number
|
22
21
|
root
|
@@ -43,7 +42,9 @@ module ReVIEW
|
|
43
42
|
next
|
44
43
|
when /\A(={2,})[\[\s\{]/
|
45
44
|
lev = $1.size
|
46
|
-
|
45
|
+
if lev > 5
|
46
|
+
error! filename, f.lineno, "section level too deep: #{lev}"
|
47
|
+
end
|
47
48
|
label = get_label(line)
|
48
49
|
if node_stack.empty?
|
49
50
|
# missing chapter label
|
@@ -65,7 +66,9 @@ module ReVIEW
|
|
65
66
|
roots.push new_chapter
|
66
67
|
|
67
68
|
when %r{\A//\w+(?:\[.*?\])*\{\s*\z}
|
68
|
-
|
69
|
+
if node_stack.empty?
|
70
|
+
error! filename, f.lineno, 'list found before section label'
|
71
|
+
end
|
69
72
|
node_stack.last.add_child(list = List.new)
|
70
73
|
beg = f.lineno
|
71
74
|
list.add line
|
data/lib/review/tocprinter.rb
CHANGED
data/lib/review/version.rb
CHANGED
data/lib/review/webmaker.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright (c) 2016-2018 Masayoshi Takahashi, Masanori Kado, Kenshi Muto
|
2
|
+
#
|
1
3
|
# This program is free software.
|
2
4
|
# You can distribute or modify this program under the terms of
|
3
5
|
# the GNU LGPL, Lesser General Public License version 2.1.
|
@@ -47,7 +49,7 @@ module ReVIEW
|
|
47
49
|
cmd_config = {}
|
48
50
|
opts = OptionParser.new
|
49
51
|
|
50
|
-
opts.banner = 'Usage: review-webmaker configfile'
|
52
|
+
opts.banner = 'Usage: review-webmaker [option] configfile'
|
51
53
|
opts.version = ReVIEW::VERSION
|
52
54
|
opts.on('--help', 'Prints this message and quit.') do
|
53
55
|
puts opts.help
|
@@ -70,7 +72,9 @@ module ReVIEW
|
|
70
72
|
|
71
73
|
def remove_old_files(path)
|
72
74
|
math_dir = "./#{@config['imagedir']}/_review_math"
|
73
|
-
|
75
|
+
if @config['imgmath'] && Dir.exist?(math_dir)
|
76
|
+
FileUtils.rm_rf(math_dir)
|
77
|
+
end
|
74
78
|
FileUtils.rm_rf(path)
|
75
79
|
end
|
76
80
|
|
@@ -170,7 +174,7 @@ module ReVIEW
|
|
170
174
|
else
|
171
175
|
filename = Pathname.new(chap.path).relative_path_from(base_path).to_s
|
172
176
|
end
|
173
|
-
id = filename.sub(/\.re\Z/, '')
|
177
|
+
id = File.basename(filename).sub(/\.re\Z/, '')
|
174
178
|
|
175
179
|
htmlfile = "#{id}.#{@config['htmlext']}"
|
176
180
|
|
@@ -195,7 +199,7 @@ module ReVIEW
|
|
195
199
|
|
196
200
|
def copy_resources(resdir, destdir, allow_exts = nil)
|
197
201
|
return nil if !resdir || !File.exist?(resdir)
|
198
|
-
allow_exts
|
202
|
+
allow_exts ||= @config['image_ext']
|
199
203
|
FileUtils.mkdir_p(destdir)
|
200
204
|
recursive_copy_files(resdir, destdir, allow_exts)
|
201
205
|
end
|
@@ -215,7 +219,11 @@ module ReVIEW
|
|
215
219
|
end
|
216
220
|
|
217
221
|
def copy_stylesheet(basetmpdir)
|
218
|
-
|
222
|
+
if @config['stylesheet'].size > 0
|
223
|
+
@config['stylesheet'].each do |sfile|
|
224
|
+
FileUtils.cp(sfile, basetmpdir)
|
225
|
+
end
|
226
|
+
end
|
219
227
|
end
|
220
228
|
|
221
229
|
def copy_frontmatter(basetmpdir)
|
@@ -260,8 +268,12 @@ module ReVIEW
|
|
260
268
|
@body = ''
|
261
269
|
@body << %Q(<div class="titlepage">)
|
262
270
|
@body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>)
|
263
|
-
|
264
|
-
|
271
|
+
if @config['aut']
|
272
|
+
@body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>)
|
273
|
+
end
|
274
|
+
if @config['pbl']
|
275
|
+
@body << %Q(<h3 class="tp-publisher">#{join_with_separator(@config.names_of('pbl'), ReVIEW::I18n.t('names_splitter'))}</h3>)
|
276
|
+
end
|
265
277
|
@body << '</div>'
|
266
278
|
|
267
279
|
@language = @config['language']
|
data/lib/review/webtocprinter.rb
CHANGED
@@ -25,20 +25,24 @@ module ReVIEW
|
|
25
25
|
if part.number
|
26
26
|
if part.file?
|
27
27
|
ext = part.book.config['htmlext'] || 'html'
|
28
|
-
path = part.path.sub(/\.re/, '.' + ext)
|
28
|
+
path = File.basename(part.path.sub(/\.re/, '.' + ext))
|
29
29
|
@out.puts %Q(<li><a href="#{path}">#{h(I18n.t('part_short', part.number) + ' ' + part.title)}</a>\n<ul>\n)
|
30
30
|
else
|
31
31
|
@out.puts %Q(<li>#{h(I18n.t('part_short', part.number) + ' ' + part.title)}\n<ul>\n)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
part.each_chapter
|
35
|
-
|
34
|
+
part.each_chapter do |chap|
|
35
|
+
print_chapter(chap)
|
36
|
+
end
|
37
|
+
if part.number
|
38
|
+
@out.puts "</ul>\n</li>\n"
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def print_chapter(chap)
|
39
43
|
chap_node = TOCParser.chapter_node(chap)
|
40
44
|
ext = chap.book.config['htmlext'] || 'html'
|
41
|
-
path = chap.path.sub(/\.re/, '.' + ext)
|
45
|
+
path = File.basename(chap.path.sub(/\.re/, '.' + ext))
|
42
46
|
label = if chap_node.number && chap.on_chaps?
|
43
47
|
"#{I18n.t('chapter_short', chap.number)} #{chap.title}"
|
44
48
|
else
|
data/review.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path('
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
2
|
require 'review/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = 'Re:VIEW: a easy-to-use digital publishing system'
|
13
13
|
gem.description = 'Re:VIEW is a digital publishing system for books and ebooks. It supports InDesign, EPUB and LaTeX.'
|
14
14
|
gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to? :required_rubygems_version=
|
15
|
-
gem.date = '2018-
|
15
|
+
gem.date = '2018-06-30'
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split("\n")
|
18
18
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.add_dependency('rubyzip')
|
26
26
|
gem.add_development_dependency('pygments.rb')
|
27
27
|
gem.add_development_dependency('rake')
|
28
|
-
gem.add_development_dependency('rubocop', '~> 0.
|
28
|
+
gem.add_development_dependency('rubocop', '~> 0.57.2')
|
29
|
+
gem.add_development_dependency('simplecov')
|
29
30
|
gem.add_development_dependency('test-unit')
|
30
31
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
\makeatletter
|
2
|
+
\def\review@texcompiler{<%= @texcompiler %>}
|
3
|
+
\def\review@documentclass{<%= @documentclass %>}
|
4
|
+
\def\review@booktitlename{<%= escape_latex(@config.name_of('booktitle')) %>}
|
5
|
+
<%- if @config['subtitle'] -%>
|
6
|
+
\def\review@subtitlename{<%= escape_latex(@config.name_of('subtitle')) %>}
|
7
|
+
<%- end -%>
|
8
|
+
\def\review@autnames{<%= escape_latex(@config.names_of('aut').join(I18n.t('names_splitter'))) %>}
|
9
|
+
\def\review@titlepageauthors{<%= @authors %>}
|
10
|
+
\def\review@date{<%= escape_latex(@config['date'].to_s) %>}
|
11
|
+
<%- if @config['highlight'] && @config['highlight']['latex'] -%>
|
12
|
+
\def\review@highlightlatex{<%= @config['highlight']['latex'] %>}
|
13
|
+
<%- end -%>
|
14
|
+
\def\review@language{<%= @config['language'] %>}
|
15
|
+
\def\review@intn@list{<%= escape_latex(I18n.t('list')) %>}
|
16
|
+
\def\review@intn@columnhead{<%= escape_latex(I18n.t('column_head')) %>}
|
17
|
+
\def\review@intn@image{<%= escape_latex(I18n.t('image')) %>}
|
18
|
+
\def\review@intn@table{<%= escape_latex(I18n.t('table')) %>}
|
19
|
+
\def\review@intn@columnname{<%= escape_latex(I18n.t('columnname')) %>}
|
20
|
+
\def\review@intn@memohead{<%= escape_latex(I18n.t('memo_head')) %>}
|
21
|
+
\def\review@intn@edition{<%= escape_latex(I18n.t('edition')) %>}
|
22
|
+
\def\review@intn@publishedby{<%= escape_latex(I18n.t('published_by', @config.names_of('pbl').join(I18n.t('names_splitter'))))%>}
|
23
|
+
\def\review@intn@captionprefix{<%= escape_latex(I18n.t('caption_prefix')) %>}
|
24
|
+
\def\review@toctitle{<%= escape_latex(@config['toctitle'].present? ? @config['toctitle'] : I18n.t('toctitle')) %>}
|
25
|
+
\def\review@prepartname{<%= escape_latex(@locale_latex['prepartname']) %>}
|
26
|
+
\def\review@postpartname{<%= escape_latex(@locale_latex['postpartname']) %>}
|
27
|
+
\def\review@prechaptername{<%= escape_latex(@locale_latex['prechaptername']) %>}
|
28
|
+
\def\review@postchaptername{<%= escape_latex(@locale_latex['postchaptername']) %>}
|
29
|
+
\def\review@figurename{<%= escape_latex(I18n.t('image')) %>}
|
30
|
+
\def\review@tablename{<%= escape_latex(I18n.t('table')) %>}
|
31
|
+
\def\review@appendixname{<%= escape_latex(@locale_latex['preappendixname']) %>}
|
32
|
+
<%- if @config['toc'] -%>
|
33
|
+
\def\review@toc{true}
|
34
|
+
\def\review@tocdepth{<%= @config['toclevel'] - 1 %>}
|
35
|
+
<%- end -%>
|
36
|
+
<%- if @config['makeindex'] -%>
|
37
|
+
\def\review@makeindex{true}
|
38
|
+
<%- end -%>
|
39
|
+
<%- if @config['cover'] -%>
|
40
|
+
\def\review@coverfile{<%= File.read(@config['cover']) %>}
|
41
|
+
<%- elsif @config['coverimage'] -%>
|
42
|
+
\def\review@coverimage{./<%= @config['imagedir'] %>/<%= @config['coverimage'] %>}
|
43
|
+
\def\review@coverimageoption{<%= @coverimageoption%>}
|
44
|
+
<%- end -%>
|
45
|
+
<%- if @config['titlepage'] -%>
|
46
|
+
\def\review@titlepage{true}
|
47
|
+
<%- if @config['titlefile'] -%>
|
48
|
+
\def\review@titlefile{<%= File.read(@config['titlefile']) %>}
|
49
|
+
<%- end -%>
|
50
|
+
<%- end -%>
|
51
|
+
<%- if @custom_originaltitlepage -%>
|
52
|
+
\def\revieworiginaltitlepagecont{<%= @custom_originaltitlepage %>}
|
53
|
+
<%- end -%>
|
54
|
+
<%- if @custom_creditpage -%>
|
55
|
+
\def\reviewcreditfilecont{<%= @custom_creditpage %>}
|
56
|
+
<%- end -%>
|
57
|
+
<%- if @custom_profilepage -%>
|
58
|
+
\def\reviewprofilepagecont{<%= @custom_profilepage %>}
|
59
|
+
<%- end -%>
|
60
|
+
<%- if @custom_advfilepage -%>
|
61
|
+
\def\reviewadvfilepagecont{<%= @custom_advfilepage %>}
|
62
|
+
<%- end -%>
|
63
|
+
<%- if @custom_backcoverpage -%>
|
64
|
+
\def\reviewbackcovercont{<%= @custom_backcoverpage %>}
|
65
|
+
<%- end -%>
|
66
|
+
|
67
|
+
<%- if @config['colophon'] && @config['colophon'] -%>
|
68
|
+
\def\review@colophon{true}
|
69
|
+
<%- if @custom_colophonpage -%>
|
70
|
+
\def\review@colophonfile{<%= @custom_colophonpage %>}
|
71
|
+
<%- end -%>
|
72
|
+
<%- end -%>
|
73
|
+
\def\review@pubhistories{<%= @config['pubhistory'].to_s.gsub(/\n/){"\n\n\\noindent\n"} %>}
|
74
|
+
\def\review@colophonnames{<%= @okuduke %>}
|
75
|
+
<%- if @config['rights'] -%>
|
76
|
+
\def\review@rights{<%= @config.names_of('rights').map{|s| escape_latex(s)}.join('\\' + '\\') %>}
|
77
|
+
<%- end -%>
|
78
|
+
|
79
|
+
\def\reviewprefacefiles{<%= @input_files['PREDEF'] %>}
|
80
|
+
\def\reviewchapterfiles{<%= @input_files['CHAPS'] %>}
|
81
|
+
\def\reviewappendixfiles{<%= @input_files['APPENDIX'] %>}
|
82
|
+
\def\reviewpostdeffiles{<%= @input_files['POSTDEF'] %>}
|
83
|
+
|
84
|
+
\makeatother
|