review 4.0.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +31 -0
  3. data/.github/workflows/ruby-win.yml +45 -0
  4. data/.github/workflows/ruby.yml +27 -0
  5. data/.rubocop.yml +141 -38
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +338 -1
  8. data/NEWS.md +339 -2
  9. data/README.md +11 -7
  10. data/Rakefile +7 -2
  11. data/appveyor.yml +0 -20
  12. data/bin/review +2 -4
  13. data/bin/review-catalog-converter +4 -4
  14. data/bin/review-check +8 -12
  15. data/bin/review-checkdep +2 -5
  16. data/bin/review-compile +11 -20
  17. data/bin/review-epub2html +1 -4
  18. data/bin/review-epubmaker +3 -4
  19. data/bin/review-idgxmlmaker +1 -3
  20. data/bin/review-index +5 -86
  21. data/bin/review-init +1 -4
  22. data/bin/review-pdfmaker +1 -3
  23. data/bin/review-preproc +3 -5
  24. data/bin/review-textmaker +1 -3
  25. data/bin/review-update +1 -4
  26. data/bin/review-validate +5 -5
  27. data/bin/review-vol +5 -82
  28. data/bin/review-webmaker +1 -3
  29. data/doc/config.yml.sample +55 -12
  30. data/doc/config.yml.sample-simple +4 -3
  31. data/doc/format.ja.md +119 -17
  32. data/doc/format.md +106 -17
  33. data/doc/makeindex.ja.md +2 -2
  34. data/doc/pdfmaker.ja.md +42 -0
  35. data/doc/pdfmaker.md +41 -0
  36. data/doc/quickstart.ja.md +55 -25
  37. data/doc/quickstart.md +47 -17
  38. data/lib/review.rb +1 -1
  39. data/lib/review/book.rb +2 -2
  40. data/lib/review/book/base.rb +69 -30
  41. data/lib/review/book/bib.rb +21 -0
  42. data/lib/review/book/book_unit.rb +158 -0
  43. data/lib/review/book/chapter.rb +33 -26
  44. data/lib/review/book/index.rb +39 -206
  45. data/lib/review/book/index/item.rb +8 -2
  46. data/lib/review/book/page_metric.rb +7 -7
  47. data/lib/review/book/part.rb +26 -11
  48. data/lib/review/book/volume.rb +5 -5
  49. data/lib/review/builder.rb +124 -27
  50. data/lib/review/call_hook.rb +20 -0
  51. data/lib/review/catalog.rb +3 -2
  52. data/lib/review/compiler.rb +197 -91
  53. data/lib/review/configure.rb +95 -9
  54. data/lib/review/converter.rb +1 -1
  55. data/lib/review/epub2html.rb +6 -1
  56. data/lib/review/epubmaker.rb +116 -117
  57. data/lib/review/epubmaker/content.rb +113 -0
  58. data/lib/review/epubmaker/epubcommon.rb +372 -0
  59. data/lib/review/epubmaker/epubv2.rb +178 -0
  60. data/lib/review/epubmaker/epubv3.rb +231 -0
  61. data/lib/review/epubmaker/producer.rb +168 -0
  62. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  63. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  64. data/lib/review/exception.rb +6 -0
  65. data/lib/review/extentions/string.rb +0 -4
  66. data/lib/review/htmlbuilder.rb +132 -87
  67. data/lib/review/htmlutils.rb +8 -11
  68. data/lib/review/i18n.rb +2 -1
  69. data/lib/review/idgxmlbuilder.rb +156 -76
  70. data/lib/review/idgxmlmaker.rb +22 -18
  71. data/lib/review/img_math.rb +245 -0
  72. data/lib/review/index_builder.rb +654 -0
  73. data/lib/review/init.rb +17 -18
  74. data/lib/review/latexbox.rb +58 -0
  75. data/lib/review/latexbuilder.rb +173 -43
  76. data/lib/review/latexutils.rb +9 -1
  77. data/lib/review/lineinput.rb +112 -2
  78. data/lib/review/logger.rb +42 -3
  79. data/lib/review/makerhelper.rb +12 -187
  80. data/lib/review/markdownbuilder.rb +51 -2
  81. data/lib/review/pdfmaker.rb +78 -73
  82. data/lib/review/plaintextbuilder.rb +98 -14
  83. data/lib/review/preprocessor.rb +18 -12
  84. data/lib/review/rstbuilder.rb +28 -9
  85. data/lib/review/sec_counter.rb +14 -0
  86. data/lib/review/template.rb +6 -0
  87. data/lib/review/textmaker.rb +21 -19
  88. data/lib/review/textutils.rb +3 -12
  89. data/lib/review/tocprinter.rb +242 -97
  90. data/lib/review/topbuilder.rb +91 -24
  91. data/lib/review/update.rb +12 -13
  92. data/lib/review/version.rb +1 -1
  93. data/lib/review/volumeprinter.rb +97 -0
  94. data/lib/review/webmaker.rb +34 -33
  95. data/lib/review/webtocprinter.rb +39 -35
  96. data/lib/review/yamlloader.rb +2 -1
  97. data/review.gemspec +5 -3
  98. data/samples/sample-book/src/.gitignore +1 -0
  99. data/samples/sample-book/src/config-ebook.yml +4 -0
  100. data/samples/sample-book/src/config-epub2.yml +1 -1
  101. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  102. data/samples/sample-book/src/config.yml +3 -3
  103. data/samples/sample-book/src/lib/tasks/review.rake +26 -6
  104. data/samples/syntax-book/Gemfile +1 -1
  105. data/samples/syntax-book/ch01.re +3 -1
  106. data/samples/syntax-book/ch02.re +28 -21
  107. data/samples/syntax-book/ch03.re +1 -1
  108. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  109. data/samples/syntax-book/config-print.yml +3 -0
  110. data/samples/syntax-book/config.yml +1 -1
  111. data/samples/syntax-book/images/img3-2.png +0 -0
  112. data/samples/syntax-book/lib/tasks/review.rake +23 -8
  113. data/templates/html/_colophon.html.erb +23 -0
  114. data/templates/html/_colophon_history.html.erb +9 -0
  115. data/templates/html/_cover.html.erb +10 -0
  116. data/templates/html/_part_body.html.erb +6 -0
  117. data/templates/html/_titlepage.html.erb +20 -0
  118. data/templates/html/layout-html5.html.erb +6 -0
  119. data/templates/html/layout-xhtml1.html.erb +6 -0
  120. data/templates/latex/config.erb +41 -29
  121. data/templates/latex/review-jlreq/README.md +3 -1
  122. data/templates/latex/review-jlreq/review-base.sty +47 -22
  123. data/templates/latex/review-jlreq/review-jlreq.cls +25 -24
  124. data/templates/latex/review-jlreq/review-style.sty +6 -1
  125. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  126. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  127. data/templates/latex/review-jsbook/README.md +7 -5
  128. data/templates/latex/review-jsbook/review-base.sty +47 -21
  129. data/templates/latex/review-jsbook/review-jsbook.cls +12 -2
  130. data/templates/latex/review-jsbook/review-style.sty +6 -1
  131. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  132. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  133. data/templates/opf/epubv2.opf.erb +7 -7
  134. data/templates/opf/epubv3.opf.erb +7 -7
  135. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  136. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  137. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  138. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  139. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  140. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  141. data/templates/web/html/layout-html5.html.erb +9 -8
  142. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  143. data/test/assets/header_listener.html +35 -0
  144. data/test/assets/img_math/img1.png +0 -0
  145. data/test/assets/img_math/img2.png +0 -0
  146. data/test/assets/img_math/img3.png +0 -0
  147. data/test/assets/syntax_book_index_detail.txt +58 -0
  148. data/test/assets/test_template.tex +12 -9
  149. data/test/assets/test_template_backmatter.tex +12 -9
  150. data/test/book_test_helper.rb +11 -5
  151. data/test/run_test.rb +1 -1
  152. data/test/test_book.rb +62 -63
  153. data/test/test_book_chapter.rb +99 -56
  154. data/test/test_book_part.rb +3 -3
  155. data/test/test_builder.rb +24 -15
  156. data/test/test_catalog.rb +1 -0
  157. data/test/test_catalog_converter_cmd.rb +1 -1
  158. data/test/test_converter.rb +1 -0
  159. data/test/test_epub3maker.rb +170 -126
  160. data/test/test_epubmaker.rb +249 -129
  161. data/test/test_epubmaker_cmd.rb +14 -7
  162. data/test/test_helper.rb +23 -11
  163. data/test/test_htmlbuilder.rb +956 -76
  164. data/test/test_htmlutils.rb +0 -12
  165. data/test/test_i18n.rb +33 -33
  166. data/test/test_idgxmlbuilder.rb +568 -10
  167. data/test/test_idgxmlmaker_cmd.rb +50 -0
  168. data/test/test_image_finder.rb +52 -70
  169. data/test/test_img_math.rb +111 -0
  170. data/test/test_index.rb +62 -52
  171. data/test/test_indexbuilder.rb +52 -0
  172. data/test/test_latexbuilder.rb +1056 -30
  173. data/test/test_latexbuilder_v2.rb +52 -12
  174. data/test/test_lineinput.rb +20 -93
  175. data/test/test_logger.rb +7 -7
  176. data/test/test_makerhelper.rb +0 -12
  177. data/test/test_markdownbuilder.rb +32 -0
  178. data/test/test_pdfmaker.rb +100 -11
  179. data/test/test_pdfmaker_cmd.rb +101 -7
  180. data/test/test_plaintextbuilder.rb +531 -25
  181. data/test/test_review_ext.rb +2 -1
  182. data/test/test_reviewheaderlistener.rb +49 -0
  183. data/test/test_rstbuilder.rb +25 -1
  184. data/test/test_sec_counter.rb +156 -0
  185. data/test/test_template.rb +12 -2
  186. data/test/test_textmaker_cmd.rb +58 -0
  187. data/test/test_tocprinter.rb +46 -0
  188. data/test/test_topbuilder.rb +365 -10
  189. data/test/test_update.rb +44 -44
  190. data/test/test_webtocprinter.rb +75 -43
  191. data/test/test_zip_exporter.rb +5 -6
  192. data/vendor/gentombow/LICENSE +1 -1
  193. data/vendor/gentombow/Makefile +0 -1
  194. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  195. data/vendor/gentombow/bounddvi-en.tex +1 -0
  196. data/vendor/gentombow/bounddvi.pdf +0 -0
  197. data/vendor/gentombow/bounddvi.sty +30 -7
  198. data/vendor/gentombow/bounddvi.tex +1 -0
  199. data/vendor/gentombow/create_archive.sh +1 -0
  200. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  201. data/vendor/gentombow/gentombow-ja.tex +9 -0
  202. data/vendor/gentombow/gentombow.pdf +0 -0
  203. data/vendor/gentombow/gentombow.sty +32 -10
  204. data/vendor/gentombow/gentombow.tex +8 -0
  205. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  206. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  207. data/vendor/jsclasses/LICENSE +1 -1
  208. data/vendor/jsclasses/Makefile +3 -2
  209. data/vendor/jsclasses/create_archive.sh +5 -5
  210. data/vendor/jsclasses/jis/Makefile +3 -2
  211. data/vendor/jsclasses/jis/jsarticle.cls +74 -31
  212. data/vendor/jsclasses/jis/jsbook.cls +74 -31
  213. data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
  214. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  215. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  216. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  217. data/vendor/jsclasses/jis/jslogo.sty +4 -16
  218. data/vendor/jsclasses/jis/jspf.cls +73 -30
  219. data/vendor/jsclasses/jis/jsreport.cls +74 -31
  220. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  221. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  222. data/vendor/jsclasses/jis/kiyou.cls +74 -31
  223. data/vendor/jsclasses/jis/minijs.sty +65 -22
  224. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  225. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  226. data/vendor/jsclasses/jis/okumacro.sty +4 -17
  227. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  228. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  229. data/vendor/jsclasses/jis/winjis.sty +23 -19
  230. data/vendor/jsclasses/jsarticle.cls +74 -31
  231. data/vendor/jsclasses/jsbook.cls +74 -31
  232. data/vendor/jsclasses/jsclasses.dtx +176 -36
  233. data/vendor/jsclasses/jsclasses.ins +15 -5
  234. data/vendor/jsclasses/jsclasses.pdf +0 -0
  235. data/vendor/jsclasses/jslogo.dtx +4 -4
  236. data/vendor/jsclasses/jslogo.ins +9 -0
  237. data/vendor/jsclasses/jslogo.pdf +0 -0
  238. data/vendor/jsclasses/jslogo.sty +4 -16
  239. data/vendor/jsclasses/jspf.cls +73 -30
  240. data/vendor/jsclasses/jsreport.cls +74 -31
  241. data/vendor/jsclasses/jsverb.ins +9 -0
  242. data/vendor/jsclasses/jsverb.pdf +0 -0
  243. data/vendor/jsclasses/jsverb.sty +1 -13
  244. data/vendor/jsclasses/kiyou.cls +74 -31
  245. data/vendor/jsclasses/minijs.sty +68 -22
  246. data/vendor/jsclasses/okumacro.dtx +4 -5
  247. data/vendor/jsclasses/okumacro.ins +9 -0
  248. data/vendor/jsclasses/okumacro.pdf +0 -0
  249. data/vendor/jsclasses/okumacro.sty +4 -17
  250. data/vendor/jsclasses/okuverb.ins +9 -0
  251. data/vendor/jsclasses/okuverb.pdf +0 -0
  252. data/vendor/jsclasses/okuverb.sty +1 -13
  253. data/vendor/jsclasses/tests/relfont.tex +10 -0
  254. data/vendor/jsclasses/winjis.sty +23 -19
  255. metadata +109 -20
  256. data/.rubocop_todo.yml +0 -7
  257. data/lib/epubmaker.rb +0 -23
  258. data/lib/epubmaker/content.rb +0 -110
  259. data/lib/epubmaker/epubcommon.rb +0 -441
  260. data/lib/epubmaker/epubv2.rb +0 -143
  261. data/lib/epubmaker/epubv3.rb +0 -233
  262. data/lib/epubmaker/producer.rb +0 -375
  263. data/lib/epubmaker/zip_exporter.rb +0 -81
  264. data/lib/lineinput.rb +0 -155
  265. data/lib/review/book/compilable.rb +0 -178
  266. data/lib/review/tocparser.rb +0 -271
  267. data/samples/syntax-book/review-ext.rb +0 -14
  268. data/test/test_tocparser.rb +0 -25
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2019 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.
@@ -78,7 +78,7 @@ module ReVIEW
78
78
 
