review 5.1.1 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +6 -2
  3. data/.github/workflows/ruby-win.yml +6 -2
  4. data/.github/workflows/ruby.yml +6 -2
  5. data/.rubocop.yml +5 -319
  6. data/NEWS.ja.md +149 -0
  7. data/NEWS.md +149 -1
  8. data/README.md +9 -8
  9. data/bin/review +1 -1
  10. data/bin/review-catalog-converter +15 -15
  11. data/bin/review-check +7 -7
  12. data/bin/review-compile +14 -23
  13. data/bin/review-index +1 -1
  14. data/bin/review-preproc +29 -35
  15. data/bin/review-validate +2 -2
  16. data/doc/config.yml.sample +9 -1
  17. data/doc/config.yml.sample-simple +1 -1
  18. data/doc/format.ja.md +29 -3
  19. data/doc/format.md +32 -3
  20. data/doc/writing_vertical.ja.md +6 -0
  21. data/lib/review/book/base.rb +3 -3
  22. data/lib/review/book/book_unit.rb +13 -3
  23. data/lib/review/book/chapter.rb +1 -1
  24. data/lib/review/book/index.rb +7 -4
  25. data/lib/review/book/part.rb +12 -13
  26. data/lib/review/book/volume.rb +1 -1
  27. data/lib/review/builder.rb +92 -65
  28. data/lib/review/catalog.rb +6 -5
  29. data/lib/review/compiler.rb +76 -57
  30. data/lib/review/configure.rb +5 -2
  31. data/lib/review/epub2html.rb +12 -12
  32. data/lib/review/epubmaker/content.rb +1 -1
  33. data/lib/review/epubmaker/epubcommon.rb +47 -45
  34. data/lib/review/epubmaker/epubv2.rb +2 -1
  35. data/lib/review/epubmaker/epubv3.rb +5 -4
  36. data/lib/review/epubmaker/producer.rb +6 -7
  37. data/lib/review/epubmaker/reviewheaderlistener.rb +1 -1
  38. data/lib/review/epubmaker.rb +56 -67
  39. data/lib/review/exception.rb +7 -0
  40. data/lib/review/extentions/string.rb +1 -1
  41. data/lib/review/htmlbuilder.rb +90 -34
  42. data/lib/review/htmlutils.rb +17 -17
  43. data/lib/review/i18n.rb +3 -3
  44. data/lib/review/i18n.yml +6 -0
  45. data/lib/review/idgxmlbuilder.rb +61 -39
  46. data/lib/review/idgxmlmaker.rb +27 -26
  47. data/lib/review/img_math.rb +12 -18
  48. data/lib/review/index_builder.rb +94 -53
  49. data/lib/review/init.rb +4 -4
  50. data/lib/review/latexbuilder.rb +84 -76
  51. data/lib/review/lineinput.rb +3 -3
  52. data/lib/review/location.rb +1 -1
  53. data/lib/review/loggable.rb +27 -0
  54. data/lib/review/logger.rb +69 -21
  55. data/lib/review/makerhelper.rb +8 -4
  56. data/lib/review/markdownbuilder.rb +21 -12
  57. data/lib/review/pdfmaker.rb +63 -42
  58. data/lib/review/plaintextbuilder.rb +16 -15
  59. data/lib/review/preprocessor/directive.rb +35 -0
  60. data/lib/review/preprocessor/line.rb +34 -0
  61. data/lib/review/preprocessor/repository.rb +177 -0
  62. data/lib/review/preprocessor.rb +94 -296
  63. data/lib/review/rstbuilder.rb +12 -3
  64. data/lib/review/template.rb +5 -1
  65. data/lib/review/textmaker.rb +32 -31
  66. data/lib/review/textutils.rb +5 -6
  67. data/lib/review/tocprinter.rb +12 -7
  68. data/lib/review/topbuilder.rb +96 -19
  69. data/lib/review/update.rb +16 -8
  70. data/lib/review/version.rb +1 -1
  71. data/lib/review/volumeprinter.rb +9 -9
  72. data/lib/review/webmaker.rb +45 -46
  73. data/lib/review/webtocprinter.rb +10 -10
  74. data/lib/review/yamlloader.rb +35 -2
  75. data/review.gemspec +2 -1
  76. data/samples/sample-book/src/config.yml +0 -1
  77. data/samples/sample-book/src/lib/tasks/review.rake +3 -1
  78. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  79. data/samples/syntax-book/ch02.re +9 -0
  80. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  81. data/templates/html/_titlepage.html.erb +9 -17
  82. data/templates/latex/config.erb +3 -0
  83. data/templates/latex/review-jlreq/review-base.sty +4 -5
  84. data/templates/latex/review-jlreq/review-jlreq.cls +39 -5
  85. data/templates/latex/review-jsbook/review-base.sty +9 -3
  86. data/templates/latex/review-jsbook/review-jsbook.cls +32 -5
  87. data/templates/opf/opf_manifest_epubv2.opf.erb +1 -1
  88. data/templates/opf/opf_manifest_epubv3.opf.erb +1 -1
  89. data/test/assets/syntax_book_index_detail.txt +10 -8
  90. data/test/assets/test_template.tex +4 -1
  91. data/test/assets/test_template_backmatter.tex +4 -1
  92. data/test/book_test_helper.rb +10 -10
  93. data/test/test_book_chapter.rb +25 -2
  94. data/test/test_builder.rb +10 -8
  95. data/test/test_epub3maker.rb +3 -3
  96. data/test/test_epubmaker.rb +27 -37
  97. data/test/test_epubmaker_cmd.rb +14 -3
  98. data/test/test_htmlbuilder.rb +111 -31
  99. data/test/test_idgxmlbuilder.rb +41 -33
  100. data/test/test_idgxmlmaker_cmd.rb +1 -1
  101. data/test/test_img_math.rb +11 -2
  102. data/test/test_index.rb +30 -4
  103. data/test/test_latexbuilder.rb +46 -25
  104. data/test/test_latexbuilder_v2.rb +18 -10
  105. data/test/test_markdownbuilder.rb +13 -0
  106. data/test/test_pdfmaker.rb +19 -0
  107. data/test/test_pdfmaker_cmd.rb +10 -10
  108. data/test/test_plaintextbuilder.rb +46 -22
  109. data/test/test_preprocessor.rb +188 -1
  110. data/test/test_rstbuilder.rb +13 -0
  111. data/test/test_textmaker_cmd.rb +1 -1
  112. data/test/test_topbuilder.rb +195 -29
  113. data/test/test_yamlloader.rb +28 -42
  114. metadata +11 -6
