review 3.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +39 -0
  3. data/.github/workflows/ruby.yml +27 -0
  4. data/.rubocop.yml +50 -12
  5. data/.travis.yml +17 -8
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +358 -0
  8. data/NEWS.md +358 -1
  9. data/README.md +11 -8
  10. data/appveyor.yml +1 -3
  11. data/bin/review-catalog-converter +4 -4
  12. data/bin/review-check +8 -8
  13. data/bin/review-checkdep +1 -1
  14. data/bin/review-compile +12 -12
  15. data/bin/review-epubmaker +3 -35
  16. data/bin/review-idgxmlmaker +16 -0
  17. data/bin/review-index +2 -89
  18. data/bin/review-preproc +14 -19
  19. data/bin/review-validate +3 -3
  20. data/bin/review-vol +4 -78
  21. data/doc/LICENSE +1 -1
  22. data/doc/config.yml.sample +46 -12
  23. data/doc/config.yml.sample-simple +4 -2
  24. data/doc/format.ja.md +37 -13
  25. data/doc/format.md +35 -20
  26. data/doc/pdfmaker.ja.md +43 -1
  27. data/doc/pdfmaker.md +42 -1
  28. data/doc/quickstart.ja.md +46 -26
  29. data/doc/quickstart.md +38 -17
  30. data/lib/epubmaker/epubcommon.rb +10 -5
  31. data/lib/epubmaker/epubv2.rb +1 -1
  32. data/lib/epubmaker/epubv3.rb +1 -0
  33. data/lib/epubmaker/producer.rb +4 -2
  34. data/lib/review/book.rb +1 -1
  35. data/lib/review/book/base.rb +38 -79
  36. data/lib/review/book/chapter.rb +18 -3
  37. data/lib/review/book/compilable.rb +6 -5
  38. data/lib/review/book/index.rb +69 -101
  39. data/lib/review/book/index/item.rb +40 -0
  40. data/lib/review/book/page_metric.rb +7 -7
  41. data/lib/review/book/part.rb +28 -5
  42. data/lib/review/book/volume.rb +3 -4
  43. data/lib/review/builder.rb +105 -44
  44. data/lib/review/catalog.rb +13 -16
  45. data/lib/review/compiler.rb +84 -72
  46. data/lib/review/configure.rb +19 -8
  47. data/lib/review/epub2html.rb +37 -4
  48. data/lib/review/epubmaker.rb +62 -7
  49. data/lib/review/extentions/string.rb +0 -4
  50. data/lib/review/htmlbuilder.rb +102 -115
  51. data/lib/review/htmlutils.rb +2 -3
  52. data/lib/review/i18n.rb +2 -2
  53. data/lib/review/i18n.yml +9 -0
  54. data/lib/review/idgxmlbuilder.rb +153 -74
  55. data/lib/review/idgxmlmaker.rb +191 -0
  56. data/lib/review/init-web/finish.html +10 -0
  57. data/lib/review/init-web/index.html +190 -0
  58. data/lib/review/init-web/review-layout-design.js +691 -0
  59. data/lib/review/init.rb +125 -34
  60. data/lib/review/latexbuilder.rb +199 -88
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/location.rb +32 -0
  63. data/lib/review/logger.rb +4 -8
  64. data/lib/review/makerhelper.rb +24 -5
  65. data/lib/review/markdownbuilder.rb +31 -37
  66. data/lib/review/md2inaobuilder.rb +3 -5
  67. data/lib/review/pdfmaker.rb +44 -22
  68. data/lib/review/plaintextbuilder.rb +106 -85
  69. data/lib/review/preprocessor.rb +32 -41
  70. data/lib/review/rstbuilder.rb +33 -33
  71. data/lib/review/textmaker.rb +19 -3
  72. data/lib/review/textutils.rb +76 -2
  73. data/lib/review/tocprinter.rb +231 -102
  74. data/lib/review/topbuilder.rb +114 -61
  75. data/lib/review/update.rb +19 -19
  76. data/lib/review/version.rb +1 -1
  77. data/lib/review/volumeprinter.rb +99 -0
  78. data/lib/review/webmaker.rb +11 -4
  79. data/lib/review/webtocprinter.rb +38 -35
  80. data/lib/review/yamlloader.rb +26 -16
  81. data/review.gemspec +6 -4
  82. data/samples/sample-book/README.md +7 -2
  83. data/samples/sample-book/src/.gitignore +154 -0
  84. data/samples/sample-book/src/config-ebook.yml +4 -0
  85. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  86. data/samples/sample-book/src/config-jlreq.yml +6 -0
  87. data/samples/sample-book/src/config.yml +2 -2
  88. data/samples/sample-book/src/lib/tasks/review.rake +29 -14
  89. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  90. data/samples/syntax-book/ch01.re +4 -2
  91. data/samples/syntax-book/ch02.re +8 -16
  92. data/samples/syntax-book/ch03.re +3 -6
  93. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  94. data/samples/syntax-book/config-jlreq.yml +5 -0
  95. data/samples/syntax-book/config-print.yml +3 -0
  96. data/samples/syntax-book/config.yml +1 -1
  97. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  98. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  99. data/templates/latex/config.erb +16 -0
  100. data/templates/latex/layout.tex.erb +4 -0
  101. data/templates/latex/review-jlreq/review-base.sty +150 -61
  102. data/templates/latex/review-jlreq/review-jlreq.cls +74 -8
  103. data/templates/latex/review-jlreq/review-style.sty +4 -1
  104. data/templates/latex/review-jsbook/README.md +39 -0
  105. data/templates/latex/review-jsbook/review-base.sty +101 -23
  106. data/templates/latex/review-jsbook/review-jsbook.cls +28 -5
  107. data/templates/latex/review-jsbook/review-style.sty +5 -2
  108. data/templates/opf/epubv3.opf.erb +1 -0
  109. data/templates/web/html/layout-html5.html.erb +2 -2
  110. data/test/assets/test_template.tex +24 -3
  111. data/test/assets/test_template_backmatter.tex +24 -3
  112. data/test/test_book.rb +75 -21
  113. data/test/test_book_chapter.rb +4 -2
  114. data/test/test_book_part.rb +3 -3
  115. data/test/test_builder.rb +16 -0
  116. data/test/test_catalog.rb +24 -42
  117. data/test/test_catalog_converter_cmd.rb +1 -1
  118. data/test/test_epubmaker_cmd.rb +14 -7
  119. data/test/test_helper.rb +15 -7
  120. data/test/test_htmlbuilder.rb +909 -159
  121. data/test/test_i18n.rb +25 -25
  122. data/test/test_idgxmlbuilder.rb +395 -38
  123. data/test/test_idgxmlmaker_cmd.rb +46 -0
  124. data/test/test_image_finder.rb +52 -70
  125. data/test/test_index.rb +50 -10
  126. data/test/test_latexbuilder.rb +1194 -106
  127. data/test/test_latexbuilder_v2.rb +628 -97
  128. data/test/test_logger.rb +14 -1
  129. data/test/test_makerhelper.rb +3 -3
  130. data/test/test_markdownbuilder.rb +134 -16
  131. data/test/test_md2inaobuilder.rb +32 -9
  132. data/test/test_pdfmaker.rb +18 -1
  133. data/test/test_pdfmaker_cmd.rb +100 -6
  134. data/test/test_plaintextbuilder.rb +371 -25
  135. data/test/test_preprocessor.rb +2 -16
  136. data/test/test_rstbuilder.rb +249 -26
  137. data/test/test_textmaker_cmd.rb +54 -0
  138. data/test/test_textutils.rb +109 -2
  139. data/test/test_topbuilder.rb +546 -31
  140. data/test/test_update.rb +17 -8
  141. data/test/test_webtocprinter.rb +66 -34
  142. data/test/test_yamlloader.rb +13 -0
  143. data/vendor/jsclasses/LICENSE +1 -1
  144. data/vendor/jsclasses/jis/jsarticle.cls +53 -14
  145. data/vendor/jsclasses/jis/jsbook.cls +53 -14
  146. data/vendor/jsclasses/jis/jsclasses.dtx +84 -25
  147. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  148. data/vendor/jsclasses/jis/jslogo.sty +3 -3
  149. data/vendor/jsclasses/jis/jspf.cls +52 -13
  150. data/vendor/jsclasses/jis/jsreport.cls +53 -14
  151. data/vendor/jsclasses/jis/kiyou.cls +53 -14
  152. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  153. data/vendor/jsclasses/jis/okumacro.sty +3 -4
  154. data/vendor/jsclasses/jsarticle.cls +53 -14
  155. data/vendor/jsclasses/jsbook.cls +53 -14
  156. data/vendor/jsclasses/jsclasses.dtx +84 -25
  157. data/vendor/jsclasses/jsclasses.pdf +0 -0
  158. data/vendor/jsclasses/jslogo.dtx +4 -4
  159. data/vendor/jsclasses/jslogo.pdf +0 -0
  160. data/vendor/jsclasses/jslogo.sty +3 -3
  161. data/vendor/jsclasses/jspf.cls +52 -13
  162. data/vendor/jsclasses/jsreport.cls +53 -14
  163. data/vendor/jsclasses/kiyou.cls +53 -14
  164. data/vendor/jsclasses/okumacro.dtx +4 -5
  165. data/vendor/jsclasses/okumacro.pdf +0 -0
  166. data/vendor/jsclasses/okumacro.sty +3 -4
  167. metadata +55 -10
  168. data/lib/review/tocparser.rb +0 -271
  169. data/samples/syntax-book/review-ext.rb +0 -14
  170. data/test/test_tocparser.rb +0 -25
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2018 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto
2
2
  # 2002-2006 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -65,11 +65,11 @@ module ReVIEW