79
79
  def dd(lines)
80
80
  split_paragraph(lines).each do |paragraph|
81
- puts "\t#{paragraph.gsub(/\n/, '')}"
81
+ puts "\t#{paragraph.delete("\n")}"
82
82
  end
83
83
  end
84
84
 
@@ -95,12 +95,18 @@ module ReVIEW
95
95
  blank
96
96
  puts "◆→開始:#{@titles['list']}←◆"
97
97
  begin
98
- list_header(id, caption, lang)
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
99
107
  rescue KeyError
100
108
  error "no such list: #{id}"
101
109
  end
102
- blank
103
- list_body(id, lines, lang)
104
110
  puts "◆→終了:#{@titles['list']}←◆"
105
111
  blank
106
112
  end
@@ -122,8 +128,13 @@ module ReVIEW
122
128
  def base_block(type, lines, caption = nil)
123
129
  blank
124
130
  puts "◆→開始:#{@titles[type]}←◆"
125
- puts "■#{compile_inline(caption)}" if caption.present?
131
+ if caption_top?('list') && caption.present?
132
+ puts "■#{compile_inline(caption)}"
133
+ end
126
134
  puts lines.join("\n")
135
+ if !caption_top?('list') && caption.present?
136
+ puts "■#{compile_inline(caption)}"
137
+ end
127
138
  puts "◆→終了:#{@titles[type]}←◆"
