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
data/doc/quickstart.md CHANGED
@@ -9,7 +9,7 @@ Re:VIEW is free software under the terms of the GNU Lesser General Public Licens
9
9
 
10
10
  This article describes how to setup Re:VIEW and use it.
11
11
 
12
- The supported version of the article is Re:VIEW 3.0.
12
+ The supported version of the article is Re:VIEW 5.1.
13
13
 
14
14
  ## Set up Re:VIEW
15
15
 
@@ -59,7 +59,7 @@ $ git pull
59
59
 
60
60
  ## Writing Re:VIEW Document
61
61
 
62
- ### Generating template fiels
62
+ ### Generating template files
63
63
 
64
64
  After setup, you can use `review-init` command to generate Re:VIEW project directory.
65
65
 
@@ -72,14 +72,23 @@ $ ls hello
72
72
  Rakefile catalog.yml config.yml hello.re images/ layouts/ sty/ style.css
73
73
  ```
74
74
 
75
+ If your purpose is to create a PDF using TeX, it is a good idea to use the wizard mode for basic layouting in a web browser. Add `-w` option to review-init.
76
+
77
+ (notice: currently wizard UI supports only Japanese language)
78
+
79
+ ```bash
80
+ $ review-init -w hello
81
+ (access http://localhost:18000 on Web browser)
82
+ ```
83
+
75
84
  In `hello` directory, many files are generated.
76
85
 
77
86
  * `*.re` : Re:VIEW format file.
78
87
  * config.yml : configuration file
88
+ * config-ebook.yml : configuration file for ebook (when using the wizard mode)
79
89
  * catalog.yml : catalog file (for TOC)
80
90
  * Rakefile : rule file for `rake` command
81
91
  * images : folder for images
82
- * layouts : forlder for layout files
83
92
  * style.css : sample stylesheet
84
93
  * sty : style files for LaTeX
85
94
  * doc : various documents (including this document)
@@ -116,33 +125,52 @@ The web site of Re:VIEW is @<tt>{https://reviewml.org/}.
116
125
 
117
126
  You should use UTF-8 as encodings in text files.
118
127
 
119
- ### generating PDF, EPUB, and plain-text
128
+ ### generating PDF, EPUB, plain-text, and InDesign XML
129
+
130
+ To convert files in the project, use review-*maker command.
120
131
 
121
- You can generate a PDF file with `review-pdfmaker` command. Also you can generate an EPUB file with `review-epubmaker` command, and can generate an plain-text file with 'review-textmaker' command.
132
+ - review-pdfmaker: generate PDF
133
+ - review-epubmaker: generate EPUB
134
+ - review-textmaker: genrate plaintext
135
+ - review-idgxmlmaker: genrate InDesign XML
122
136
 
123
- To generate PDF, you should install TeXLive 2012 or later. To generate EPUB, you should install zip command.
137
+ To generate PDF, you should install TeXLive 2012 or later. To generate EPUB, you should install zip command.
124
138
  When you want to use MathML, you should install [MathML library](http://www.hinet.mydns.jp/?mathml.rb)
125
139
 
126
- Each maker need `config.yml`, configuration YAML files. `review-init` command generates `config.yml` in default.
140
+ Each maker need `config.yml`, configuration YAML files. `review-init` command generates `config.yml` in default.
127
141
 
128
142
  ```bash
129
- $ review-pdfmaker config.yml ## generate PDF
130
- $ review-epubmaker config.yml ## generate EPUB
131
- $ review-textmaker config.yml ## generate text with decoration
132
- $ review-textmaker -n config.yml ## generate text without decoration
143
+ $ review-pdfmaker config.yml ## generate PDF
144
+ $ review-pdfmaker config-ebook.yml ## generate PDF (for ebook)
145
+ $ review-epubmaker config.yml ## generate EPUB
146
+ $ review-textmaker config.yml ## generate text with decoration
147
+ $ review-textmaker -n config.yml ## generate text without decoration
148
+ $ review-idgxmlmaker config.yml ## generate InDesign XML
133
149
  ```
134
150
 
135
151
  You also can generate them with Rake.
136
152
 
137
153
  ```bash
138
154
  $ rake pdf ## generate PDF
155
+ $ REVIEW_CONFIG_FILE=config-ebook.yml rake pdf ## generate PDF (for ebook)
139
156
  $ rake epub ## generate EPUB
140
157
  $ rake text ## generate text with decoration
141
158
  $ rake plaintext ## generate text without decoration
159
+ $ rake idgxml ## generate InDesign XML
142
160
  ```
143
161
 
144
162
  There is a sample YAML file [config.yml.sample](https://github.com/kmuto/review/blob/master/doc/config.yml.sample) in the same directory of this document.
145
163
 
164
+ #### generate PDF using Vivliostyle CLI
165
+
166
+ Instead of using TeX (`review-pdfmaker` or `rake pdf`), you can also create a PDF use [Vivliostyle CLI](https://github.com/vivliostyle/vivliostyle-cli). Re:VIEW creates EPUB first and then converts it to PDF with Vivliostyle CLI.
167
+
168
+ ```bash
169
+ $ rake vivliostyle:build ## build PDF using Viliostyle
170
+ $ rake vivliostyle:preview ## preview pages in Chrome/Chromium browser
171
+ $ rake vivliostyle ## shortcut of vivliostyle:build
172
+ ```
173
+
146
174
  ### add chapters and modify them
147
175
 
148
176
  `catalog.yml` file is a catalog of Re:VIEW format files.
@@ -164,7 +192,6 @@ POSTDEF:
164
192
 
165
193
  The first item in CHAPS is the first chapter, and the second item (if you add) is the second chapter. PREDEF is for front matter, APPENDIX is for appendix, and POSTDEF is for back matter. You can see in detail with [catalog.md](https://github.com/kmuto/review/blob/master/doc/catalog.ja.md).
166
194
 
167
-
168
195
  ### more information
169
196
 
170
197
  For more information about Re:VIEW format, see [format.md](https://github.com/kmuto/review/blob/master/doc/format.md).
@@ -205,17 +232,20 @@ $ review-vol
205
232
  You can also use `review-index` command to generate header list.
206
233
 
207
234
  ```bash
208
- $ review-index --level <heading level> -a
235
+ $ review-index --level <heading level>
236
+ $ review-index --level <heading level> -d ## show volumes also
209
237
  ```
210
238
 
239
+ review-vol and review-index can have large differences in the number of characters, lines, and pages. While review-vol only estimates from the file, review-index actually compiles and calculates.
240
+
211
241
  ## how to update the document folder to the new Re:VIEW version
212
242
 
213
- Re:VIEW is updated regularly. We Re:VIEW team watch the backward compatibility carefully, but if you want to use the features in the new version, you can use review-update command to update the document folder.
243
+ Re:VIEW is updated regularly. We Re:VIEW team watch the backward compatibility carefully, but if you want to use the features in the new version, you can use review-update command to update the project folder.
214
244
 
215
245
  ```bash
216
246
  $ review-update
217
- ** review-update updates your project to 3.0.0 **
218
- config.yml: Update 'review_version' to '3.0'? [y]/n
247
+ ** review-update updates your project to 5.0.0 **
248
+ config.yml: Update 'review_version' to '5.0'? [y]/n
219
249
  Rakefile will be overridden with Re:VIEW version (/.../review/samples/sample-book/src/Rakefile). Do you really proceed? [y]/n
220
250
  lib/tasks/review.rake will be overridden with Re:VIEW version (/.../review/samples/sample-book/src/lib/tasks/review.rake). Do you really proceed? [y]/n
221
251
  INFO: new file /.../sty/plistings.sty is created.
@@ -231,7 +261,7 @@ Finished.
231
261
 
232
262
  ## Copyright
233
263
 
234
- The original author of Re:VIEW is Minero Aoki. The current maintainer is Kenshi Muto(@kmuto), and committers are Masayoshi Takahashi and Masanori Kado (February 2019).
264
+ The original author of Re:VIEW is Minero Aoki. The current maintainer is Kenshi Muto(@kmuto), and committers are Masayoshi Takahashi and Masanori Kado (March 2020).
235
265
 
236
266
  If you want to report bugs and patches, or to get more information, see:
237
267
 
data/lib/review.rb CHANGED
@@ -1,3 +1,3 @@
1
- Dir["#{File.dirname(__FILE__)}/review/*.rb"].sort.each do |path|
1
+ Dir["#{__dir__}/review/*.rb"].sort.each do |path|
2
2
  require "review/#{File.basename(path, '.rb')}"
3
3
  end
data/lib/review/book.rb CHANGED
@@ -18,8 +18,8 @@ require 'review/book/index'
18
18
 
19
19
  module ReVIEW
20
20
  module Book
21
- def self.load(dir)
22
- Base.load(dir)
21
+ def self.load(_dir)
22
+ raise NotImplementedError, 'ReVIEW::Book.load is obsoleted. Please use ReVIEW::Book::Base.new.'
23
23
  end
24
24
  end
25
25
  end
@@ -9,26 +9,34 @@
9
9
  #
10
10
  require 'review/configure'
11
11
  require 'review/catalog'
12
+ require 'review/book/bib'
12
13
 
13
14
  module ReVIEW
14
15
  module Book
15
16
  class Base
16
17
  attr_accessor :config
17
18
  attr_writer :parts
18
- attr_writer :catalog
19
+ attr_accessor :catalog
19
20
  attr_reader :basedir
21
+ attr_accessor :bibpaper_index
20
22
 
21
- def self.load(dir = '.')
22
- new(dir)
23
+ def self.load(basedir = '.', config: nil)
24
+ new(basedir, config: config)
23
25
  end
24
26
 
25
- def initialize(basedir = '.')
27
+ def initialize(basedir = '.', config: nil)
26
28
  @basedir = basedir
27
29
  @logger = ReVIEW.logger
28
30
  @parts = nil
29
31
  @chapter_index = nil
30
- @config = ReVIEW::Configure.values
32
+ @config = config || ReVIEW::Configure.values
31
33
  @catalog = nil
34
+ @bibpaper_index = nil
35
+ catalog_path = filename_join(@basedir, @config['catalogfile'])
36
+ if catalog_path && File.file?(catalog_path)
37
+ parse_catalog_file(catalog_path)
38
+ end
39
+
32
40
  @warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
33
41
  @basedir_seen = {}
34
42
  update_rubyenv
@@ -44,6 +52,14 @@ module ReVIEW
44
52
  end
45
53
  end
46
54
 
55
+ def execute_indexer
56
+ return unless @catalog
57
+
58
+ parts.each do |part|
59
+ part.chapters.each(&:execute_indexer)
60
+ end
61
+ end
62
+
47
63
  def bib_file
48
64
  config['bib_file']
49
65
  end
@@ -79,7 +95,7 @@ module ReVIEW
79
95
  def page_metric
80
96
  if config['page_metric'].respond_to?(:downcase) && config['page_metric'].upcase =~ /\A[A-Z0-9_]+\Z/
81
97
  ReVIEW::Book::PageMetric.const_get(config['page_metric'].upcase)
82
- elsif config['page_metric'].is_a?(Array) && config['page_metric'].size == 5
98
+ elsif config['page_metric'].is_a?(Array) && (config['page_metric'].size == 5 || config['page_metric'].size == 4)
83
99
  ReVIEW::Book::PageMetric.new(*config['page_metric'])
84
100
  else
85
101
  config['page_metric']
@@ -94,6 +110,30 @@ module ReVIEW
94
110
  end
95
111
  end
96
112
 
113
+ def create_chapter_index
114
+ chapter_index = ChapterIndex.new
115
+ each_chapter do |chap|
116
+ chapter_index.add_item(Index::Item.new(chap.id, chap.number, chap))
117
+ end
118
+ parts.each do |prt|
119
+ if prt.id.present?
120
+ chapter_index.add_item(Index::Item.new(prt.id, prt.number, prt))
121
+ end
122
+ end
123
+ chapter_index
124
+ end
125
+
126
+ def generate_indexes
127
+ if bib_exist?
128
+ bib = ReVIEW::Book::Bib.new(file_content: bib_content, book: self)
129
+ bib.generate_indexes(use_bib: true)
130
+ @bibpaper_index = bib.bibpaper_index
131
+ end
132
+ self.each_chapter(&:generate_indexes)
133
+ self.parts.map(&:generate_indexes)
134
+ @chapter_index = create_chapter_index
135
+ end
136
+
97
137
  def parts
98
138
  @parts ||= read_parts
99
139
  end
@@ -101,7 +141,7 @@ module ReVIEW
101
141
  def parts_in_file
102
142
  # TODO: should be `parts.find_all{|part| part.present? and part.file?}` ?
103
143
  parts.find_all do |part|
104
- part if part.present? and part.file?
144
+ part if part.present? && part.file?
105
145
  end
106
146
  end
107
147
 
@@ -137,24 +177,19 @@ module ReVIEW
137
177
  def chapter_index
138
178
  return @chapter_index if @chapter_index
139
179
 
140
- contents = chapters
141
- # TODO: contents += parts.find_all { |prt| prt.id.present? }
142
- parts.each do |prt|
143
- if prt.id.present?
144
- contents << prt
145
- end
146
- end
147
- @chapter_index = ChapterIndex.new(contents)
180
+ @chapter_index = create_chapter_index
181
+ @chapter_index
148
182
  end
149
183
 
150
184
  def chapter(id)
151
- chapter_index[id]
185
+ chapter_index[id].content
152
186
  end
153
187
 
154
188
  def next_chapter(chapter)
155
189
  finded = false
156
190
  each_chapter do |c|
157
191
  return c if finded
192
+
158
193
  if c == chapter
159
194
  finded = true
160
195
  end
@@ -166,6 +201,7 @@ module ReVIEW
166
201
  finded = false
167
202
  each_chapter_r do |c|
168
203
  return c if finded
204
+
169
205
  if c == chapter
170
206
  finded = true
171
207
  end
@@ -174,9 +210,7 @@ module ReVIEW
174
210
  end
175
211
 
176
212
  def volume
177
- vol = Volume.sum(chapters.map(&:volume))
178
- vol.page_per_kbyte = page_metric.page_per_kbyte
179
- vol
213
+ Volume.sum(parts.map(&:volume) + chapters.map(&:volume))
180
214
  end
181
215
 
182
216
  def load_config(filename)
@@ -184,17 +218,15 @@ module ReVIEW
184
218
  @config.merge!(new_conf)
185
219
  end
186
220
 
187
- def catalog
188
- return @catalog if @catalog.present?
189
-
190
- catalogfile_path = filename_join(@basedir, config['catalogfile'])
191
- if File.file?(catalogfile_path)
192
- @catalog = File.open(catalogfile_path, 'rt:BOM|utf-8') { |f| Catalog.new(f) }
221
+ def parse_catalog_file(path)
222
+ unless File.file?(path)
223
+ raise FileNotFound, "catalog.yml is not found #{path}"
193
224
  end
194
- if @catalog
225
+
226
+ File.open(path, 'rt:BOM|utf-8') do |f|
227
+ @catalog = Catalog.new(f)
195
228
  @catalog.validate!(@config, basedir)
196
229
  end
197
- @catalog
198
230
  end
199
231
 
200
232
  def read_chaps
@@ -253,6 +285,10 @@ module ReVIEW
253
285
  File.exist?(File.join(contentdir, bib_file))
254
286
  end
255
287
 
288
+ def bib_content
289
+ File.read(File.join(contentdir, bib_file))
290
+ end
291
+
256
292
  def prefaces
257
293
  if catalog
258
294
  return Part.mkpart_from_namelist(self, catalog.predef)
@@ -334,8 +370,8 @@ module ReVIEW
334
370
  end
335
371
  end
336
372
 
337
- chap = read_chaps.map(&:strip).join("\n").split(/\n{2,}/).
338
- map do |part_chunk|
373
+ # rubocop:disable Style/RedundantAssignment
374
+ chap = read_chaps.map(&:strip).join("\n").split(/\n{2,}/).map do |part_chunk|
339
375
  chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, File.join(contentdir, chapid)) }
