review 4.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +35 -0
  3. data/.github/workflows/ruby-win.yml +19 -9
  4. data/.github/workflows/ruby.yml +7 -3
  5. data/.rubocop.yml +138 -34
  6. data/NEWS.ja.md +285 -0
  7. data/NEWS.md +285 -1
  8. data/README.md +7 -6
  9. data/Rakefile +7 -2
  10. data/bin/review +2 -4
  11. data/bin/review-catalog-converter +4 -4
  12. data/bin/review-check +8 -12
  13. data/bin/review-checkdep +2 -5
  14. data/bin/review-compile +18 -34
  15. data/bin/review-epub2html +1 -4
  16. data/bin/review-epubmaker +3 -4
  17. data/bin/review-idgxmlmaker +1 -3
  18. data/bin/review-index +5 -86
  19. data/bin/review-init +1 -4
  20. data/bin/review-pdfmaker +1 -3
  21. data/bin/review-preproc +30 -38
  22. data/bin/review-textmaker +1 -3
  23. data/bin/review-update +1 -4
  24. data/bin/review-validate +4 -4
  25. data/bin/review-vol +5 -82
  26. data/bin/review-webmaker +1 -3
  27. data/doc/config.yml.sample +45 -11
  28. data/doc/config.yml.sample-simple +3 -3
  29. data/doc/format.ja.md +103 -13
  30. data/doc/format.md +104 -16
  31. data/doc/makeindex.ja.md +2 -2
  32. data/doc/pdfmaker.ja.md +42 -0
  33. data/doc/pdfmaker.md +41 -0
  34. data/doc/quickstart.ja.md +19 -6
  35. data/doc/quickstart.md +18 -6
  36. data/doc/writing_vertical.ja.md +6 -0
  37. data/lib/review.rb +1 -1
  38. data/lib/review/book.rb +2 -2
  39. data/lib/review/book/base.rb +67 -29
  40. data/lib/review/book/bib.rb +21 -0
  41. data/lib/review/book/book_unit.rb +158 -0
  42. data/lib/review/book/chapter.rb +33 -26
  43. data/lib/review/book/index.rb +24 -185
  44. data/lib/review/book/index/item.rb +7 -1
  45. data/lib/review/book/page_metric.rb +7 -7
  46. data/lib/review/book/part.rb +26 -11
  47. data/lib/review/book/volume.rb +5 -5
  48. data/lib/review/builder.rb +121 -52
  49. data/lib/review/call_hook.rb +20 -0
  50. data/lib/review/catalog.rb +3 -2
  51. data/lib/review/compiler.rb +230 -111
  52. data/lib/review/configure.rb +91 -7
  53. data/lib/review/converter.rb +1 -1
  54. data/lib/review/epub2html.rb +6 -1
  55. data/lib/review/epubmaker.rb +124 -152
  56. data/lib/review/epubmaker/content.rb +113 -0
  57. data/lib/review/epubmaker/epubcommon.rb +372 -0
  58. data/lib/review/epubmaker/epubv2.rb +178 -0
  59. data/lib/review/epubmaker/epubv3.rb +231 -0
  60. data/lib/review/epubmaker/producer.rb +167 -0
  61. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  62. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  63. data/lib/review/exception.rb +13 -0
  64. data/lib/review/htmlbuilder.rb +176 -89
  65. data/lib/review/htmlutils.rb +8 -11
  66. data/lib/review/i18n.rb +2 -1
  67. data/lib/review/idgxmlbuilder.rb +165 -75
  68. data/lib/review/idgxmlmaker.rb +24 -28
  69. data/lib/review/img_math.rb +238 -0
  70. data/lib/review/index_builder.rb +645 -0
  71. data/lib/review/init.rb +9 -17
  72. data/lib/review/latexbox.rb +58 -0
  73. data/lib/review/latexbuilder.rb +193 -75
  74. data/lib/review/latexutils.rb +9 -1
  75. data/lib/review/lineinput.rb +112 -2
  76. data/lib/review/loggable.rb +27 -0
  77. data/lib/review/logger.rb +90 -3
  78. data/lib/review/makerhelper.rb +17 -188
  79. data/lib/review/markdownbuilder.rb +54 -4
  80. data/lib/review/pdfmaker.rb +76 -84
  81. data/lib/review/plaintextbuilder.rb +106 -22
  82. data/lib/review/preprocessor.rb +107 -303
  83. data/lib/review/preprocessor/directive.rb +35 -0
  84. data/lib/review/preprocessor/line.rb +34 -0
  85. data/lib/review/preprocessor/repository.rb +177 -0
  86. data/lib/review/rstbuilder.rb +27 -8
  87. data/lib/review/sec_counter.rb +14 -0
  88. data/lib/review/template.rb +11 -1
  89. data/lib/review/textmaker.rb +27 -32
  90. data/lib/review/textutils.rb +3 -12
  91. data/lib/review/tocprinter.rb +242 -97
  92. data/lib/review/topbuilder.rb +98 -31
  93. data/lib/review/update.rb +12 -13
  94. data/lib/review/version.rb +1 -1
  95. data/lib/review/volumeprinter.rb +97 -0
  96. data/lib/review/webmaker.rb +40 -47
  97. data/lib/review/webtocprinter.rb +39 -35
  98. data/lib/review/yamlloader.rb +2 -1
  99. data/review.gemspec +5 -3
  100. data/samples/sample-book/src/config-epub2.yml +1 -1
  101. data/samples/sample-book/src/config.yml +3 -3
  102. data/samples/sample-book/src/lib/tasks/review.rake +19 -1
  103. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  104. data/samples/syntax-book/Gemfile +1 -1
  105. data/samples/syntax-book/ch01.re +1 -1
  106. data/samples/syntax-book/ch02.re +21 -6
  107. data/samples/syntax-book/ch03.re +1 -1
  108. data/samples/syntax-book/config.yml +1 -1
  109. data/samples/syntax-book/images/img3-2.png +0 -0
  110. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  111. data/templates/html/_colophon.html.erb +23 -0
  112. data/templates/html/_colophon_history.html.erb +9 -0
  113. data/templates/html/_cover.html.erb +10 -0
  114. data/templates/html/_part_body.html.erb +6 -0
  115. data/templates/html/_titlepage.html.erb +20 -0
  116. data/templates/html/layout-html5.html.erb +6 -0
  117. data/templates/html/layout-xhtml1.html.erb +6 -0
  118. data/templates/latex/config.erb +35 -23
  119. data/templates/latex/review-jlreq/README.md +3 -1
  120. data/templates/latex/review-jlreq/review-base.sty +36 -23
  121. data/templates/latex/review-jlreq/review-jlreq.cls +18 -25
  122. data/templates/latex/review-jlreq/review-style.sty +6 -1
  123. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  124. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  125. data/templates/latex/review-jsbook/README.md +7 -5
  126. data/templates/latex/review-jsbook/review-base.sty +40 -24
  127. data/templates/latex/review-jsbook/review-jsbook.cls +13 -3
  128. data/templates/latex/review-jsbook/review-style.sty +6 -1
  129. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  130. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  131. data/templates/opf/epubv2.opf.erb +7 -7
  132. data/templates/opf/epubv3.opf.erb +7 -7
  133. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  134. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  135. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  136. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  137. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  138. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  139. data/templates/web/html/layout-html5.html.erb +9 -8
  140. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  141. data/test/assets/header_listener.html +35 -0
  142. data/test/assets/img_math/img1.png +0 -0
  143. data/test/assets/img_math/img2.png +0 -0
  144. data/test/assets/img_math/img3.png +0 -0
  145. data/test/assets/syntax_book_index_detail.txt +58 -0
  146. data/test/assets/test_template.tex +6 -3
  147. data/test/assets/test_template_backmatter.tex +6 -3
  148. data/test/book_test_helper.rb +11 -5
  149. data/test/run_test.rb +1 -1
  150. data/test/test_book.rb +54 -63
  151. data/test/test_book_chapter.rb +95 -54
  152. data/test/test_book_part.rb +3 -3
  153. data/test/test_builder.rb +29 -20
  154. data/test/test_catalog_converter_cmd.rb +1 -1
  155. data/test/test_converter.rb +1 -0
  156. data/test/test_epub3maker.rb +170 -126
  157. data/test/test_epubmaker.rb +254 -129
  158. data/test/test_epubmaker_cmd.rb +15 -4
  159. data/test/test_helper.rb +12 -5
  160. data/test/test_htmlbuilder.rb +926 -76
  161. data/test/test_htmlutils.rb +0 -12
  162. data/test/test_i18n.rb +33 -33
  163. data/test/test_idgxmlbuilder.rb +531 -20
  164. data/test/test_idgxmlmaker_cmd.rb +7 -3
  165. data/test/test_img_math.rb +111 -0
  166. data/test/test_index.rb +62 -52
  167. data/test/test_indexbuilder.rb +52 -0
  168. data/test/test_latexbuilder.rb +891 -20
  169. data/test/test_latexbuilder_v2.rb +56 -10
  170. data/test/test_lineinput.rb +20 -93
  171. data/test/test_logger.rb +7 -7
  172. data/test/test_makerhelper.rb +0 -12
  173. data/test/test_markdownbuilder.rb +32 -0
  174. data/test/test_pdfmaker.rb +100 -11
  175. data/test/test_pdfmaker_cmd.rb +3 -3
  176. data/test/test_plaintextbuilder.rb +546 -32
  177. data/test/test_preprocessor.rb +188 -1
  178. data/test/test_review_ext.rb +2 -1
  179. data/test/test_reviewheaderlistener.rb +49 -0
  180. data/test/test_rstbuilder.rb +25 -1
  181. data/test/test_sec_counter.rb +156 -0
  182. data/test/test_template.rb +12 -2
  183. data/test/test_textmaker_cmd.rb +5 -1
  184. data/test/test_tocprinter.rb +46 -0
  185. data/test/test_topbuilder.rb +324 -20
  186. data/test/test_update.rb +44 -44
  187. data/test/test_webtocprinter.rb +75 -43
  188. data/test/test_zip_exporter.rb +5 -6
  189. data/vendor/gentombow/LICENSE +1 -1
  190. data/vendor/gentombow/Makefile +0 -1
  191. data/vendor/gentombow/bounddvi-en.pdf +0 -0
  192. data/vendor/gentombow/bounddvi-en.tex +1 -0
  193. data/vendor/gentombow/bounddvi.pdf +0 -0
  194. data/vendor/gentombow/bounddvi.sty +30 -7
  195. data/vendor/gentombow/bounddvi.tex +1 -0
  196. data/vendor/gentombow/create_archive.sh +1 -0
  197. data/vendor/gentombow/gentombow-ja.pdf +0 -0
  198. data/vendor/gentombow/gentombow-ja.tex +9 -0
  199. data/vendor/gentombow/gentombow.pdf +0 -0
  200. data/vendor/gentombow/gentombow.sty +32 -10
  201. data/vendor/gentombow/gentombow.tex +8 -0
  202. data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
  203. data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
  204. data/vendor/jsclasses/Makefile +3 -2
  205. data/vendor/jsclasses/create_archive.sh +5 -5
  206. data/vendor/jsclasses/jis/Makefile +3 -2
  207. data/vendor/jsclasses/jis/jsarticle.cls +22 -18
  208. data/vendor/jsclasses/jis/jsbook.cls +22 -18
  209. data/vendor/jsclasses/jis/jsclasses.dtx +94 -13
  210. data/vendor/jsclasses/jis/jsclasses.ins +15 -5
  211. data/vendor/jsclasses/jis/jslogo.ins +9 -0
  212. data/vendor/jsclasses/jis/jslogo.sty +1 -13
  213. data/vendor/jsclasses/jis/jspf.cls +22 -18
  214. data/vendor/jsclasses/jis/jsreport.cls +22 -18
  215. data/vendor/jsclasses/jis/jsverb.ins +9 -0
  216. data/vendor/jsclasses/jis/jsverb.sty +1 -13
  217. data/vendor/jsclasses/jis/kiyou.cls +22 -18
  218. data/vendor/jsclasses/jis/minijs.sty +65 -22
  219. data/vendor/jsclasses/jis/okumacro.ins +9 -0
  220. data/vendor/jsclasses/jis/okumacro.sty +1 -13
  221. data/vendor/jsclasses/jis/okuverb.ins +9 -0
  222. data/vendor/jsclasses/jis/okuverb.sty +1 -13
  223. data/vendor/jsclasses/jis/winjis.sty +23 -19
  224. data/vendor/jsclasses/jsarticle.cls +22 -18
  225. data/vendor/jsclasses/jsbook.cls +22 -18
  226. data/vendor/jsclasses/jsclasses.dtx +94 -13
  227. data/vendor/jsclasses/jsclasses.ins +15 -5
  228. data/vendor/jsclasses/jsclasses.pdf +0 -0
  229. data/vendor/jsclasses/jslogo.ins +9 -0
  230. data/vendor/jsclasses/jslogo.pdf +0 -0
  231. data/vendor/jsclasses/jslogo.sty +1 -13
  232. data/vendor/jsclasses/jspf.cls +22 -18
  233. data/vendor/jsclasses/jsreport.cls +22 -18
  234. data/vendor/jsclasses/jsverb.ins +9 -0
  235. data/vendor/jsclasses/jsverb.pdf +0 -0
  236. data/vendor/jsclasses/jsverb.sty +1 -13
  237. data/vendor/jsclasses/kiyou.cls +22 -18
  238. data/vendor/jsclasses/minijs.sty +68 -22
  239. data/vendor/jsclasses/okumacro.ins +9 -0
  240. data/vendor/jsclasses/okumacro.pdf +0 -0
  241. data/vendor/jsclasses/okumacro.sty +1 -13
  242. data/vendor/jsclasses/okuverb.ins +9 -0
  243. data/vendor/jsclasses/okuverb.pdf +0 -0
  244. data/vendor/jsclasses/okuverb.sty +1 -13
  245. data/vendor/jsclasses/tests/relfont.tex +10 -0
  246. data/vendor/jsclasses/winjis.sty +23 -19
  247. metadata +106 -22
  248. data/.rubocop_todo.yml +0 -7
  249. data/lib/epubmaker.rb +0 -23
  250. data/lib/epubmaker/content.rb +0 -110
  251. data/lib/epubmaker/epubcommon.rb +0 -441
  252. data/lib/epubmaker/epubv2.rb +0 -143
  253. data/lib/epubmaker/epubv3.rb +0 -233
  254. data/lib/epubmaker/producer.rb +0 -375
  255. data/lib/epubmaker/zip_exporter.rb +0 -81
  256. data/lib/lineinput.rb +0 -155
  257. data/lib/review/book/compilable.rb +0 -178
  258. data/lib/review/tocparser.rb +0 -275
  259. data/test/test_tocparser.rb +0 -25
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.1.0'.freeze
2
+ VERSION = '5.2.0'.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-2020 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,28 +19,23 @@ 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
+ require 'review/loggable'
24
25
 