128
139
  blank
129
140
  end
@@ -140,10 +151,15 @@ module ReVIEW
140
151
  def emlistnum(lines, caption = nil, _lang = nil)
141
152
  blank
142
153
  puts "◆→開始:#{@titles['emlist']}←◆"
143
- puts "■#{compile_inline(caption)}" if caption.present?
154
+ if caption_top?('list') && caption.present?
155
+ puts "■#{compile_inline(caption)}"
156
+ end
144
157
  lines.each_with_index do |line, i|
145
158
  puts((i + 1).to_s.rjust(2) + ": #{line}")
146
159
  end
160
+ if !caption_top?('list') && caption.present?
161
+ puts "■#{compile_inline(caption)}"
162
+ end
147
163
  puts "◆→終了:#{@titles['emlist']}←◆"
148
164
  blank
149
165
  end
@@ -152,12 +168,18 @@ module ReVIEW
152
168
  blank
153
169
  puts "◆→開始:#{@titles['list']}←◆"
154
170
  begin
155
- list_header(id, caption, lang)
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
156
180
  rescue KeyError
157
181
  error "no such list: #{id}"
158
182
  end
159
- blank
160
- listnum_body(lines, lang)
161
183
  puts "◆→終了:#{@titles['list']}←◆"
162
184
  blank