65
65
  end
66
66
 
67
67
  def ul_item(lines)
68
- puts "●\t#{lines.join}"
68
+ puts "●\t#{join_lines_to_paragraph(lines)}"
69
69
  end
70
70
 
71
71
  def ol_item(lines, num)
72
- puts "#{num}\t#{lines.join}"
72
+ puts "#{num}\t#{join_lines_to_paragraph(lines)}"
73
73
  end
74
74
 
75
75
  def dt(line)
@@ -91,30 +91,50 @@ module ReVIEW
91
91
 
92
92
  alias_method :lead, :read
93
93
 
94
- def list_header(id, caption, _lang)
94
+ def list(lines, id, caption, lang = nil)
95
95
  blank
96
96
  puts "◆→開始:#{@titles['list']}←◆"
97
+ begin
98
+ if caption_top?('list')
99
+ list_header(id, caption, lang)
100
+ blank
101
+ end
102
+ list_body(id, lines, lang)
103
+ unless caption_top?('list')
104
+ blank
105
+ list_header(id, caption, lang)
106
+ end
107
+ rescue KeyError
108
+ error "no such list: #{id}"
109
+ end
110
+ puts "◆→終了:#{@titles['list']}←◆"
111
+ blank
112
+ end
113
+
114
+ def list_header(id, caption, _lang)
97
115
  if get_chap