25
26
  module ReVIEW
26
27
  class WEBMaker
27
28
  include ERB::Util
28
29
  include MakerHelper
30
+ include Loggable
29
31
 
30
32
  attr_accessor :config, :basedir
31
33
 
32
34
  def initialize
33
35
  @basedir = nil
34
36
  @logger = ReVIEW.logger
35
- end
36
-
37
- def error(msg)
38
- @logger.error msg
39
- exit 1
40
- end
41
-
42
- def warn(msg)
43
- @logger.warn msg
37
+ @img_math = nil
38
+ @compile_errors = nil
44
39
  end
45
40
 
46
41
  def self.execute(*args)
@@ -75,31 +70,29 @@ module ReVIEW
75
70
  end
76
71
 
77
72
  def remove_old_files(path)
78
- cleanup_mathimg
73
+ @img_math.cleanup_mathimg
79
74
  FileUtils.rm_rf(path)
80
75
  end
81
76
 
82
77
  def execute(*args)
83
- @config = ReVIEW::Configure.values
84
- @config.maker = 'webmaker'
85
78
  cmd_config, yamlfile = parse_opts(args)
86
- error "#{yamlfile} not found." unless File.exist?(yamlfile)
79
+ error! "#{yamlfile} not found." unless File.exist?(yamlfile)
80
+
81
+ @config = ReVIEW::Configure.create(maker: 'webmaker',
82
+ yamlfile: yamlfile,
83
+ config: cmd_config)
87
84
 