163
185
  end
@@ -173,8 +195,10 @@ module ReVIEW
173
195
  metrics = " #{metrics}" if metrics.present?
174
196
  blank
175
197
  puts "◆→開始:#{@titles['image']}←◆"
176
- image_header(id, caption)
177
- blank
198
+ if caption_top?('image')
199
+ image_header(id, caption)
200
+ blank
201
+ end
178
202
  if @chapter.image_bound?(id)
179
203
  puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
180
204
  else
@@ -183,6 +207,10 @@ module ReVIEW
183
207
  puts line
184
208
  end
185
209
  end
210
+ unless caption_top?('image')
211
+ blank
212
+ image_header(id, caption)
213
+ end
186
214
  puts "◆→終了:#{@titles['image']}←◆"
187
215
  blank
188
216
  end
@@ -198,22 +226,20 @@ module ReVIEW
198
226
  def texequation(lines, id = nil, caption = '')
199
227
  blank
200
228
  puts "◆→開始:#{@titles['texequation']}←◆"
201
- texequation_header(id, caption)
229
+ texequation_header(id, caption) if caption_top?('equation')
202
230
 
203
- if @book.config['imgmath']
231
+ if @book.config['math_format'] == 'imgmath'
204
232
  fontsize = @book.config['imgmath_options']['fontsize'].to_f
205
233
  lineheight = @book.config['imgmath_options']['lineheight'].to_f
206
234
  math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n"
207
235
  key = Digest::SHA256.hexdigest(math_str)
208
- math_dir = File.join(@book.config['imagedir'], '_review_math_text')
209
- Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
210
- img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
211
- defer_math_image(math_str, img_path, key)
236
+ img_path = @img_math.defer_math_image(math_str, key)
212
237
  puts "◆→math:#{File.basename(img_path)}←◆"
213
238
  else
214
239
  puts lines.join("\n")
215
240
  end
216
241
 
242
+ texequation_header(id, caption) unless caption_top?('equation')
217
243
  puts "◆→終了:#{@titles['texequation']}←◆"
218
244
  blank
219
245
  end
@@ -245,6 +271,7 @@ module ReVIEW
245
271
 
246
272
  def comment(lines, comment = nil)
247
273
  return unless @book.config['draft']
274
+
248
275
  lines ||= []
249
276
  unless comment.blank?
250
277
  lines.unshift(comment)
@@ -338,6 +365,18 @@ module ReVIEW
338
365
  "@#{str}@◆→@〜@部分に下線←◆"