98
116
  puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
99
117
  else
100
118
  puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
101
119
  end
102
- blank
103
120
  end
104
121
 
105
122
  def list_body(_id, lines, _lang)
106
123
  lines.each do |line|
107
124
  puts detab(line)
108
125
  end
109
- puts "◆→終了:#{@titles['list']}←◆"
110
- blank
111
126
  end
112
127
 
113
128
  def base_block(type, lines, caption = nil)
114
129
  blank
115
130
  puts "◆→開始:#{@titles[type]}←◆"
116
- puts "■#{compile_inline(caption)}" if caption.present?
131
+ if caption_top?('list') && caption.present?
132
+ puts "■#{compile_inline(caption)}"
133
+ end
117
134
  puts lines.join("\n")
135
+ if !caption_top?('list') && caption.present?
136
+ puts "■#{compile_inline(caption)}"
137
+ end
118
138
  puts "◆→終了:#{@titles[type]}←◆"
119
139
  blank
120
140
  end
@@ -131,20 +151,43 @@ module ReVIEW
131
151
  def emlistnum(lines, caption = nil, _lang = nil)
132
152
  blank
133
153
  puts "◆→開始:#{@titles['emlist']}←◆"
134
- puts "■#{compile_inline(caption)}" if caption.present?
154
+ if caption_top?('list') && caption.present?
155
+ puts "■#{compile_inline(caption)}"
156
+ end
135
157
  lines.each_with_index do |line, i|
136
158
  puts((i + 1).to_s.rjust(2) + ": #{line}")
137
159
  end