88
- begin
89
- loader = ReVIEW::YAMLLoader.new
90
- @config.deep_merge!(loader.load_file(yamlfile))
91
- rescue => e
92
- error "yaml error #{e.message}"
93
- end
94
- # YAML configs will be overridden by command line options.
95
- @config.deep_merge!(cmd_config)
96
85
  @config['htmlext'] = 'html'
86
+ @img_math = ReVIEW::ImgMath.new(@config)
87
+
97
88
  I18n.setup(@config['language'])
98
89
  begin
99
90
  generate_html_files(yamlfile)
91
+ @logger.success("built #{build_path}")
100
92
  rescue ApplicationError => e
101
93
  raise if @config['debug']
102
- error(e.message)
94
+
95
+ error! e.message
103
96
  end
104
97
  end
105
98
 
@@ -109,17 +102,16 @@ module ReVIEW
109
102
  remove_old_files(@path)
110
103
  Dir.mkdir(@path)
111
104
 
112
- @book = ReVIEW::Book.load(@basedir)
113
- @book.config = @config
105
+ @book = ReVIEW::Book::Base.new(@basedir, config: @config)
106
+ @converter = ReVIEW::Converter.new(@book, ReVIEW::HTMLBuilder.new(img_math: @img_math))
114
107
 
115
108
  copy_stylesheet(@path)