339
366
  end
340
367
 
368
+ def inline_ins(str)
369
+ "◆→開始:挿入表現←◆#{str}◆→終了:挿入表現←◆"
370
+ end
371
+
372
+ def inline_del(str)
373
+ "◆→開始:削除表現←◆#{str}◆→終了:削除表現←◆"
374
+ end
375
+
376
+ def inline_tcy(str)
377
+ "◆→開始:回転←◆#{str}◆→終了:縦回転←◆"
378
+ end
379
+
341
380
  def inline_icon(id)
342
381
  begin
343
382
  "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}←◆"
@@ -368,13 +407,10 @@ module ReVIEW
368
407
  end
369
408
 
370
409
  def inline_m(str)
371
- if @book.config['imgmath']
410
+ if @book.config['math_format'] == 'imgmath'
372
411
  math_str = '$' + str + '$'
373
412
  key = Digest::SHA256.hexdigest(str)
374
- math_dir = File.join(@book.config['imagedir'], '_review_math_text')
375
- Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
376
- img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
377
- defer_math_image(math_str, img_path, key)
413
+ img_path = @img_math.defer_math_image(math_str, key)
378
414
  %Q(◆→TeX式ここから←◆◆→math:#{File.basename(img_path)}←◆◆→TeX式ここまで←◆)
379
415
  else
380
416
  %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
@@ -415,17 +451,48 @@ module ReVIEW
415
451
  blank
416
452
  end
417
453
 
454
+ def common_block_begin(type, _level, _label, caption = nil)
455
+ blank
456
+ puts "◆→開始:#{@titles[type]}←◆"
457
+ puts '■' + compile_inline(caption) if caption.present?
458
+ end
459
+
460
+ def common_block_end(type, _level)
461
+ puts "◆→終了:#{@titles[type]}←◆"
462
+ blank
463
+ end
464
+
465
+ CAPTION_TITLES.each do |name|
466
+ class_eval %Q(
467
+ def #{name}_begin(caption = nil)
468
+ check_nested_minicolumn
469
+ @doc_status[:minicolumn] = '#{name}'
470
+ common_block_begin('#{name}', nil, nil, caption)
471
+ end
472
+
473
+ def #{name}_end
474
+ common_block_end('#{name}', nil)
475
+ @doc_status[:minicolumn] = nil
476
+ end
477
+ ), __FILE__, __LINE__ - 11
478
+ end
479
+
418
480
  def indepimage(_lines, id, caption = nil, metric = nil)
419
481
  metrics = parse_metric('top', metric)
420
482
  metrics = " #{metrics}" if metrics.present?
421
483
  blank
484
+ if caption_top?('image') && caption.present?
485
+ puts "図 #{compile_inline(caption)}"
486
+ end
422
487
  begin
423
488
  puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆"
424
489
  rescue
425
490
  warn "image not bound: #{id}"
426
491
  puts "◆→画像 #{id}←◆"
427
492
  end
428
- puts "図 #{compile_inline(caption)}" if caption.present?
493
+ if !caption_top?('image') && caption.present?
494
+ puts "図 #{compile_inline(caption)}"
495
+ end
429
496
  blank
430
497
  end
431
498
 
data/lib/review/update.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2018-2019 Kenshi Muto
2
+ # Copyright (c) 2018-2020 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,7 +20,7 @@ module ReVIEW
20
20
  end
21
21
 
22
22
  # should be
23
- TARGET_VERSION = '4.0'
23
+ TARGET_VERSION = '5.0'
24
24
  EPUB_VERSION = '3'
25
25
  HTML_VERSION = '5'
26
26
  TEX_DOCUMENTCLASS = ['review-jsbook', 'review-jlreq']
@@ -239,7 +239,7 @@ module ReVIEW
239
239
  def update_version
240
240
  @config_ymls.each do |yml|
241
241
  config = YAML.load_file(yml)
242
- if config['review_version'].to_f == TARGET_VERSION.to_f
242
+ if config['review_version'].to_f.round(1) == TARGET_VERSION.to_f.round(1)
243
243
  next
244
244
  end
245
245
 
@@ -301,6 +301,7 @@ module ReVIEW
301
301
  if !config['htmlversion'].present? || config['htmlversion'].to_f >= HTML_VERSION.to_f
302
302
  next
303
303
  end
304
+
304
305
  if confirm("%s: Update '%s' to '%s' from '%s'?", [File.basename(yml), 'htmlversion', HTML_VERSION, config['htmlversion']])
305
306
  rewrite_yml(yml, 'htmlversion', HTML_VERSION)
306
307
  end
@@ -313,6 +314,7 @@ module ReVIEW
313
314
  if !config['chapter_quote'].present? || config['chapter_quote'].scan('%s').size != 1
314
315
  next
315
316
  end
317
+
316
318
  v = config['chapter_quote'].sub('%s', '%s %s')
317
319
  if confirm("%s: 'chapter_quote' now takes 2 values. Update '%s' to '%s'?", [File.basename(yml), config['chapter_quote'], v])
318
320
  rewrite_yml(yml, 'chapter_quote', v)
@@ -414,9 +416,7 @@ module ReVIEW
414
416
  opts << "paper=#{v.sub('j', '').sub('paper', '')}"
415
417
  when /[\d.]+ptj/ # not cared...
416
418
  opts << "fontsize=#{v.sub('j', '')}"
417
- when /[\d.]+pt/
418
- opts << "fontsize=#{v}"
419
- when /[\d.]+Q/
419
+ when /[\d.]+pt/, /[\d.]+Q/
420
420
  opts << "fontsize=#{v}"
421
421
  when 'landscape', 'oneside', 'twoside', 'vartwoside', 'onecolumn',
422
422
  'twocolumn', 'titlepage', 'notitlepage', 'openright',
@@ -442,9 +442,7 @@ module ReVIEW
442
442
  opts << "paper=#{v.sub('j', '').sub('paper', '')}"
443
443
  when /[\d.]+ptj/ # not cared...
444
444
  opts << "fontsize=#{v.sub('j', '')}"
445
- when /[\d.]+pt/
446
- opts << "fontsize=#{v}"
447
- when /[\d.]+Q/
445
+ when /[\d.]+pt/, /[\d.]+Q/
448
446
  opts << "fontsize=#{v}"
449
447
  when 'landscape', 'oneside', 'twoside', 'onecolumn', 'twocolumn', 'titlepage', 'notitlepage', 'openright', 'openany', 'leqno', 'fleqn', 'draft', 'final', 'report'
450
448
  # pass-through
@@ -513,11 +511,12 @@ module ReVIEW
513
511
  def update_tex_command
514
512
  @tex_ymls.each do |yml|
515
513
  config = YAML.load_file(yml)
516
- if !config['texcommand'] || config['texcommand'] !~ /\s+\-/
514
+ if !config['texcommand'] || config['texcommand'] !~ /\s+-/
517
515
  next
518
516
  end
517
+
519
518
  # option should be moved to texoptions
520
- cmd, opts = config['texcommand'].split(/\s+\-/, 2)
519
+ cmd, opts = config['texcommand'].split(/\s+-/, 2)
521
520
  opts = "-#{opts}"
522
521
 
523
522
  unless confirm("%s: 'texcommand' has options ('%s'). Move it to 'texoptions'?", [File.basename(yml), opts])
@@ -537,12 +536,12 @@ module ReVIEW
537
536
  def update_dvi_command
538
537
  @tex_ymls.each do |yml|
539
538
  config = YAML.load_file(yml)
540
- if !config['dvicommand'] || config['dvicommand'] !~ /\s+\-/
539
+ if !config['dvicommand'] || config['dvicommand'] !~ /\s+-/
541
540
  next
542
541
  end
543
542
 
544
543
  # option should be moved to dvioptions
545
- cmd, opts = config['dvicommand'].split(/\s+\-/, 2)
544
+ cmd, opts = config['dvicommand'].split(/\s+-/, 2)
546
545
  opts = "-#{opts}"
547
546
 
548
547
  unless confirm("%s: 'dvicommand' has options ('%s'). Move it to 'dvioptions'?", [File.basename(yml), opts])
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '5.1.1'.freeze
3
3
  end
@@ -0,0 +1,97 @@
1
+ #
2
+ # Copyright (c) 2014-2021 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
+ @yamlfile = 'config.yml'
26
+ end
27
+
28
+ def execute(*args)
29
+ parse_options(args)
30
+ @config = ReVIEW::Configure.create(yamlfile: @yamlfile)
31
+ @book = ReVIEW::Book::Base.new('.', config: @config)
32
+ unless File.readable?(@yamlfile)
33
+ @logger.error("No such fiile or can't open #{@yamlfile}.")
34
+ exit 1
35
+ end
36
+ I18n.setup(@book.config['language'])
37
+
38
+ begin
39
+ @book.each_part do |part|
40
+ if part.number
41
+ print_chapter_volume(part)
42
+ end
43
+ part.each_chapter do |chap|
44
+ print_chapter_volume(chap)
45
+ end
46
+ end
47
+ rescue ReVIEW::FileNotFound, ReVIEW::CompileError, ReVIEW::ApplicationError => e
48
+ @logger.error e.message
49
+ exit 1
50
+ end
51
+ puts '============================='
52
+ print_volume(@book.volume)
53
+ end
54
+
55
+ def parse_options(args)
56
+ opts = OptionParser.new
57
+ opts.version = ReVIEW::VERSION
58
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @yamlfile = yaml }
59
+ opts.on('--help', 'Print this message and quit') do
60
+ puts opts.help
61
+ exit 0
62
+ end
63
+ begin
64
+ opts.parse!(args)
65
+ rescue OptionParser::ParseError => e
66
+ @logger.error e.message
67
+ $stderr.puts opts.help
68
+ exit 1
69
+ end
70
+ end
71
+
72
+ def print_chapter_volume(chap)
73
+ builder = ReVIEW::PLAINTEXTBuilder.new
74
+ builder.bind(ReVIEW::Compiler.new(builder), chap, nil)
75
+
76
+ vol = chap.volume
77
+ title = chap.format_number
78
+ unless title.empty?
79
+ title += ' '
80
+ end
81
+ begin
82
+ title += builder.compile_inline(chap.title)
83
+ rescue ReVIEW::ApplicationError => e
84
+ @logger.warn "#{chap.name} : #{e.message.sub(/.+error: /, '')}"
85
+ end
86
+
87
+ printf("%3dKB %6dC %5dL %3dP %s %-s\n",
88
+ vol.kbytes, vol.chars, vol.lines, vol.page,
89
+ "#{chap.name} ".ljust(15, '.'), title)
90
+ end
91
+
92
+ def print_volume(vol)
93
+ # total
94
+ printf("%3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page)
95
+ end
96
+ end
97
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2018 Masayoshi Takahashi, Masanori Kado, Kenshi Muto
1
+ # Copyright (c) 2016-2021 Masayoshi Takahashi, Masanori Kado, Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -19,8 +19,8 @@ require 'review/yamlloader'
19
19
  require 'review/template'
20
20
  require 'review/tocprinter'
21
21
  require 'review/version'
22
- require 'erb'
23
22
  require 'review/makerhelper'
23
+ require 'review/img_math'
24
24
 
25
25
  module ReVIEW
26
26
  class WEBMaker
@@ -32,6 +32,7 @@ module ReVIEW
32
32
  def initialize
33
33
  @basedir = nil
34
34
  @logger = ReVIEW.logger
35
+ @img_math = nil
35
36
  end
36
37
 
37
38
  def error(msg)
@@ -50,6 +51,7 @@ module ReVIEW
50
51
  def parse_opts(args)
51
52
  cmd_config = {}
52
53
  opts = OptionParser.new
54
+ @buildonly = nil
53
55
 
54
56
  opts.banner = 'Usage: review-webmaker [option] configfile'
55
57
  opts.version = ReVIEW::VERSION
@@ -58,6 +60,7 @@ module ReVIEW
58
60
  exit 0
59
61
  end
60
62
  opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true }