160
+ if !caption_top?('list') && caption.present?
161
+ puts "■#{compile_inline(caption)}"
162
+ end
138
163
  puts "◆→終了:#{@titles['emlist']}←◆"
139
164
  blank
140
165
  end
141
166
 
167
+ def listnum(lines, id, caption, lang = nil)
168
+ blank
169
+ puts "◆→開始:#{@titles['list']}←◆"
170
+ begin
171
+ if caption_top?('list') && caption.present?
172
+ list_header(id, caption, lang)
173
+ blank
174
+ end
175
+ listnum_body(lines, lang)
176
+ if !caption_top?('list') && caption.present?
177
+ blank
178
+ list_header(id, caption, lang)
179
+ end
180
+ rescue KeyError
181
+ error "no such list: #{id}"
182
+ end
183
+ puts "◆→終了:#{@titles['list']}←◆"
184
+ blank
185
+ end
186
+
142
187
  def listnum_body(lines, _lang)
143
188
  lines.each_with_index do |line, i|
144
189
  puts((i + 1).to_s.rjust(2) + ": #{line}")
145
190
  end
146
- puts "◆→終了:#{@titles['list']}←◆"
147
- blank
148
191
  end
149
192
 
150
193
  def image(lines, id, caption, metric = nil)
@@ -152,13 +195,11 @@ module ReVIEW
152
195
  metrics = " #{metrics}" if metrics.present?
153
196
  blank
154
197
  puts "◆→開始:#{@titles['image']}←◆"
155
- if get_chap
156
- puts "#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
157
- else
158
- puts "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
198
+ if caption_top?('image')
199
+ image_header(id, caption)
200
+ blank
159
201
  end
160
- blank
161
- if @chapter.image(id).bound?
202
+ if @chapter.image_bound?(id)
162
203
  puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
163
204
  else
164
205
  warn "image not bound: #{id}"
@@ -166,13 +207,47 @@ module ReVIEW
166
207
  puts line
167
208
  end
168
209
  end
210
+ unless caption_top?('image')
211
+ blank
212
+ image_header(id, caption)
213
+ end
169
214
  puts "◆→終了:#{@titles['image']}←◆"
170
215
  blank
171
216
  end
172
217
 
218
+ def image_header(id, caption)
219
+ if get_chap
220
+ puts "#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
221
+ else
222
+ puts "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
223
+ end
224
+ end
225
+
173
226
  def texequation(lines, id = nil, caption = '')
174
227
  blank
175
228
  puts "◆→開始:#{@titles['texequation']}←◆"
229
+ texequation_header(id, caption) if caption_top?('equation')
230
+
231
+ if @book.config['imgmath']
232
+ fontsize = @book.config['imgmath_options']['fontsize'].to_f
233
+ lineheight = @book.config['imgmath_options']['lineheight'].to_f
234
+ math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n"
235
+ key = Digest::SHA256.hexdigest(math_str)
236
+ math_dir = File.join(@book.config['imagedir'], '_review_math_text')
237
+ Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
238
+ img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
239
+ defer_math_image(math_str, img_path, key)
240
+ puts "◆→math:#{File.basename(img_path)}←◆"
241
+ else
242
+ puts lines.join("\n")
243
+ end
244
+
245
+ texequation_header(id, caption) unless caption_top?('equation')
246
+ puts "◆→終了:#{@titles['texequation']}←◆"
247
+ blank
248
+ end
249
+
250
+ def texequation_header(id, caption)
176
251
  if id
177
252
  if get_chap
178
253
  puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
@@ -180,49 +255,14 @@ module ReVIEW
180
255
  puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
181
256
  end
182
257
  end
183
- puts lines.join("\n")
184
- puts "◆→終了:#{@titles['texequation']}←◆"
185
- blank
186
258
  end
187
259
 
188
260
  def table(lines, id = nil, caption = nil)
189
261
  blank
190
262
  puts "◆→開始:#{@titles['table']}←◆"