116
109
  copy_frontmatter(@path)
117
110
  build_body(@path, yamlfile)
118
111
  copy_backmatter(@path)
119
112
 
120
- math_dir = "./#{@config['imagedir']}/_review_math"
121
- if @config['imgmath'] && File.exist?("#{math_dir}/__IMGMATH_BODY__.tex")
122
- make_math_images(math_dir)
113
+ if @config['math_format'] == 'imgmath'
114
+ @img_math.make_math_images
123
115
  end
124
116
 
125
117
  copy_images(@config['imagedir'], "#{@path}/#{@config['imagedir']}")
@@ -129,16 +121,9 @@ module ReVIEW
129
121
  copy_resources(@config['fontdir'], "#{@path}/fonts", @config['font_ext'])
130
122
  end
131
123
 
132
- def clean_mathdir
133
- if @config['imgmath'] && File.exist?("#{@config['imagedir']}/_review_math")
134
- FileUtils.rm_rf("#{@config['imagedir']}/_review_math")
135
- end
136
- end
137
-
138
124
  def build_body(basetmpdir, _yamlfile)
139
125
  base_path = Pathname.new(@basedir)
140
- builder = ReVIEW::HTMLBuilder.new
141
- @converter = ReVIEW::Converter.new(@book, builder)
126
+ @compile_errors = nil
142
127
  @book.parts.each do |part|