340
376
  if part_exist? && read_part.size > part
341
377
  Part.new(self, part += 1, chaps, read_part[part - 1])
@@ -343,6 +379,8 @@ module ReVIEW
343
379
  Part.new(self, nil, chaps)
344
380
  end
345
381
  end
382
+ # rubocop:enable Style/RedundantAssignment
383
+
346
384
  chap
347
385
  end
348
386
 
@@ -356,7 +394,8 @@ module ReVIEW
356
394
  res = ''
357
395
  File.open(filename_join(@basedir, filename), 'rt:BOM|utf-8') do |f|
358
396
  f.each_line do |line|
359
- next if /\A#/ =~ line
397
+ next if line.start_with?('#')
398
+
360
399
  line.gsub!(/#.*\Z/, '')
361
400
  res << line
362
401
  end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Copyright (c) 2009-2020 Minero Aoki, Kenshi Muto
3
+ #
4
+ # This program is free software.
5
+ # You can distribute or modify this program under the terms of
6
+ # the GNU LGPL, Lesser General Public License version 2.1.
7
+ # For details of the GNU LGPL, see the file "COPYING".
8
+ #
9
+ require 'review/book/book_unit'
10
+ require 'review/lineinput'
11
+ require 'review/preprocessor'
12
+
13
+ module ReVIEW
14
+ module Book
15
+ class Bib < BookUnit
16
+ def number
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,158 @@
1
+ # Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2008 Minero Aoki
3
+ #
4
+ # This program is free software.
5
+ # You can distribute or modify this program under the terms of
6
+ # the GNU LGPL, Lesser General Public License version 2.1.
7
+ # For details of the GNU LGPL, see the file "COPYING".
8
+ #
9
+ require 'review/textutils'
10
+ require 'review/index_builder'
11
+
12
+ module ReVIEW
13
+ module Book
14
+ class BookUnit
15
+ include TextUtils
16
+ attr_reader :book
17
+ attr_reader :path
18
+ attr_reader :lines
19
+ attr_accessor :content
20
+
21
+ attr_reader :list_index, :table_index, :equation_index, :footnote_index,
22
+ :numberless_image_index, :image_index, :icon_index, :indepimage_index,
23
+ :headline_index, :column_index
24
+
25
+ def initialize(file_content: nil, book: nil)
26
+ if book
27
+ @book = book
28
+ end
29
+ if file_content
30
+ @content = file_content
31
+ end
32
+ if @content
33
+ @lines = @content.lines
34
+ end
35
+ end
36
+
37
+ def execute_indexer(force: false)
38
+ if @index_builder && !force
39
+ return @index_builder
40
+ end
41
+
42
+ @index_builder = ReVIEW::IndexBuilder.new
43
+ compiler = ReVIEW::Compiler.new(@index_builder)
44
+ compiler.compile(self)
45
+ @index_builder
46
+ end
47
+
48
+ def generate_indexes(use_bib: false)
49
+ return unless content
50
+
51
+ @lines = content.lines
52
+
53
+ @indexes = execute_indexer
54
+
55
+ @list_index = @indexes.list_index
56
+ @table_index = @indexes.table_index
57
+ @equation_index = @indexes.equation_index
58
+ @footnote_index = @indexes.footnote_index
59
+ @headline_index = @indexes.headline_index
60
+ @column_index = @indexes.column_index
61
+ if use_bib
62
+ @book.bibpaper_index = @indexes.bibpaper_index
63
+ end
64
+ end
65
+
66
+ def dirname
67
+ @path && File.dirname(@path)
68
+ end
69
+
70
+ def basename
71
+ @path && File.basename(@path)
72
+ end
73
+
74
+ def name
75
+ @name && File.basename(@name, '.*')
76
+ end
77
+
78
+ alias_method :id, :name
79
+
80
+ def title
81
+ return @title if @title
82
+
83
+ @title = ''
84
+ return @title unless content
85
+
86
+ content.each_line do |line|
87
+ if line =~ /\A=+/
88
+ @title = line.sub(/\A=+(\[.+?\])?(\{.+?\})?/, '').strip
89
+ break
90
+ end
91
+ end
92
+ @title
93
+ end
94
+
95
+ def size
96
+ content.size
97
+ end
98
+
99
+ def volume
100
+ @volume ||= Volume.count_file(path)
101
+ end
102
+
103
+ def list(id)
104
+ list_index[id]
105
+ end
106
+
107
+ def table(id)
108
+ table_index[id]
109
+ end
110
+
111
+ def equation(id)
112
+ equation_index[id]
113
+ end
114
+
115
+ def footnote(id)
116
+ footnote_index[id]
117
+ end
118
+
119
+ def image(id)
120
+ return image_index[id] if image_index.key?(id)
121
+ return icon_index[id] if icon_index.key?(id)
122
+ return numberless_image_index[id] if numberless_image_index.key?(id)
123
+
124
+ indepimage_index[id]
125
+ end
126
+
127
+ def bibpaper(id)
128
+ bibpaper_index[id]
129
+ end
130
+
131
+ def bibpaper_index
132
+ raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?
133
+
134
+ @book.bibpaper_index
135
+ end
136
+
137
+ def headline(caption)
138
+ headline_index[caption]
139
+ end
140
+
141
+ def column(id)
142
+ column_index[id]
143
+ end
144
+
145
+ def next_chapter
146
+ book.next_chapter(self)
147
+ end
148
+
149
+ def prev_chapter
150
+ book.prev_chapter(self)
151
+ end
152
+
153
+ def image_bound?(item_id)
154
+ image(item_id).path
155
+ end
156
+ end
157
+ end
158
+ end