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 PLAINTEXTBuidlerTest < Test::Unit::TestCase
14
14
  @config['language'] = 'ja'
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)
@@ -469,10 +471,10 @@ EOS
469
471
 
470
472
  def test_empty_table
471
473
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
472
- assert_equal ':2: error: no rows in the table', e.message
474
+ assert_equal 'no rows in the table', e.message
473
475
 
474
476
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
475
- assert_equal ':3: error: no rows in the table', e.message
477
+ assert_equal 'no rows in the table', e.message
476
478
  end
477
479
 
478
480
  def test_inline_table
@@ -691,8 +693,8 @@ EOS
691
693
 
692
694
  //}
693
695
  EOS
694
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
695
- assert_match(/minicolumn cannot be nested:/, e.message)
696
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
697
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
696
698
  end
697
699
  end
698
700
 
@@ -708,8 +710,8 @@ EOS
708
710
 
709
711
  //}
710
712
  EOS
711
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
712
- assert_match(/minicolumn cannot be nested:/, e.message)
713
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
714
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
713
715
  end
714
716
  end
715
717
 
@@ -724,8 +726,8 @@ EOS
724
726
 
725
727
  //}
726
728
  EOS
727
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
728
- assert_match(/minicolumn cannot be nested:/, e.message)
729
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
730
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
729
731
  end
730
732
  end
731
733
 
@@ -760,20 +762,42 @@ EOS
760
762
  assert_equal %Q(\\sin\n1^{2}\n\n), actual
761
763
  end
762
764
 
765
+ def test_endnote
766
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
767
+ assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
768
+
769
+ actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
770
+ expected = <<-'EOS'
771
+ (1)
772
+ (1) bar
773
+ EOS
774
+ assert_equal expected, actual
775
+ end
776
+
763
777
  def test_inline_unknown
764
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
765
- assert_equal ':1: error: unknown image: n', e.message
766
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
767
- assert_equal ':1: error: unknown footnote: n', e.message
768
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
769
- assert_equal ':1: error: unknown headline: n', e.message
778
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
779
+ assert_match(/unknown image: n/, @log_io.string)
780
+
781
+ @log_io.string = ''
782
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
783
+ assert_match(/unknown footnote: n/, @log_io.string)
784
+
785
+ @log_io.string = ''
786
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<endnote>{n}\n") }
787
+ assert_match(/unknown endnote: n/, @log_io.string)
788
+
789
+ @log_io.string = ''
790
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
791
+ assert_match(/unknown headline: n/, @log_io.string)
770
792
  %w[list table column].each do |name|