143
128
  if part.name.present?
144
129
  if part.file?
@@ -153,9 +138,13 @@ module ReVIEW
153
138
 
154
139
  part.chapters.each { |chap| build_chap(chap, base_path, basetmpdir, false) }
155
140
  end
141
+ if @compile_errors
142
+ app_error 'compile error, No web files output.'
143
+ end
156
144
  end
157
145
 
158
146
  def build_part(part, basetmpdir, htmlfile)
147
+ @title = h("#{ReVIEW::I18n.t('part', part.number)} #{part.name.strip}")
159
148
  File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
160
149
  @body = ''
161
150
  @body << %Q(<div class="part">\n)
@@ -165,8 +154,7 @@ module ReVIEW
165
154
 
166
155
  @language = @config['language']
167
156
  @stylesheets = @config['stylesheet']
168
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
169
- f.write ReVIEW::Template.load(tmplfile).result(binding)
157
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
170
158
  end
171
159
  end
172
160
 
@@ -201,14 +189,16 @@ module ReVIEW
201
189
 
202
190
  begin
203
191
  @converter.convert(filename, File.join(basetmpdir, htmlfile))
204
- rescue => e
205
- warn "compile error in #{filename} (#{e.class})"
206
- warn e.message
192
+ rescue ApplicationError => e
193
+ @compile_errors = true
194
+ error "compile error in #{filename} (#{e.class})"
195
+ error e.message
207
196
  end