@@ -14,6 +14,8 @@ class IDGXMLBuidlerTest < Test::Unit::TestCase
14
14
  @config['tableopt'] = '10'
15
15
  @book = Book::Base.new
16
16
  @book.config = @config
17
+ @log_io = StringIO.new
18
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
17
19
  @compiler = ReVIEW::Compiler.new(@builder)
18
20
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
19
21
  location = Location.new(nil, nil)
@@ -169,10 +171,10 @@ EOS
169
171
 
170
172
  def test_empty_table
171
173
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
172
- assert_equal ':2: error: no rows in the table', e.message
174
+ assert_equal 'no rows in the table', e.message
173
175
 
174
176
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
175
- assert_equal ':3: error: no rows in the table', e.message
177
+ assert_equal 'no rows in the table', e.message
176
178
  end
177
179
 
178
180
  def test_emtable
@@ -346,15 +348,15 @@ EOS
346
348
  //}
347
349
  EOS
348
350
 
349
- if type == 'notice' # exception pattern
350
- expected = <<-EOS.chomp
351
+ expected = if type == 'notice' # exception pattern
352
+ <<-EOS.chomp
351
353
  <#{type}-t><title aid:pstyle='#{type}-title'>#{type}1</title></#{type}-t><#{type}-t><title aid:pstyle='#{type}-title'>#{type}2</title></#{type}-t>
352
354
  EOS
353
- else
354
- expected = <<-EOS.chomp
355
+ else
356
+ <<-EOS.chomp
355
357
  <#{type}><title aid:pstyle='#{type}-title'>#{type}1</title></#{type}><#{type}><title aid:pstyle='#{type}-title'>#{type}2</title></#{type}>
356
358
  EOS
357
- end
359
+ end
358
360
  assert_equal expected, compile_block(src)
359
361
 
360
362
  src = <<-EOS
@@ -410,17 +412,17 @@ LIST
410
412
  //}
411
413
  EOS
412
414
 