771
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
772
- assert_equal ":1: error: unknown #{name}: n", e.message
793
+ @log_io.string = ''
794
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
795
+ assert_match(/unknown #{name}: n/, @log_io.string)
773
796
  end
774
797
  %w[chap chapref title].each do |name|
775
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
776
- assert_equal ':1: error: key not found: "n"', e.message
798
+ @log_io.string = ''
799
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
800
+ assert_match(/key not found: "n"/, @log_io.string)
777
801
  end
778
802
  end
779
803
 
@@ -891,7 +915,7 @@ EOS
891
915
  //endchild
892
916
  EOS
893
917
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
894
- assert_equal ":1: error: //endchild is shown, but any opened //beginchild doesn't exist", e.message
918
+ assert_equal ":1: //endchild is shown, but any opened //beginchild doesn't exist", e.message
895
919
  end
896
920
 
897
921
  def test_nest_error_close1
@@ -899,7 +923,7 @@ EOS
899
923
  //beginchild
900
924
  EOS
901
925
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
902
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
926
+ assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
903
927
  end
904
928
 
905
929
  def test_nest_error_close2
@@ -917,7 +941,7 @@ EOS
917
941
  //beginchild
918
942
  EOS
919
943
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
920
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
944
+ assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
921
945
  end
922
946
 
923
947
  def test_nest_error_close3
@@ -937,7 +961,7 @@ EOS
937
961
  //endchild
938
962
  EOS
939
963
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
940
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
964
+ assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
941
965
  end
942
966
 
943
967
  def test_nest_ul
@@ -1,9 +1,196 @@
1
1
  require 'test_helper'
2
2
  require 'review/preprocessor'
3
3
  require 'stringio'
4
+ require 'book_test_helper'
4
5
 
5
6
  class PreprocessorTest < Test::Unit::TestCase
6
7
  include ReVIEW
8
+ include BookTestHelper
7
9
 
8
- ## TODO: add tests
10
+ def test_mapfile
11
+ preproc = ReVIEW::Preprocessor.new({})
12
+
13
+ ch01_re = <<-'REFILE'
14
+ = test1
15
+
16
+ //list[hello.rb.1][hello.re]{
17
+ #@mapfile(hello.rb)
18
+ #@end
19
+ //}
20
+ REFILE
21
+
22
+ hello_rb = <<-'RBFILE'
23
+ #!/usr/bin/env ruby
24
+
25
+ class Hello
26
+ def hello(name)
27
+ print "hello, #{name}!\n"
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ Hello.new.hello("world")
33
+ end
34
+ RBFILE
35
+
36
+ expected = <<-'EXPECTED'
37
+ = test1
38
+
39
+ //list[hello.rb.1][hello.re]{
40
+ #@mapfile(hello.rb)
41
+ #!/usr/bin/env ruby
42
+
43
+ class Hello
44
+ def hello(name)
45
+ print "hello, #{name}!\n"
46
+ end
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ Hello.new.hello("world")
51
+ end
52
+ #@end
53
+ //}
54
+ EXPECTED
55
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
56
+ 'ch01.re' => ch01_re,
57
+ 'hello.rb' => hello_rb) do |_dir, _book, _files|
58
+ preproc.process('ch01.re')
59
+ end
60
+ assert_equal expected, converted
61
+ end
62
+
63
+ def test_mapfile_tabwidth_is_4
64
+ param = { 'tabwidth' => 4 }
65
+ preproc = ReVIEW::Preprocessor.new(param)
66
+
67
+ ch01 = <<-'REFILE'
68
+ //emlist[test1][inc.txt]{
69
+ #@mapfile(inc.txt)
70
+ #@end
71
+ //}
72
+ REFILE
73
+
74
+ inc_txt = <<-'INC_TXT'
75
+ test.
76
+ test2.
77
+
78
+ test3.
79
+
80
+ test4.
81
+
82
+ test5.
83
+ INC_TXT
84
+
85
+ expected = <<-'EXPECTED'
86
+ //emlist[test1][inc.txt]{
87
+ #@mapfile(inc.txt)
88
+ test.
89
+ test2.
90
+
91
+ test3.
92
+
93
+ test4.
94
+
95
+ test5.
96
+ #@end
97
+ //}
98
+ EXPECTED
99
+ converted = nil
100
+ mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
101
+ 'inc.txt' => inc_txt,
102
+ 'ch01.re' => ch01) do |_dir, _book, _files|
103
+ converted = preproc.process('ch01.re')
104
+ end
105
+ assert_equal expected, converted
106
+ end
107
+
108
+ def test_maprange
109
+ preproc = ReVIEW::Preprocessor.new({})
110
+
111
+ ch01_re = <<-'REFILE'
112
+ //list[range.rb][range.rb(抜粋)]{
113
+ #@maprange(range.rb,sample)
114
+ #@end
115
+ //}
116
+ REFILE
117
+
118
+ range_rb = <<-'RBFILE'
119
+ #!/usr/bin/env ruby
120
+
121
+ class Hello
122
+ #@range_begin(sample)
123
+ def hello(name)
124
+ print "hello, #{name}!\n"
125
+ end
126
+ #@range_end(sample)
127
+ end
128
+
129
+ if __FILE__ == $0
130
+ Hello.new.hello("world")
131
+ end
132
+ RBFILE
133
+
134
+ expected = <<-'EXPECTED'
135
+ //list[range.rb][range.rb(抜粋)]{
136
+ #@maprange(range.rb,sample)
137
+ def hello(name)
138
+ print "hello, #{name}!\n"
139
+ end
140
+ #@end
141
+ //}
142
+ EXPECTED
143
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
144
+ 'ch01.re' => ch01_re,
145
+ 'range.rb' => range_rb) do |_dir, _book, _files|
146
+ preproc.process('ch01.re')
147
+ end
148
+ assert_equal expected, converted
149
+ end
150
+
151
+ def test_at_at_maprange
152
+ preproc = ReVIEW::Preprocessor.new({})
153
+
154
+ ch01_re = <<-'REFILE'
155
+ //list[range.c][range.c(抜粋)]{
156
+ #@maprange(range.c,sample)
157
+ #@end
158
+ //}
159
+ REFILE
160
+
161
+ range_c = <<-'CFILE'
162
+ #include <stdio.h>
163
+
164
+ /* #@@range_begin(sample) */
165
+ void
166
+ put_hello(char *name)
167
+ {
168
+ printf("hello, %s!\n", name);
169
+ }
170
+ /* #@@range_end(sample) */
171
+
172
+ int main()
173
+ {
174
+ put_hello("world");
175
+ }
176
+ CFILE
177
+
178
+ expected = <<-'EXPECTED'
179
+ //list[range.c][range.c(抜粋)]{
180
+ #@maprange(range.c,sample)
181
+ void
182
+ put_hello(char *name)
183
+ {
184
+ printf("hello, %s!\n", name);
185
+ }
186
+ #@end
187
+ //}
188
+ EXPECTED
189
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
190
+ 'ch01.re' => ch01_re,
191
+ 'range.c' => range_c) do |_dir, _book, _files|
192
+ preproc.process('ch01.re')
193
+ end
194
+ assert_equal expected, converted
195
+ end
9
196
  end
@@ -513,6 +513,19 @@ EOS
513
513
 
514
514
  \\sin 1^{2}
515
515
 
516
+ EOS
517
+ assert_equal expected, actual
518
+ end
519
+
520
+ def test_endnote
521
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
522
+ assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
523
+
524
+ actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
525
+ expected = <<-'EOS'
526
+ [(1)]_
527
+
528
+ .. [(1)] bar
516
529
  EOS
517
530
  assert_equal expected, actual
518
531
  end
@@ -21,7 +21,7 @@ class TEXTMakerCmdTest < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  def common_buildtext(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'] + '-text')
27
27
  assert !File.exist?(builddir)