208
197
  end
209
198
 
210
199
  def copy_images(resdir, destdir)
211
200
  return nil unless File.exist?(resdir)
201
+
212
202
  allow_exts = @config['image_ext']
213
203
  FileUtils.mkdir_p(destdir)
214
204
  recursive_copy_files(resdir, destdir, allow_exts)
@@ -216,6 +206,7 @@ module ReVIEW
216
206
 
217
207
  def copy_resources(resdir, destdir, allow_exts = nil)
218
208
  return nil if !resdir || !File.exist?(resdir)
209
+
219
210
  allow_exts ||= @config['image_ext']
220
211
  FileUtils.mkdir_p(destdir)
221
212
  recursive_copy_files(resdir, destdir, allow_exts)
@@ -225,6 +216,7 @@ module ReVIEW
225
216
  Dir.open(resdir) do |dir|
226
217
  dir.each do |fname|
227
218
  next if fname.start_with?('.')
219
+
228
220
  if FileTest.directory?("#{resdir}/#{fname}")
229
221
  recursive_copy_files("#{resdir}/#{fname}", "#{destdir}/#{fname}", allow_exts)
230
222
  elsif fname =~ /\.(#{allow_exts.join('|')})\Z/i
@@ -259,6 +251,7 @@ module ReVIEW
259
251
  end
260
252
 
261
253
  def build_indexpage(basetmpdir)
254
+ @title = h('index')
262
255
  File.open("#{basetmpdir}/index.html", 'w') do |f|
263
256
  if @config['coverimage']
264
257
  file = File.join(@config['imagedir'], @config['coverimage'])
@@ -275,16 +268,16 @@ module ReVIEW
275
268
  @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
276
269
  @next = @book.chapters[0]
277
270
  @next_title = @next ? @next.title : ''
278
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
279
- f.write ReVIEW::Template.load(tmplfile).result(binding)
271
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
280
272
  end
281
273
  end
282
274
 
283
275
  def build_titlepage(basetmpdir, htmlfile)
276
+ @title = h('titlepage')
284
277
  File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
285
278
  @body = ''
286
279
  @body << %Q(<div class="titlepage">)
287
- @body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>)
280
+ @body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>)
288
281
  if @config['aut']
289
282
  @body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>)
290
283
  end
@@ -295,8 +288,7 @@ module ReVIEW
295
288
 
296
289
  @language = @config['language']
297
290
  @stylesheets = @config['stylesheet']
298
- tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
299
- f.write ReVIEW::Template.load(tmplfile).result(binding)
291
+ f.write ReVIEW::Template.generate(path: template_name, binding: binding)
300
292
  end