63
+ opts.on('-y', '--only file1,file2,...', 'Build only specified files.') { |v| @buildonly = v.split(/\s*,\s*/).map { |m| m.strip.sub(/\.re\Z/, '') } }
61
64
 
62
65
  opts.parse!(args)
63
66
  if args.size != 1
@@ -73,30 +76,28 @@ module ReVIEW
73
76
  end
74
77
 
75
78
  def remove_old_files(path)
76
- cleanup_mathimg
79
+ @img_math.cleanup_mathimg
77
80
  FileUtils.rm_rf(path)
78
81
  end
79
82
 
80
83
  def execute(*args)
81
- @config = ReVIEW::Configure.values
82
- @config.maker = 'webmaker'
83
84
  cmd_config, yamlfile = parse_opts(args)
84
85
  error "#{yamlfile} not found." unless File.exist?(yamlfile)
85
86
 
86
- begin
87
- loader = ReVIEW::YAMLLoader.new
88
- @config.deep_merge!(loader.load_file(yamlfile))
89
- rescue => e
90
- error "yaml error #{e.message}"
91
- end
92
- # YAML configs will be overridden by command line options.
93
- @config.deep_merge!(cmd_config)
87
+ @config = ReVIEW::Configure.create(maker: 'webmaker',
88
+ yamlfile: yamlfile,
89
+ config: cmd_config)
90
+
94
91
  @config['htmlext'] = 'html'