413
- if type == 'notice' # exception pattern
414
- expected = <<-EOS.chomp
415
+ expected = if type == 'notice' # exception pattern
416
+ <<-EOS.chomp
415
417
  <#{type}><ul><li aid:pstyle="ul-item">A</li></ul><ol><li aid:pstyle="ol-item" olnum="1" num="1">B</li></ol></#{type}><#{type}-t><title aid:pstyle='#{type}-title'>OMITEND1</title><list type='emlist'><pre>LIST
416
418
  </pre></list></#{type}-t><#{type}-t><title aid:pstyle='#{type}-title'>OMITEND2</title></#{type}-t>
417
419
  EOS
418
- else
419
- expected = <<-EOS.chomp
420
+ else
421
+ <<-EOS.chomp
420
422
  <#{type}><ul><li aid:pstyle="ul-item">A</li></ul><ol><li aid:pstyle="ol-item" olnum="1" num="1">B</li></ol></#{type}><#{type}><title aid:pstyle='#{type}-title'>OMITEND1</title><list type='emlist'><pre>LIST
421
423
  </pre></list></#{type}><#{type}><title aid:pstyle='#{type}-title'>OMITEND2</title></#{type}>
422
424
  EOS
423
- end
425
+ end
424
426
  assert_equal expected, compile_block(src)
425
427
  end
426
428
  end
@@ -436,8 +438,8 @@ EOS
436
438
 
437
439
  //}
438
440
  EOS
439
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
440
- assert_match(/minicolumn cannot be nested:/, e.message)
441
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
442
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
441
443
  end
442
444
  end
443
445
 
@@ -453,8 +455,8 @@ EOS
453
455
 
454
456
  //}
455
457
  EOS
456
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
457
- assert_match(/minicolumn cannot be nested:/, e.message)
458
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
459
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
458
460
  end
459
461
  end
460
462
 
@@ -469,8 +471,8 @@ EOS
469
471
 
470
472
  //}
471
473
  EOS
472
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
473
- assert_match(/minicolumn cannot be nested:/, e.message)
474
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
475
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
474
476
  end
475
477
  end
476
478
 
@@ -1095,8 +1097,8 @@ EOS
1095
1097
  * AA
1096
1098
  EOS
1097
1099
 
1098
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1099
- assert_equal ':1: error: too many *.', e.message
1100
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1101
+ assert_match(/too many \*\./, @log_io.string)
1100
1102
  end
1101
1103
 
1102
1104
  def test_ul_nest4
@@ -1131,19 +1133,25 @@ EOS
1131
1133
  end
1132
1134
 
1133
1135
  def test_inline_unknown
1134
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1135
- assert_equal ':1: error: unknown image: n', e.message
1136
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1137
- assert_equal ':1: error: unknown footnote: n', e.message
1138
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1139
- assert_equal ':1: error: unknown headline: n', e.message
1136
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1137
+ assert_match(/unknown image: n/, @log_io.string)
1138
+
1139
+ @log_io.string = ''
1140
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1141
+ assert_match(/unknown footnote: n/, @log_io.string)
1142
+
1143
+ @log_io.string = ''
1144
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1145
+ assert_match(/unknown headline: n/, @log_io.string)
1140
1146
  %w[list table column].each do |name|