191
-
192
- rows = []
193
- sepidx = nil
194
- lines.each_with_index do |line, idx|
195
- if /\A[\=\-]{12}/ =~ line
196
- # just ignore
197
- # error "too many table separator" if sepidx
198
- sepidx ||= idx
199
- next
200
- end
201
- rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
202
- end
203
- rows = adjust_n_cols(rows)
204
-
205
- begin
206
- table_header id, caption if caption.present?
207
- rescue KeyError
208
- error "no such table: #{id}"
209
- end
210
- return if rows.empty?
211
- table_begin rows.first.size
212
- if sepidx
213
- sepidx.times do
214
- tr(rows.shift.map { |s| th(s) })
215
- end
216
- rows.each do |cols|
217
- tr(cols.map { |s| td(s) })
218
- end
219
- else
220
- rows.each do |cols|
221
- h, *cs = *cols
222
- tr([th(h)] + cs.map { |s| td(s) })
223
- end
224
- end
225
- table_end
263
+ super(lines, id, caption, true)
264
+ puts "◆→終了:#{@titles['table']}←◆"
265
+ blank
226
266
  end
227
267
 
228
268
  def th(str)
@@ -230,17 +270,15 @@ module ReVIEW
230
270
  end
231
271
 
232
272
  def table_end
233
- puts "◆→終了:#{@titles['table']}←◆"
234
- blank
235
273
  end
236
274
 
237
275
  def comment(lines, comment = nil)
238
276
  return unless @book.config['draft']
239
277
  lines ||= []
240
278
  unless comment.blank?
241
- lines.unshift comment
279
+ lines.unshift(comment)
242
280
  end
243
- str = lines.join
281
+ str = lines.join("\n")
244
282
  puts "◆→#{str}←◆"
245
283
  end
246
284
 
@@ -359,7 +397,17 @@ module ReVIEW
359
397
  end
360
398
 
361
399
  def inline_m(str)
