review 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.rubocop.yml +4 -1
  4. data/NEWS.ja.md +29 -0
  5. data/NEWS.md +29 -0
  6. data/bin/review-index +2 -89
  7. data/bin/review-vol +4 -78
  8. data/doc/config.yml.sample +18 -5
  9. data/doc/config.yml.sample-simple +1 -1
  10. data/doc/pdfmaker.ja.md +42 -0
  11. data/doc/pdfmaker.md +41 -0
  12. data/doc/quickstart.ja.md +8 -5
  13. data/doc/quickstart.md +7 -4
  14. data/lib/review/book/base.rb +2 -4
  15. data/lib/review/book/compilable.rb +1 -5
  16. data/lib/review/book/page_metric.rb +7 -7
  17. data/lib/review/book/part.rb +6 -3
  18. data/lib/review/book/volume.rb +3 -4
  19. data/lib/review/builder.rb +23 -10
  20. data/lib/review/compiler.rb +9 -9
  21. data/lib/review/configure.rb +6 -0
  22. data/lib/review/epubmaker.rb +1 -1
  23. data/lib/review/htmlbuilder.rb +56 -16
  24. data/lib/review/idgxmlbuilder.rb +63 -22
  25. data/lib/review/latexbuilder.rb +70 -19
  26. data/lib/review/makerhelper.rb +18 -1
  27. data/lib/review/pdfmaker.rb +8 -1
  28. data/lib/review/plaintextbuilder.rb +41 -11
  29. data/lib/review/textmaker.rb +1 -1
  30. data/lib/review/textutils.rb +2 -3
  31. data/lib/review/tocprinter.rb +231 -102
  32. data/lib/review/topbuilder.rb +47 -13
  33. data/lib/review/version.rb +1 -1
  34. data/lib/review/volumeprinter.rb +99 -0
  35. data/lib/review/webmaker.rb +1 -1
  36. data/lib/review/webtocprinter.rb +38 -35
  37. data/review.gemspec +1 -1
  38. data/samples/sample-book/src/config.yml +1 -1
  39. data/templates/web/html/layout-html5.html.erb +2 -2
  40. data/test/test_book.rb +1 -1
  41. data/test/test_book_part.rb +3 -3
  42. data/test/test_helper.rb +4 -1
  43. data/test/test_htmlbuilder.rb +179 -0
  44. data/test/test_idgxmlbuilder.rb +143 -0
  45. data/test/test_latexbuilder.rb +223 -0
  46. data/test/test_pdfmaker.rb +17 -0
  47. data/test/test_plaintextbuilder.rb +99 -0
  48. data/test/test_topbuilder.rb +116 -2
  49. data/test/test_webtocprinter.rb +66 -34
  50. metadata +3 -5
  51. data/lib/review/tocparser.rb +0 -275
  52. data/test/test_tocparser.rb +0 -25
@@ -149,6 +149,23 @@ class PDFMakerTest < Test::Unit::TestCase
149
149
  end
150
150
  end
151
151
 
152
+ def test_template_content_with_localconfig
153
+ @config['mycustom'] = { 'value' => '#_TEST_' }
154
+ Dir.mktmpdir do |dir|
155
+ Dir.chdir(dir) do
156
+ Dir.mkdir('layouts')
157
+ File.write(File.join('layouts', 'config-local.tex.erb'), %q(\def\customvalue{<%= escape(@config['mycustom']['value']) %>}) + "\n")
158
+ @maker.basedir = Dir.pwd
159
+ @maker.erb_config
160
+ tmpl = @maker.template_content
161
+ expect = File.read(File.join(assets_dir, 'test_template.tex'))
162
+ expect.gsub!(/\\def\\review@reviewversion{[^\}]+}/, "\\def\\review@reviewversion{#{ReVIEW::VERSION}}")
163
+ expect.sub!("\\makeatother\n", '\&' + "%% BEGIN: config-local.tex.erb\n\\def\\customvalue{\\#\\textunderscore{}TEST\\textunderscore{}}\n%% END: config-local.tex.erb\n")
164
+ assert_equal(expect, tmpl)
165
+ end
166
+ end
167
+ end
168
+
152
169
  def test_gettemplate_with_backmatter