301
293
  end
302
294
 
@@ -311,6 +303,7 @@ module ReVIEW
311
303
 
312
304
  def copy_file_with_param(name, target_file = nil)
313
305
  return if @config[name].nil? || !File.exist?(@config[name])
306
+
314
307
  target_file ||= File.basename(@config[name])
315
308
  FileUtils.cp(@config[name], File.join(@path, target_file))
316
309
  end
@@ -1,54 +1,58 @@
1
1
  require 'review/tocprinter'
2
2
  require 'review/i18n'
3
+ require 'review/htmlutils'
3
4
 
4
5
  module ReVIEW
5
6
  class WEBTOCPrinter < TOCPrinter
6
7
  include HTMLUtils
7
8
 
8
9
  def self.book_to_string(book)
9
- io = StringIO.new
10
- ReVIEW::WEBTOCPrinter.new(1, {}, io).print_book(book)
11
- io.seek(0)
12
- io.read
10
+ ReVIEW::WEBTOCPrinter.new.print_book(book)
13
11
  end
14
12
 
15
13
  def print_book(book)
16
- @out.puts '<ul class="book-toc">'
17
- @out.puts %Q(<li><a href="index.html">TOP</a></li>\n)
18
- book.each_part do |part|
19
- print_part(part)
20
- end
21
- @out.puts '</ul>'
14
+ @book = book
15
+ @indent = nil
16
+ @upper = 1 # only part and chapter
17
+ print_result(build_result_array)
22
18
  end
23
19
 
24
- def print_part(part)
25
- if part.number
26
- if part.file?
27
- ext = part.book.config['htmlext'] || 'html'
28
- path = File.basename(part.path.sub(/\.re/, '.' + ext))
29
- @out.puts %Q(<li><a href="#{path}">#{h(I18n.t('part_short', part.number) + ' ' + part.title)}</a>\n<ul>\n)
20
+ def print_result(result_array)
21
+ content = <<EOT
22
+ <ul class="book-toc">
23
+ <li><a href="index.html">TOP</a></li>
24
+ EOT
25
+
26
+ path = ''
27
+ result_array.each do |result|
28
+ unless result.headline
29
+ result.headline = '-'
30
+ end
31
+
32
+ if result.name
33
+ path = "#{result.name}.#{@book.config['htmlext']}"
34
+ next
35
+ end
36
+
37
+ if result.part
38
+ if result.part == 'end'
39
+ content << "</ul></li>\n"
40
+ end
41
+ next
42
+ end
43
+
44
+ if path.start_with?('.')
45
+ content << "<li>#{escape(result.headline)}"
30
46
  else
31
- @out.puts %Q(<li>#{h(I18n.t('part_short', part.number) + ' ' + part.title)}\n<ul>\n)
47
+ content << %Q(<li><a href="#{path}">#{escape(result.headline)}</a>)
48
+ end
49
+ if result.level == 0
50
+ content << "\n<ul>" # part
51
+ else
52
+ content << "</li>\n"
32
53
  end
33
54
  end
34
- part.each_chapter do |chap|
35
- print_chapter(chap)
36
- end
37
- if part.number
38
- @out.puts "</ul>\n</li>\n"
39
- end
40
- end
41
-
42
- def print_chapter(chap)
43
- chap_node = TOCParser.chapter_node(chap)
44
- ext = chap.book.config['htmlext'] || 'html'
45
- path = File.basename(chap.path.sub(/\.re/, '.' + ext))
46
- label = if chap_node.number && chap.on_chaps?
47
- "#{I18n.t('chapter_short', chap.number)} #{chap.title}"
48
- else
49
- chap.title
50
- end
51
- @out.puts %Q(<li><a href="#{path}">#{h(label)}</a></li>\n)
55
+ content << "</ul>\n"
52
56
  end
53
57
  end
54
58
  end