92
+ @img_math = ReVIEW::ImgMath.new(@config)
93
+
95
94
  I18n.setup(@config['language'])
96
95
  begin
97
96
  generate_html_files(yamlfile)
97
+ @logger.success("built #{build_path}")
98
98
  rescue ApplicationError => e
99
99
  raise if @config['debug']
100
+
100
101
  error(e.message)
101
102
  end
102
103
  end
@@ -107,17 +108,16 @@ module ReVIEW
107
108
  remove_old_files(@path)
108
109
  Dir.mkdir(@path)
109
110
 
110
- @book = ReVIEW::Book.load(@basedir)
111
- @book.config = @config
111
+ @book = ReVIEW::Book::Base.new(@basedir, config: @config)
112
+ @converter = ReVIEW::Converter.new(@book, ReVIEW::HTMLBuilder.new(img_math: @img_math))
112
113
 
113
114
  copy_stylesheet(@path)
114
115
  copy_frontmatter(@path)
115
116
  build_body(@path, yamlfile)
116
117
  copy_backmatter(@path)
117
118
 
118
- math_dir = "./#{@config['imagedir']}/_review_math"
119
- if @config['imgmath'] && File.exist?("#{math_dir}/__IMGMATH_BODY__.tex")
120
- make_math_images(math_dir)
119
+ if @config['math_format'] == 'imgmath'
120
+ @img_math.make_math_images
121
121
  end