153
170
  @config.merge!(
154
171
  'backcover' => 'backcover.tex',
@@ -249,6 +249,17 @@ EOS
249
249
  foo
250
250
  bar
251
251
 
252
+ EOS
253
+ assert_equal expected, actual
254
+
255
+ @config['caption_position']['list'] = 'bottom'
256
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
257
+ expected = <<-EOS
258
+ foo
259
+ bar
260
+
261
+ リスト1.1 this is test<&>_
262
+
252
263
  EOS
253
264
  assert_equal expected, actual
254
265
  end
@@ -264,6 +275,17 @@ EOS
264
275
  1: foo
265
276
  2: bar
266
277
 
278
+ EOS
279
+ assert_equal expected, actual
280
+
281
+ @config['caption_position']['list'] = 'bottom'
282
+ actual = compile_block("//listnum[test][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
283
+ expected = <<-EOS
284
+ 1: foo
285
+ 2: bar
286
+
287
+ リスト1.1 this is test<&>_
288
+
267
289
  EOS
268
290
  assert_equal expected, actual
269
291
  end
@@ -277,6 +299,18 @@ bar
277
299
 
278
300
  buz
279
301
 
302
+ EOS
303
+ assert_equal expected, actual
304
+
305
+ @config['caption_position']['list'] = 'bottom'
306
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
307
+ expected = <<-EOS
308
+ foo
309
+ bar
310
+
311
+ buz
312
+ foo/bar/test.rb
313
+
280
314
  EOS
281
315
  assert_equal expected, actual
282
316
  end
@@ -308,6 +342,16 @@ FOO
308
342
  foo
309
343
  bar
310
344
 
345
+ EOS
346
+ assert_equal expected, actual
347
+
348
+ @config['caption_position']['list'] = 'bottom'
349
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
350
+ expected = <<-EOS
351
+ foo
352
+ bar
353
+ FOO
354
+
311
355
  EOS
312
356
  assert_equal expected, actual
313
357
  end
@@ -327,6 +371,16 @@ cap1
327
371
  lineA
328
372
  lineB
329
373
 
374
+ EOS
375
+ assert_equal expected, actual
376
+
377
+ @config['caption_position']['list'] = 'bottom'
378
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
379
+ expected = <<-EOS
380
+ lineA
381
+ lineB
382
+ cap1
383
+
330
384
  EOS
331
385
  assert_equal expected, actual
332
386
  end
@@ -348,6 +402,16 @@ cap1
348
402
  lineA
349
403
  lineB
350
404
 
405
+ EOS
406
+ assert_equal expected, actual
407
+
408
+ @config['caption_position']['list'] = 'bottom'
409
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
410
+ expected = <<-EOS
411
+ lineA
412
+ lineB
413
+ cap1
414
+
351
415
  EOS
352
416
  assert_equal expected, actual
353
417
  end
@@ -359,6 +423,16 @@ this is test<&>_
359
423
  1: foo
360
424
  2: bar
361
425
 
426
+ EOS
427
+ assert_equal expected, actual
428
+
429
+ @config['caption_position']['list'] = 'bottom'
430
+ actual = compile_block("//emlistnum[this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
431
+ expected = <<-EOS
432
+ 1: foo
433
+ 2: bar
434
+ this is test<&>_
435
+
362
436
  EOS
363
437
  assert_equal expected, actual
364
438
  end
@@ -387,6 +461,16 @@ EOS
387
461
  aaa\tbbb
388
462
  ccc\tddd<>&
389
463
 
464
+ EOS
465
+ assert_equal expected, actual
466
+
467
+ @config['caption_position']['table'] = 'bottom'
468
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
469
+ expected = <<-EOS
470
+ aaa\tbbb
471
+ ccc\tddd<>&
472
+
473
+ 表1.1 FOO
390
474
  EOS
391
475
  assert_equal expected, actual
392
476
  end
@@ -521,6 +605,10 @@ EOS
521
605
 
522
606
  actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
523
607
  assert_equal %Q(図1.1 sample photo\n\n), actual
608
+
609
+ @config['caption_position']['image'] = 'top'
610
+ actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
611
+ assert_equal %Q(図1.1 sample photo\n\n), actual
524
612
  end
525
613
 
526
614
  def test_image_with_metric
@@ -649,6 +737,17 @@ EOS
649
737
  式1.1 The Equivalence of Mass and Energy
650
738
  e=mc^2
651
739
 
740
+ EOS
741
+ actual = compile_block(src)
742
+ assert_equal expected, actual
743
+
744
+ @config['caption_position']['equation'] = 'bottom'
745
+ expected = <<-EOS
746
+ 式1.1
747
+
748
+ e=mc^2
749
+ 式1.1 The Equivalence of Mass and Energy
750
+
652
751
  EOS
653
752
  actual = compile_block(src)
654
753
  assert_equal expected, actual
@@ -295,6 +295,19 @@ EOS
295
295
  2: bar
296
296
  ◆→終了:リスト←◆
297
297
 
298
+ EOS
299
+ assert_equal expected, actual
300
+
301
+ @config['caption_position']['list'] = 'bottom'
302
+ actual = compile_block("//listnum[test][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
303
+ expected = <<-EOS
304
+ ◆→開始:リスト←◆
305
+ 1: foo
306
+ 2: bar
307
+
308
+ リスト1.1 this is ★test☆<&>_
309
+ ◆→終了:リスト←◆
310
+
298
311
  EOS
299
312
  assert_equal expected, actual
300
313
  end
@@ -310,6 +323,20 @@ bar
310
323
  buz
311
324
  ◆→終了:ソースコードリスト←◆
312
325
 
326
+ EOS
327
+ assert_equal expected, actual
328
+
329
+ @config['caption_position']['list'] = 'bottom'
330
+ actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
331
+ expected = <<-EOS
332
+ ◆→開始:ソースコードリスト←◆
333
+ foo
334
+ bar
335
+
336
+ buz
337
+ ■foo/bar/test.rb
338
+ ◆→終了:ソースコードリスト←◆
339
+
313
340
  EOS
314
341
  assert_equal expected, actual
315
342
  end
@@ -347,6 +374,18 @@ foo
347
374
  bar
348
375
  ◆→終了:書式←◆
349
376
 
377
+ EOS
378
+ assert_equal expected, actual
379
+
380
+ @config['caption_position']['list'] = 'bottom'
381
+ actual = compile_block("//box[FOO]{\nfoo\nbar\n//}\n")
382
+ expected = <<-EOS
383
+ ◆→開始:書式←◆
384
+ foo
385
+ bar
386
+ ■FOO
387
+ ◆→終了:書式←◆
388
+
350
389
  EOS
351
390
  assert_equal expected, actual
352
391
  end
@@ -370,6 +409,18 @@ lineA
370
409
  lineB
371
410
  ◆→終了:コマンド←◆
372
411
 
412
+ EOS
413
+ assert_equal expected, actual
414
+
415
+ @config['caption_position']['list'] = 'bottom'
416
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
417
+ expected = <<-EOS
418
+ ◆→開始:コマンド←◆
419
+ lineA
420
+ lineB
421
+ ■cap1
422
+ ◆→終了:コマンド←◆
423
+
373
424
  EOS
374
425
  assert_equal expected, actual
375
426
  end
@@ -395,6 +446,18 @@ lineA
395
446
  lineB
396
447
  ◆→終了:インラインリスト←◆
397
448
 
449
+ EOS
450
+ assert_equal expected, actual
451
+
452
+ @config['caption_position']['list'] = 'bottom'
453
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
454
+ expected = <<-EOS
455
+ ◆→開始:インラインリスト←◆
456
+ lineA
457
+ lineB
458
+ ■cap1
459
+ ◆→終了:インラインリスト←◆
460
+
398
461
  EOS
399
462
  assert_equal expected, actual
400
463
  end
@@ -408,6 +471,18 @@ EOS
408
471
  2: bar
409
472
  ◆→終了:インラインリスト←◆
410
473
 
474
+ EOS
475
+ assert_equal expected, actual
476
+
477
+ @config['caption_position']['list'] = 'bottom'
478
+ actual = compile_block("//emlistnum[this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
479
+ expected = <<-EOS
480
+ ◆→開始:インラインリスト←◆
481
+ 1: foo
482
+ 2: bar
483
+ ■this is ★test☆<&>_
484
+ ◆→終了:インラインリスト←◆
485
+
411
486
  EOS
412
487
  assert_equal expected, actual
413
488
  end
@@ -440,6 +515,19 @@ EOS
440
515
  ccc\tddd<>&
441
516
  ◆→終了:表←◆
442
517
 
518
+ EOS
519
+ assert_equal expected, actual
520
+
521
+ @config['caption_position']['table'] = 'bottom'
522
+ actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
523
+ expected = <<-EOS
524
+ ◆→開始:表←◆
525
+ ★aaa☆\t★bbb☆
526
+ ccc\tddd<>&
527
+
528
+ 表1.1 FOO
529
+ ◆→終了:表←◆
530
+
443
531
  EOS
444
532
  assert_equal expected, actual
445
533
  end
@@ -657,6 +745,18 @@ EOS
657
745
  actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
658
746
  expected = <<-EOS
659
747
  ◆→開始:図←◆
748
+ ◆→./images/chap1-sampleimg.png←◆
749
+
750
+ 図1.1 sample photo
751
+ ◆→終了:図←◆
752
+
753
+ EOS
754
+ assert_equal expected, actual
755
+
756
+ @config['caption_position']['image'] = 'top'
757
+ actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
758
+ expected = <<-EOS
759
+ ◆→開始:図←◆
660
760
  図1.1 sample photo
661
761
 
662
762
  ◆→./images/chap1-sampleimg.png←◆
@@ -676,9 +776,9 @@ EOS
676
776
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\nfoo\n//}\n")
677
777
  expected = <<-EOS
678
778
  ◆→開始:図←◆
679
- 図1.1 sample photo
680
-
681
779
  ◆→./images/chap1-sampleimg.png scale=1.2←◆
780
+
781
+ 図1.1 sample photo
682
782
  ◆→終了:図←◆
683
783
 
684
784
  EOS
@@ -829,6 +929,20 @@ EOS
829
929
  e=mc^2
830
930
  ◆→終了:TeX式←◆
831
931
 
932
+ EOS
933
+ actual = compile_block(src)
934
+ assert_equal expected, actual
935
+
936
+ @config['caption_position']['equation'] = 'bottom'
937
+
938
+ expected = <<-EOS
939
+ 式1.1
940
+
941
+ ◆→開始:TeX式←◆
942
+ e=mc^2
943
+ 式1.1 The Equivalence of Mass ▲and☆ Energy
944
+ ◆→終了:TeX式←◆
945
+
832
946
  EOS
833
947
  actual = compile_block(src)
834
948
  assert_equal expected, actual
@@ -35,8 +35,8 @@ EOB
35
35
  expect = <<-EOB
36
36
  <ul class="book-toc">
37
37
  <li><a href="index.html">TOP</a></li>
38
- <li><a href="ch1.html">1 ch. 1</a></li>
39
- <li><a href="ch2.html">2 ch. 2</a></li>
38
+ <li><a href="ch1.html">第1章 ch. 1</a></li>
39
+ <li><a href="ch2.html">第2章 ch. 2</a></li>
40
40
  </ul>
41
41
  EOB
42
42
  assert_equal expect, str
@@ -58,16 +58,12 @@ EOB
58
58
  expect = <<-EOB
59
59
  <ul class="book-toc">
60
60
  <li><a href="index.html">TOP</a></li>
61
- <li>I part1
62
- <ul>
63
- <li><a href="ch1.html">1 ch. 1</a></li>
64
- </ul>
65
- </li>
66
- <li>II part2
67
- <ul>
68
- <li><a href="ch2.html">2 ch. 2</a></li>
69
- </ul>
70
- </li>
61
+ <li>第I部 part1
62
+ <ul><li><a href="ch1.html">第1章 ch. 1</a></li>
63
+ </ul></li>
64
+ <li>第II部 part2
65
+ <ul><li><a href="ch2.html">第2章 ch. 2</a></li>
66
+ </ul></li>
71
67
  </ul>
72
68
  EOB
73
69
  assert_equal expect, str
@@ -91,16 +87,12 @@ EOB
91
87
  expect = <<-EOB
92
88
  <ul class="book-toc">
93
89
  <li><a href="index.html">TOP</a></li>
94
- <li><a href="p1.html">I This is PART1</a>
95
- <ul>
96
- <li><a href="ch1.html">1 ch. 1</a></li>
97
- </ul>
98
- </li>
99
- <li><a href="p2.html">II This is PART2</a>
100
- <ul>
101
- <li><a href="ch2.html">2 ch. 2</a></li>
102
- </ul>
103
- </li>
90
+ <li><a href="p1.html">第I部 This is PART1</a>
91
+ <ul><li><a href="ch1.html">第1章 ch. 1</a></li>
92
+ </ul></li>
93
+ <li><a href="p2.html">第II部 This is PART2</a>
94
+ <ul><li><a href="ch2.html">第2章 ch. 2</a></li>
95
+ </ul></li>
104
96
  </ul>
105
97
  EOB
106
98
  assert_equal expect, str
@@ -141,21 +133,61 @@ EOB
141
133
  <li><a href="index.html">TOP</a></li>
142
134
  <li><a href="pre1.html">PRE1</a></li>
143
135
  <li><a href="pre2.html">PRE2</a></li>
144
- <li><a href="part1.html">I PART1</a>
145
- <ul>
146
- <li><a href="ch1.html">1 ch. 1</a></li>
147
- </ul>
148
- </li>
149
- <li><a href="part2.html">II PART2</a>
150
- <ul>
151
- <li><a href="ch2.html">2 ch. 2</a></li>
152
- </ul>
153
- </li>
154
- <li><a href="app1.html">APP1</a></li>
155
- <li><a href="app2.html">APP2</a></li>
136
+ <li><a href="part1.html">第I部 PART1</a>
137
+ <ul><li><a href="ch1.html">第1章 ch. 1</a></li>
138
+ </ul></li>
139
+ <li><a href="part2.html">第II部 PART2</a>
140
+ <ul><li><a href="ch2.html">第2章 ch. 2</a></li>
141
+ </ul></li>
142
+ <li><a href="app1.html">付録A APP1</a></li>
143
+ <li><a href="app2.html">付録B APP2</a></li>
156
144
  <li><a href="post1.html">POST1</a></li>
157
145
  <li><a href="post2.html">POST2</a></li>
158
146
  </ul>
147
+ EOB
148
+ assert_equal expect, str
149
+ end
150
+ end
151
+
152
+ def test_webtocprinter_nochapter
153
+ catalog_yml = <<-EOB
154
+ CHAPS:
155
+ EOB
156
+ mktmpbookdir 'catalog.yml' => catalog_yml do |_dir, book, _files|
157
+ str = WEBTOCPrinter.book_to_string(book)
158
+ expect = <<-EOB
159
+ <ul class="book-toc">
160
+ <li><a href="index.html">TOP</a></li>
161
+ </ul>
162
+ EOB
163
+ assert_equal expect, str
164
+ end
165
+ end
166
+
167
+ def test_webtocprinter_noheadline
168
+ catalog_yml = <<-EOB
169
+ CHAPS:
170
+ - ch1.re
171
+ - ch2.re
172
+ - ch3.re
173
+ - ch4.re
174
+ EOB
175
+ mktmpbookdir 'catalog.yml' => catalog_yml,
176
+ 'ch1.re' => "A\n",
177
+ 'ch2.re' => "B\n\n= C\n== D\n",
178
+ 'ch3.re' => "//emlist{\nLIST\n//}\n",
179
+ 'ch4.re' => "==[column] E\n\n= F" do |_dir, book, _files|
180
+ str = WEBTOCPrinter.book_to_string(book)
181
+ expect = <<-EOB
182
+ <ul class="book-toc">
183
+ <li><a href="index.html">TOP</a></li>
184
+ <li><a href="ch1.html">-</a></li>
185
+ <li><a href="ch2.html">-</a></li>
186
+ <li><a href="ch2.html">第2章 C</a></li>
187
+ <li><a href="ch3.html">-</a></li>
188
+ <li><a href="ch4.html">-</a></li>
189
+ <li><a href="ch4.html">第4章 F</a></li>
190
+ </ul>
159
191
  EOB
160
192
  assert_equal expect, str
161
193
  end