1141
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1142
- assert_equal ":1: error: unknown #{name}: n", e.message
1147
+ @log_io.string = ''
1148
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1149
+ assert_match(/unknown #{name}: n/, @log_io.string)
1143
1150
  end
1144
1151
  %w[chap chapref title].each do |name|
1145
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1146
- assert_equal ':1: error: key not found: "n"', e.message
1152
+ @log_io.string = ''
1153
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1154
+ assert_match(/key not found: "n"/, @log_io.string)
1147
1155
  end
1148
1156
  end
1149
1157
 
@@ -1283,7 +1291,7 @@ EOS
1283
1291
  //beginchild
1284
1292
  EOS
1285
1293
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1286
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
1294
+ assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
1287
1295
  end
1288
1296
 
1289
1297
  def test_nest_error_close2
@@ -1301,7 +1309,7 @@ EOS
1301
1309
  //beginchild
1302
1310
  EOS
1303
1311
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1304
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
1312
+ assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
1305
1313
  end
1306
1314
 
1307
1315
  def test_nest_error_close3
@@ -1321,7 +1329,7 @@ EOS
1321
1329
  //endchild
1322
1330
  EOS
1323
1331
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1324
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
1332
+ assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
1325
1333
  end
1326
1334
 
1327
1335
  def test_nest_ul
@@ -21,7 +21,7 @@ class IDGXMLMakerCmdTest < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  def common_buildidgxml(bookdir, configfile, targetfile, option)
24
- if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
24
+ unless /mswin|mingw|cygwin/.match?(RUBY_PLATFORM)
25
25
  config = prepare_samplebook(@tmpdir1, bookdir, nil, configfile)
26
26
  builddir = File.join(@tmpdir1, config['bookname'] + '-idgxml')
27
27
  assert !File.exist?(builddir)
@@ -30,7 +30,7 @@ class ImgMathTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_defer_math_image
33
- unless support_latex_in_tests?
33
+ unless support_latex_in_tests? && support_pdftocairo_in_tests?
34
34
  $stderr.puts 'skip test_defer_math_image'
35
35
  return true
36
36
  end
@@ -104,7 +104,16 @@ class ImgMathTest < Test::Unit::TestCase
104
104
  begin
105
105
  `uplatex -v`
106
106
  true
107
- rescue
107
+ rescue StandardError
108
+ false
109
+ end
110
+ end
111
+
112
+ def support_pdftocairo_in_tests?
113
+ begin
114
+ `pdftocairo -v`
115
+ true
116
+ rescue StandardError
108
117
  false
109
118
  end
110
119
  end
data/test/test_index.rb CHANGED
@@ -12,6 +12,8 @@ class IndexTest < Test::Unit::TestCase
12
12
  @builder = TOPBuilder.new
13
13
  @config = ReVIEW::Configure.create(config: { 'secnolevel' => 2, 'language' => 'ja' })
14
14
  @book = Book::Base.new(config: @config)
15
+ @log_io = StringIO.new
16
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
15
17
  @compiler = ReVIEW::Compiler.new(@builder)
16
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
17
19
  location = Location.new(nil, nil)
@@ -21,16 +23,19 @@ class IndexTest < Test::Unit::TestCase
21
23
  end
22
24
 
23
25
  def test_footnote_index
24
- compile_block("//footnote[foo][bar]\n")
26
+ compile_block("@<fn>{foo}\n//footnote[foo][bar]\n")
25
27
  fn = @chapter.footnote_index
26
28
  items = fn.to_a
27
29
  item = items[0]
28
30
  assert_equal 'foo', item.id
29
31
  assert_equal 'bar', item.content
32
+
33
+ compile_block("//footnote[foo][bar]\n")
34
+ assert_match(/ID foo is not referred/, @log_io.string)
30
35
  end
31
36
 
32
37
  def test_footnote_index_with_escape
33
- compile_block('//footnote[foo][bar[\]buz]' + "\n")
38
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar[\]buz]' + "\n")
34
39
  fn = @chapter.footnote_index
35
40
  items = fn.to_a
36
41
  item = items[0]
@@ -39,7 +44,7 @@ class IndexTest < Test::Unit::TestCase
39
44
  end
40
45
 
41
46
  def test_footnote_index_with_escape2
42
- compile_block('//footnote[foo][bar\\a\\$buz]' + "\n")
47
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar\\a\\$buz]' + "\n")
43
48
  fn = @chapter.footnote_index
44
49
  items = fn.to_a
45
50
  item = items[0]
@@ -48,7 +53,7 @@ class IndexTest < Test::Unit::TestCase
48
53
  end
49
54
 
50
55
  def test_footnote_index_key?
51
- compile_block('//footnote[foo][bar]' + "\n")
56
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar]' + "\n")
52
57
  fn = @chapter.footnote_index
53
58
  assert_equal true, fn.key?('foo')
54
59
 
@@ -58,6 +63,27 @@ class IndexTest < Test::Unit::TestCase
58
63
  # rubocop:enable Style/PreferredHashMethods
59
64
  end
60
65
 