122
122
 
123
123
  copy_images(@config['imagedir'], "#{@path}/#{@config['imagedir']}")
@@ -127,16 +127,8 @@ module ReVIEW
127
127
  copy_resources(@config['fontdir'], "#{@path}/fonts", @config['font_ext'])
128
128
  end
129
129
 
130
- def clean_mathdir
131
- if @config['imgmath'] && File.exist?("#{@config['imagedir']}/_review_math")
132
- FileUtils.rm_rf("#{@config['imagedir']}/_review_math")
133
- end
134
- end
135
-
136
130
  def build_body(basetmpdir, _yamlfile)
137
131
  base_path = Pathname.new(@basedir)
138
- builder = ReVIEW::HTMLBuilder.new
139
- @converter = ReVIEW::Converter.new(@book, builder)
140
132
  @book.parts.each do |part|
141
133
  if part.name.present?
142
134
  if part.file?
@@ -154,6 +146,7 @@ module ReVIEW
154
146
  end
155
147
 
156
148
  def build_part(part, basetmpdir, htmlfile)
149
+ @title = h("#{ReVIEW::I18n.t('part', part.number)} #{part.name.strip}")
157
150
  File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
158
151
  @body = ''
159
152
  @body << %Q(<div class="part">\n)
@@ -163,8 +156,7 @@ module ReVIEW
163
156
 
164
157
  @language = @config['language']
165
158
  @stylesheets = @config['stylesheet']
166
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
167
- f.write ReVIEW::Template.load(tmplfile).result(binding)
159
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
168
160
  end
169
161
  end
170
162
 
@@ -186,6 +178,11 @@ module ReVIEW
186
178
  end
187
179
  id = File.basename(filename).sub(/\.re\Z/, '')
188
180
 
181
+ if @buildonly && !@buildonly.include?(id)
182
+ warn "skip #{id}.re"
183
+ return
184
+ end
185
+
189
186
  htmlfile = "#{id}.#{@config['htmlext']}"
190
187
 
191
188
  if @config['params'].present?
@@ -202,6 +199,7 @@ module ReVIEW
202
199
 
203
200
  def copy_images(resdir, destdir)
204
201
  return nil unless File.exist?(resdir)
202
+
205
203
  allow_exts = @config['image_ext']
206
204
  FileUtils.mkdir_p(destdir)
207
205
  recursive_copy_files(resdir, destdir, allow_exts)
@@ -209,6 +207,7 @@ module ReVIEW
209
207
 
210
208
  def copy_resources(resdir, destdir, allow_exts = nil)
211
209
  return nil if !resdir || !File.exist?(resdir)
210
+
212
211
  allow_exts ||= @config['image_ext']
213
212
  FileUtils.mkdir_p(destdir)
214
213
  recursive_copy_files(resdir, destdir, allow_exts)
@@ -218,6 +217,7 @@ module ReVIEW
218
217
  Dir.open(resdir) do |dir|
219
218
  dir.each do |fname|
220
219
  next if fname.start_with?('.')
220
+
221
221
  if FileTest.directory?("#{resdir}/#{fname}")
222
222
  recursive_copy_files("#{resdir}/#{fname}", "#{destdir}/#{fname}", allow_exts)
223
223
  elsif fname =~ /\.(#{allow_exts.join('|')})\Z/i
@@ -252,6 +252,7 @@ module ReVIEW
252
252
  end
253
253
 
254
254
  def build_indexpage(basetmpdir)
255
+ @title = h('index')
255
256
  File.open("#{basetmpdir}/index.html", 'w') do |f|
256
257
  if @config['coverimage']
257
258
  file = File.join(@config['imagedir'], @config['coverimage'])
@@ -268,16 +269,16 @@ module ReVIEW
268
269
  @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
269
270
  @next = @book.chapters[0]
270
271
  @next_title = @next ? @next.title : ''
271
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
272
- f.write ReVIEW::Template.load(tmplfile).result(binding)
272
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
273
273
  end
274
274
  end
275
275
 
276
276
  def build_titlepage(basetmpdir, htmlfile)
277
+ @title = h('titlepage')
277
278
  File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
278
279
  @body = ''
279
280
  @body << %Q(<div class="titlepage">)
280
- @body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>)
281
+ @body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>)
281
282
  if @config['aut']
282
283
  @body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>)
283
284
  end
@@ -288,8 +289,7 @@ module ReVIEW
288
289
 
289
290
  @language = @config['language']
290
291
  @stylesheets = @config['stylesheet']
291
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
292
- f.write ReVIEW::Template.load(tmplfile).result(binding)
292
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
293
293
  end
294
294
  end
295
295
 
@@ -304,6 +304,7 @@ module ReVIEW
304
304
 
305
305
  def copy_file_with_param(name, target_file = nil)
306
306
  return if @config[name].nil? || !File.exist?(@config[name])
307
+
307
308
  target_file ||= File.basename(@config[name])
308
309
  FileUtils.cp(@config[name], File.join(@path, target_file))
309
310
  end