362
- %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
400
+ if @book.config['imgmath']
401
+ math_str = '$' + str + '$'
402
+ key = Digest::SHA256.hexdigest(str)
403
+ math_dir = File.join(@book.config['imagedir'], '_review_math_text')
404
+ Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
405
+ img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
406
+ defer_math_image(math_str, img_path, key)
407
+ %Q(◆→TeX式ここから←◆◆→math:#{File.basename(img_path)}←◆◆→TeX式ここまで←◆)
408
+ else
409
+ %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
410
+ end
363
411
  end
364
412
 
365
413
  def bibpaper_header(id, caption)
@@ -400,13 +448,18 @@ module ReVIEW
400
448
  metrics = parse_metric('top', metric)
401
449
  metrics = " #{metrics}" if metrics.present?
402
450
  blank
451
+ if caption_top?('image') && caption.present?
452
+ puts "図 #{compile_inline(caption)}"
453
+ end
403
454
  begin
404
455
  puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆"
405
456
  rescue
406
457
  warn "image not bound: #{id}"
407
458
  puts "◆→画像 #{id}←◆"
408
459
  end
409
- puts "図 #{compile_inline(caption)}" if caption.present?
460
+ if !caption_top?('image') && caption.present?
461
+ puts "図 #{compile_inline(caption)}"
462
+ end
410
463
  blank
411
464
  end
412
465
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2018 Kenshi Muto
2
+ # Copyright (c) 2018-2019 Kenshi Muto
3
3
  #
4
4
  # This program is free software.
5
5
  # You can distribute or modify this program under the terms of
@@ -20,14 +20,14 @@ module ReVIEW
20
20
  end
21
21
 
22
22
  # should be
23
- TARGET_VERSION = '3.0'
23
+ TARGET_VERSION = '4.0'
24
24
  EPUB_VERSION = '3'
25
25
  HTML_VERSION = '5'
26
26
  TEX_DOCUMENTCLASS = ['review-jsbook', 'review-jlreq']
27
27
  TEX_DOCUMENTCLASS_BAD = ['jsbook', nil]
28
28
  TEX_DOCUMENTCLASS_OPTS = 'media=print,paper=a5'
29
29
  TEX_COMMAND = 'uplatex'
30
- TEX_OPTIONS = '-interaction=nonstopmode -file-line-error'
30
+ TEX_OPTIONS = '-interaction=nonstopmode -file-line-error -halt-on-error'
31
31
  DVI_COMMAND = 'dvipdfmx'
32
32
  DVI_OPTIONS = '-d 5 -z 9'
33
33
 
@@ -126,7 +126,7 @@ module ReVIEW
126
126
  content = File.read(yml)
127
127
  content.gsub!(/^(\s*)#{key}:.*$/, '\1' + "#{key}: #{val}")
128
128
  if @backup
129
- FileUtils.mv yml, "#{yml}-old"
129
+ FileUtils.mv(yml, "#{yml}-old")
130
130
  end
131
131
  File.write(yml, content)
132
132
  end
@@ -145,8 +145,8 @@ module ReVIEW
145
145
 
146
146
  begin
147
147
  opts.parse!(args)
148
- rescue OptionParser::ParseError => err
149
- @logger.error err.message
148
+ rescue OptionParser::ParseError => e
149
+ @logger.error e.message
150
150
  $stderr.puts opts.help
151
151
  raise ApplicationError
152
152
  end
@@ -257,7 +257,7 @@ module ReVIEW
257
257
  def update_rakefile(dir)
258
258
  taskdir = File.join(dir, 'lib/tasks')
259
259
  unless File.exist?(taskdir)
260
- FileUtils.mkdir_p taskdir
260
+ FileUtils.mkdir_p(taskdir)
261
261
  end
262
262
 
263
263
  master_rakefile = File.join(@review_dir, 'samples/sample-book/src/Rakefile')
@@ -266,13 +266,13 @@ module ReVIEW
266
266
  if File.exist?(target_rakefile)
267
267
  if Digest::SHA256.hexdigest(File.read(target_rakefile)) != Digest::SHA256.hexdigest(File.read(master_rakefile))
268
268
  if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', ['Rakefile', master_rakefile])
269
- FileUtils.mv target_rakefile, "#{target_rakefile}-old"
270
- FileUtils.cp master_rakefile, target_rakefile
269
+ FileUtils.mv(target_rakefile, "#{target_rakefile}-old")
270
+ FileUtils.cp(master_rakefile, target_rakefile)
271
271
  end
272
272
  end
273
273
  else
274
274
  @logger.info t('new file %s is created.', [target_rakefile]) unless @force
275
- FileUtils.cp master_rakefile, target_rakefile
275
+ FileUtils.cp(master_rakefile, target_rakefile)
276
276
  end
277
277
 
278
278
  master_rakefile = File.join(@review_dir, 'samples/sample-book/src/lib/tasks/review.rake')
@@ -280,13 +280,13 @@ module ReVIEW
280
280
  if File.exist?(target_rakefile)
281
281
  if Digest::SHA256.hexdigest(File.read(target_rakefile)) != Digest::SHA256.hexdigest(File.read(master_rakefile))
282
282
  if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', ['lib/tasks/review.rake', master_rakefile])
283
- FileUtils.mv target_rakefile, "#{target_rakefile}-old"
284
- FileUtils.cp master_rakefile, target_rakefile
283
+ FileUtils.mv(target_rakefile, "#{target_rakefile}-old")
284
+ FileUtils.cp(master_rakefile, target_rakefile)
285
285
  end
286
286
  end
287
287
  else
288
288
  @logger.info t('new file %s is created.', [target_rakefile]) unless @force
289
- FileUtils.cp master_rakefile, target_rakefile
289
+ FileUtils.cp(master_rakefile, target_rakefile)
290
290
  end
291
291
  end
292
292
 
@@ -469,7 +469,7 @@ module ReVIEW
469
469
  def update_tex_stys(template, dir)
470
470
  texmacrodir = File.join(dir, 'sty')
471
471
  unless File.exist?(texmacrodir)
472
- FileUtils.mkdir texmacrodir
472
+ FileUtils.mkdir(texmacrodir)
473
473
  end
474
474
 
475
475
  tdir = File.join(@review_dir, 'templates/latex', template)
@@ -479,7 +479,7 @@ module ReVIEW
479
479
  unless File.exist?(target_styfile)
480
480
  # just copy
481
481
  @logger.info t('new file %s is created.', [target_styfile]) unless @force
482
- FileUtils.cp master_styfile, target_styfile
482
+ FileUtils.cp(master_styfile, target_styfile)
483
483
  next
484
484
  end
485
485
  if File.basename(target_styfile) == 'review-custom.sty'
@@ -492,20 +492,20 @@ module ReVIEW
492
492
  end
493
493
 
494
494
  if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', [target_styfile, master_styfile])
495
- FileUtils.mv target_styfile, "#{target_styfile}-old"
496
- FileUtils.cp master_styfile, target_styfile
495
+ FileUtils.mv(target_styfile, "#{target_styfile}-old")
496
+ FileUtils.cp(master_styfile, target_styfile)
497
497
  end
498
498
  end
499
499
 
500
500
  if template == 'review-jsbook'
501
501
  unless File.exist?(File.join(texmacrodir, 'jsbook.cls'))
502
502
  @logger.info t('new file %s is created.', [File.join(texmacrodir, 'jsbook.cls')]) unless @force
503
- FileUtils.cp File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls')
503
+ FileUtils.cp(File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls'))
504
504
  end
505
505
 
506
506
  unless File.exist?(File.join(texmacrodir, 'gentombow.sty'))
507
507
  @logger.info t('new file %s is created.', [File.join(texmacrodir, 'gentombow.sty')]) unless @force
508
- FileUtils.cp File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty')
508
+ FileUtils.cp(File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty'))
509
509
  end
510
510
  end
511
511
  end
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '4.2.0'.freeze
3
3
  end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Copyright (c) 2014-2020 Minero Aoki, Kenshi Muto
3
+ # 2003-2014 Minero Aoki
4
+ #
5
+ # This program is free software.
6
+ # You can distribute or modify this program under the terms of
7
+ # the GNU LGPL, Lesser General Public License version 2.1.
8
+ # For details of the GNU LGPL, see the file "COPYING".
9
+ #
10
+ require 'optparse'
11
+ require 'review'
12
+ require 'review/i18n'
13
+ require 'review/plaintextbuilder'
14
+
15
+ include ReVIEW::TextUtils
16
+
17
+ module ReVIEW
18
+ class VolumePrinter
19
+ def self.execute(*args)
20
+ new.execute(*args)
21
+ end
22
+
23
+ def initialize
24
+ @logger = ReVIEW.logger
25
+ @config = ReVIEW::Configure.values
26
+ @yamlfile = 'config.yml'
27
+ end
28
+
29
+ def execute(*args)
30
+ parse_options(args)
31
+ @book = ReVIEW::Book::Base.load
32
+ @book.config = @config
33
+ unless File.readable?(@yamlfile)
34
+ @logger.error("No such fiile or can't open #{@yamlfile}.")
35
+ exit 1
36
+ end
37
+ @book.load_config(@yamlfile)
38
+ I18n.setup(@book.config['language'])
39
+
40
+ begin
41
+ @book.each_part do |part|
42
+ if part.number
43
+ print_chapter_volume(part)
44
+ end
45
+ part.each_chapter do |chap|
46
+ print_chapter_volume(chap)
47
+ end
48
+ end
49
+ rescue ReVIEW::FileNotFound => e
50
+ @logger.error e
51
+ exit 1
52
+ end
53
+ puts '============================='
54
+ print_volume(@book.volume)
55
+ end
56
+
57
+ def parse_options(args)
58
+ opts = OptionParser.new
59
+ opts.version = ReVIEW::VERSION
60
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @yamlfile = yaml }
61
+ opts.on('--help', 'Print this message and quit') do
62
+ puts opts.help
63
+ exit 0
64
+ end
65
+ begin
66
+ opts.parse!(args)
67
+ rescue OptionParser::ParseError => e
68
+ @logger.error e.message
69
+ $stderr.puts opts.help
70
+ exit 1
71
+ end
72
+ end
73
+
74
+ def print_chapter_volume(chap)
75
+ builder = ReVIEW::PLAINTEXTBuilder.new
76
+ builder.bind(ReVIEW::Compiler.new(builder), chap, nil)
77
+
78
+ vol = chap.volume
79
+ title = chap.format_number
80
+ unless title.empty?
81
+ title += ' '
82
+ end
83
+ begin
84
+ title += builder.compile_inline(chap.title)
85
+ rescue ReVIEW::ApplicationError => e
86
+ @logger.warn "#{chap.name} : #{e.message.sub(/.+error: /, '')}"
87
+ end
88
+
89
+ printf("%3dKB %6dC %5dL %3dP %s %-s\n",
90
+ vol.kbytes, vol.chars, vol.lines, vol.page,
91
+ "#{chap.name} ".ljust(15, '.'), title)
92
+ end
93
+
94
+ def print_volume(vol)
95
+ # total
96
+ printf("%3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page)
97
+ end
98
+ end
99
+ end