66
+ def test_endnote_index
67
+ compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
68
+ endnote = @chapter.endnote_index
69
+ items = endnote.to_a
70
+ item = items[0]
71
+ assert_equal 'foo', item.id
72
+ assert_equal 'bar', item.content
73
+ assert_equal true, endnote.key?('foo')
74
+ # rubocop:disable Style/PreferredHashMethods
75
+ assert_equal true, endnote.has_key?('foo')
76
+ # rubocop:enable Style/PreferredHashMethods
77
+
78
+ e = assert_raises(ReVIEW::ApplicationError) do
79
+ compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n")
80
+ end
81
+ assert_equal ':3: //endnote is found but //printendnotes is not found.', e.message
82
+
83
+ compile_block("//endnote[foo][bar]\n//printendnotes\n")
84
+ assert_match(/ID foo is not referred/, @log_io.string)
85
+ end
86
+
61
87
  def test_headline_index
62
88
  src = <<-EOB
63
89
  = chap1
@@ -20,6 +20,8 @@ class LATEXBuidlerTest < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -255,6 +257,20 @@ EOS
255
257
  assert_equal 'test \\reviewttb{inline test} test2', actual
256
258
  end
257
259
 
260
+ def test_endnote
261
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
262
+ assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
263
+
264
+ actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
265
+ expected = <<-'EOS'
266
+
267
+ \endnote{bar}
268
+
269
+ \theendnotes
270
+ EOS
271
+ assert_equal expected, actual
272
+ end
273
+
258
274
  def test_inline_hd_chap
259
275
  def @chapter.headline_index
260
276
  item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
@@ -1372,7 +1388,7 @@ EOS
1372
1388
  actual = compile_block("//indepimage[sample_img_nofile_][sample photo]\n")
1373
1389
  expected = <<-EOS
1374
1390
  \\begin{reviewdummyimage}
1375
- --[[path = sample\\textunderscore{}img\\textunderscore{}nofile\\textunderscore{} (not exist)]]--
1391
+ {-}{-}[[path = sample\\reviewbackslash{}textunderscore\\{\\}img\\reviewbackslash{}textunderscore\\{\\}nofile\\reviewbackslash{}textunderscore\\{\\} (not exist)]]{-}{-}
1376
1392
  \\reviewindepimagecaption{図: sample photo}
1377
1393
  \\end{reviewdummyimage}
1378
1394
  EOS
@@ -1433,10 +1449,10 @@ EOS
1433
1449
 
1434
1450
  def test_empty_table
1435
1451
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
1436
- assert_equal ':2: error: no rows in the table', e.message
1452
+ assert_equal 'no rows in the table', e.message
1437
1453
 
1438
1454
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
1439
- assert_equal ':3: error: no rows in the table', e.message
1455
+ assert_equal 'no rows in the table', e.message
1440
1456
  end
1441
1457
 
1442
1458
  def test_customize_cellwidth
@@ -2252,8 +2268,8 @@ EOS
2252
2268
 
2253
2269
  //}
2254
2270
  EOS
2255
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2256
- assert_match(/minicolumn cannot be nested:/, e.message)
2271
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2272
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2257
2273
  end
2258
2274
  end
2259
2275
 
@@ -2269,8 +2285,8 @@ EOS
2269
2285
 
2270
2286
  //}
2271
2287
  EOS
2272
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2273
- assert_match(/minicolumn cannot be nested:/, e.message)
2288
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2289
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2274
2290
  end
2275
2291
  end
2276
2292
 
@@ -2285,8 +2301,8 @@ EOS
2285
2301
 
2286
2302
  //}
2287
2303
  EOS
2288
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2289
- assert_match(/minicolumn cannot be nested:/, e.message)
2304
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2305
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2290
2306
  end
2291
2307
  end
2292
2308
 
@@ -2406,12 +2422,11 @@ EOS
2406
2422
 
2407
2423
  def test_inline_w
2408
2424
  Dir.mktmpdir do |dir|
2409
- File.open(File.join(dir, 'words.csv'), 'w') do |f|
2410
- f.write <<EOB
2425
+ File.write(File.join(dir, 'words.csv'), <<EOB
2411
2426
  "F","foo"
2412
2427
  "B","bar""\\<>_@<b>{BAZ}"
2413
2428
  EOB
2414
- end
2429
+ )
2415
2430
  @book.config['words_file'] = File.join(dir, 'words.csv')
2416
2431
 
2417
2432
  io = StringIO.new
@@ -2427,19 +2442,25 @@ EOS
2427
2442
  end
2428
2443
 
2429
2444
  def test_inline_unknown
2430
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2431
- assert_equal ':1: error: unknown image: n', e.message
2432
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2433
- assert_equal ':1: error: unknown footnote: n', e.message
2434
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2435
- assert_equal ':1: error: unknown headline: n', e.message
2445
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2446
+ assert_match(/unknown image: n/, @log_io.string)
2447
+
2448
+ @log_io.string = ''
2449
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2450
+ assert_match(/unknown footnote: n/, @log_io.string)
2451
+
2452
+ @log_io.string = ''
2453
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2454
+ assert_match(/unknown headline: n/, @log_io.string)
2436
2455
  %w[list table column].each do |name|
2437
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2438
- assert_equal ":1: error: unknown #{name}: n", e.message
2456
+ @log_io.string = ''
2457
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2458
+ assert_match(/unknown #{name}: n/, @log_io.string)
2439
2459
  end
2440
2460
  %w[chap chapref title].each do |name|
2441
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2442
- assert_equal ':1: error: key not found: "n"', e.message
2461
+ @log_io.string = ''
2462
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2463
+ assert_match(/key not found: "n"/, @log_io.string)
2443
2464
  end
2444
2465
  end
2445
2466
 
@@ -2588,7 +2609,7 @@ EOS
2588
2609
  //beginchild
2589
2610
  EOS
2590
2611
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2591
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2612
+ assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2592
2613
  end
2593
2614
 
2594
2615
  def test_nest_error_close2
@@ -2606,7 +2627,7 @@ EOS
2606
2627
  //beginchild
2607
2628
  EOS
2608
2629
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2609
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
2630
+ assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
2610
2631
  end
2611
2632
 
2612
2633
  def test_nest_error_close3
@@ -2626,7 +2647,7 @@ EOS
2626
2647
  //endchild
2627
2648
  EOS
2628
2649
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2629
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
2650
+ assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
2630
2651
  end
2631
2652
 
2632
2653
  def test_nest_ul
@@ -20,6 +20,8 @@ class LATEXBuidlerV2Test < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -1544,19 +1546,25 @@ EOS
1544
1546
  end
1545
1547
 
1546
1548
  def test_inline_unknown
1547
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1548
- assert_equal ':1: error: unknown image: n', e.message
1549
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1550
- assert_equal ':1: error: unknown footnote: n', e.message
1551
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1552
- assert_equal ':1: error: unknown headline: n', e.message
1549
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1550
+ assert_match(/unknown image: n/, @log_io.string)
1551
+
1552
+ @log_io.string = ''
1553
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1554
+ assert_match(/unknown footnote: n/, @log_io.string)
1555
+
1556
+ @log_io.string = ''
1557
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1558
+ assert_match(/unknown headline: n/, @log_io.string)
1553
1559
  %w[list table column].each do |name|
1554
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1555
- assert_equal ":1: error: unknown #{name}: n", e.message
1560
+ @log_io.string = ''
1561
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1562
+ assert_match(/unknown #{name}: n/, @log_io.string)
1556
1563
  end
1557
1564
  %w[chap chapref title].each do |name|
1558
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1559
- assert_equal ':1: error: key not found: "n"', e.message
1565
+ @log_io.string = ''
1566
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1567
+ assert_match(/key not found: "n"/, @log_io.string)
1560
1568
  end
1561
1569
  end
1562
1570
 
@@ -106,6 +106,19 @@ EOS
106
106
  assert_equal %Q(test <span class="red">コメント</span> test2), actual
107
107
  end
108
108
 
109
+ def test_endnote
110
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
111
+ assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
112
+
113
+ actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
114
+ expected = <<-'EOS'
115
+ <sup>(1)</sup>
116
+
117
+ (1) bar
118
+ EOS
119
+ assert_equal expected, actual
120
+ end
121
+
109
122
  def test_inline_hd_chap
110
123
  def @chapter.headline_index
111
124
  item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
@@ -167,6 +167,25 @@ class PDFMakerTest < Test::Unit::TestCase
167
167
  end
168
168
  end
169
169
 
170
+ def test_template_content_with_invalid_localconfig
171
+ Dir.mktmpdir do |dir|
172
+ Dir.chdir(dir) do
173
+ Dir.mkdir('layouts')
174
+ File.write(File.join('layouts', 'config-local.tex.erb'), %q(<%= not_existed_method %>\n))
175
+ @maker.basedir = Dir.pwd
176
+ @maker.erb_config
177
+ @maker.instance_eval do
178
+ def error!(msg)
179
+ msg
180
+ end
181
+ end
182
+ error_msg = @maker.template_content
183
+ assert_match(/template or configuration error:/, error_msg)
184
+ assert_match(/undefined local variable or method `not_existed_method'/, error_msg)
185
+ end
186
+ end
187
+ end
188
+
170
189
  def test_gettemplate_with_backmatter
171
190
  @config.merge!(
172
191
  'backcover' => 'backcover.tex',
@@ -21,7 +21,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  def common_buildpdf(bookdir, templatedir, configfile, targetpdffile, option = nil)
24
- if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
24
+ unless /mswin|mingw|cygwin/.match?(RUBY_PLATFORM)
25
25
  config = prepare_samplebook(@tmpdir1, bookdir, templatedir, configfile)
26
26
  builddir = File.join(@tmpdir1, config['bookname'] + '-pdf')
27
27
  assert !File.exist?(builddir)
@@ -41,7 +41,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
41
41
  def test_pdfmaker_cmd_sample_jsbook_print
42
42
  begin
43
43
  `uplatex -v`
44
- rescue
44
+ rescue StandardError
45
45
  $stderr.puts 'skip test_pdfmaker_cmd_sample_jsbook_print'
46
46
  return true
47
47
  end
@@ -51,7 +51,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
51
51
  def test_pdfmaker_cmd_sample_jsbook_ebook
52
52
  begin
53
53
  `uplatex -v`
54
- rescue
54
+ rescue StandardError
55
55
  $stderr.puts 'skip test_pdfmaker_cmd_sample_jsbook_ebook'
56
56
  return true
57
57
  end
@@ -61,7 +61,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
61
61
  def test_pdfmaker_cmd_sample_jlreq_print
62
62
  begin
63
63
  `uplatex -v`
64
- rescue
64
+ rescue StandardError
65
65
  $stderr.puts 'skip test_pdfmaker_cmd_sample_jlreq_print'
66
66
  return true
67
67
  end
@@ -71,7 +71,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
71
71
  def test_pdfmaker_cmd_sample_jlreq_ebook
72
72
  begin
73
73
  `uplatex -v`
74
- rescue
74
+ rescue StandardError
75
75
  $stderr.puts 'skip test_pdfmaker_cmd_sample_jlreq_ebook'
76
76
  return true
77
77
  end
@@ -81,7 +81,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
81
81
  def test_pdfmaker_cmd_syntax_jsbook_print
82
82
  begin
83
83
  `uplatex -v`
84
- rescue
84
+ rescue StandardError
85
85
  $stderr.puts 'skip test_pdfmaker_cmd_syntax_jsbook_print'
86
86
  return true
87
87
  end
@@ -91,7 +91,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
91
91
  def test_pdfmaker_cmd_syntax_jsbook_print_buildonly
92
92
  begin
93
93
  `uplatex -v`
94
- rescue
94
+ rescue StandardError
95
95
  $stderr.puts 'skip test_pdfmaker_cmd_syntax_jsbook_print_buildonly'
96
96
  return true
97
97
  end
@@ -101,7 +101,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
101
101
  def test_pdfmaker_cmd_syntax_jsbook_ebook
102
102
  begin
103
103
  `uplatex -v`
104
- rescue
104
+ rescue StandardError
105
105
  $stderr.puts 'skip test_pdfmaker_cmd_syntax_jsbook_ebook'
106
106
  return true
107
107
  end
@@ -111,7 +111,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
111
111
  def test_pdfmaker_cmd_syntax_jlreq_ebook
112
112
  begin
113
113
  `uplatex -v`
114
- rescue
114
+ rescue StandardError
115
115
  $stderr.puts 'skip test_pdfmaker_cmd_syntax_jlreq_ebook'
116
116
  return true
117
117
  end
@@ -121,7 +121,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
121
121
  def test_pdfmaker_cmd_syntax_jlreq_ebook_lualatex
122
122
  begin
123
123
  `lualatex -v`
124
- rescue
124
+ rescue StandardError
125
125
  $stderr.puts 'skip test_pdfmaker_cmd_syntax_jlreq_ebook_lualatex'
126
126
  return true
127
127
  end