review 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +90 -66
  3. data/.travis.yml +1 -1
  4. data/Gemfile +0 -1
  5. data/NEWS.ja.md +82 -0
  6. data/NEWS.md +83 -0
  7. data/README.md +5 -3
  8. data/Rakefile +8 -8
  9. data/bin/review +1 -5
  10. data/bin/review-catalog-converter +22 -27
  11. data/bin/review-check +36 -43
  12. data/bin/review-checkdep +10 -15
  13. data/bin/review-compile +37 -55
  14. data/bin/review-epubmaker +4 -5
  15. data/bin/review-index +21 -29
  16. data/bin/review-init +26 -37
  17. data/bin/review-pdfmaker +0 -2
  18. data/bin/review-preproc +25 -45
  19. data/bin/review-validate +19 -18
  20. data/bin/review-vol +15 -27
  21. data/doc/config.yml.sample +5 -2
  22. data/doc/format.ja.md +20 -1
  23. data/doc/format.md +21 -5
  24. data/doc/images/review-generate.png +0 -0
  25. data/lib/epubmaker.rb +1 -3
  26. data/lib/epubmaker/content.rb +24 -27
  27. data/lib/epubmaker/epubcommon.rb +135 -148
  28. data/lib/epubmaker/epubv2.rb +39 -46
  29. data/lib/epubmaker/epubv3.rb +93 -103
  30. data/lib/epubmaker/producer.rb +138 -151
  31. data/lib/epubmaker/zip_exporter.rb +21 -26
  32. data/lib/review/book.rb +3 -6
  33. data/lib/review/book/base.rb +78 -103
  34. data/lib/review/book/chapter.rb +36 -40
  35. data/lib/review/book/compilable.rb +28 -31
  36. data/lib/review/book/image_finder.rb +6 -13
  37. data/lib/review/book/index.rb +100 -121
  38. data/lib/review/book/page_metric.rb +2 -7
  39. data/lib/review/book/part.rb +18 -20
  40. data/lib/review/book/volume.rb +9 -13
  41. data/lib/review/builder.rb +81 -116
  42. data/lib/review/catalog.rb +15 -19
  43. data/lib/review/compiler.rb +64 -83
  44. data/lib/review/configure.rb +87 -97
  45. data/lib/review/converter.rb +2 -7
  46. data/lib/review/epubbuilder.rb +1 -3
  47. data/lib/review/epubmaker.rb +213 -205
  48. data/lib/review/exception.rb +2 -4
  49. data/lib/review/extentions.rb +0 -1
  50. data/lib/review/extentions/hash.rb +2 -2
  51. data/lib/review/extentions/string.rb +5 -30
  52. data/lib/review/htmlbuilder.rb +320 -375
  53. data/lib/review/htmltoc.rb +4 -7
  54. data/lib/review/htmlutils.rb +29 -32
  55. data/lib/review/i18n.rb +33 -44
  56. data/lib/review/i18n.yml +3 -3
  57. data/lib/review/idgxmlbuilder.rb +309 -345
  58. data/lib/review/latexbuilder.rb +175 -212
  59. data/lib/review/latexindex.rb +2 -8
  60. data/lib/review/latexutils.rb +33 -43
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/logger.rb +21 -0
  63. data/lib/review/makerhelper.rb +1 -4
  64. data/lib/review/markdownbuilder.rb +44 -53
  65. data/lib/review/md2inaobuilder.rb +6 -12
  66. data/lib/review/pdfmaker.rb +143 -173
  67. data/lib/review/preprocessor.rb +64 -101
  68. data/lib/review/rstbuilder.rb +126 -158
  69. data/lib/review/sec_counter.rb +18 -34
  70. data/lib/review/template.rb +4 -5
  71. data/lib/review/textbuilder.rb +2 -3
  72. data/lib/review/textutils.rb +7 -13
  73. data/lib/review/tocparser.rb +31 -56
  74. data/lib/review/tocprinter.rb +26 -52
  75. data/lib/review/topbuilder.rb +219 -247
  76. data/lib/review/unfold.rb +15 -24
  77. data/lib/review/version.rb +1 -1
  78. data/lib/review/webmaker.rb +75 -99
  79. data/lib/review/webtocprinter.rb +15 -20
  80. data/lib/review/yamlloader.rb +13 -15
  81. data/review.gemspec +20 -22
  82. data/templates/latex/layout.tex.erb +2 -2
  83. data/templates/opf/epubv2.opf.erb +7 -7
  84. data/templates/opf/epubv3.opf.erb +7 -7
  85. data/templates/web/html/layout-html5.html.erb +2 -2
  86. data/test/assets/black.eps +280 -0
  87. data/test/assets/fit.png +0 -0
  88. data/test/assets/large.gif +0 -0
  89. data/test/assets/large.jpg +0 -0
  90. data/test/assets/large.png +0 -0
  91. data/test/assets/large.svg +65 -0
  92. data/test/assets/test_template.tex +1 -1
  93. data/test/book_test_helper.rb +2 -2
  94. data/test/run_test.rb +4 -4
  95. data/test/sample-book/src/Rakefile +21 -22
  96. data/test/syntax-book/Gemfile +4 -0
  97. data/test/syntax-book/Rakefile +72 -0
  98. data/test/syntax-book/appA.re +22 -0
  99. data/test/syntax-book/bib.re +6 -0
  100. data/test/syntax-book/catalog.yml +15 -0
  101. data/test/syntax-book/ch01.re +136 -0
  102. data/test/syntax-book/ch02.re +351 -0
  103. data/test/syntax-book/ch03.re +82 -0
  104. data/test/syntax-book/config.yml +35 -0
  105. data/test/syntax-book/images/ball.png +0 -0
  106. data/test/syntax-book/images/cover.jpg +0 -0
  107. data/test/syntax-book/images/fractal.png +0 -0
  108. data/test/syntax-book/images/img3-1.png +0 -0
  109. data/test/syntax-book/images/inlineicon.jpg +0 -0
  110. data/test/syntax-book/images/logic.png +0 -0
  111. data/test/syntax-book/images/logic2.png +0 -0
  112. data/test/syntax-book/images/puzzle.jpg +0 -0
  113. data/test/syntax-book/images/table.jpg +0 -0
  114. data/test/syntax-book/part2.re +6 -0
  115. data/test/syntax-book/pre01.re +26 -0
  116. data/test/syntax-book/review-ext.rb +14 -0
  117. data/test/syntax-book/sty/jumoline.sty +310 -0
  118. data/test/syntax-book/sty/reviewmacro.sty +39 -0
  119. data/test/syntax-book/style.css +494 -0
  120. data/test/syntax-book/syntax.dic +2 -0
  121. data/test/test_book.rb +106 -111
  122. data/test/test_book_chapter.rb +21 -22
  123. data/test/test_book_part.rb +3 -5
  124. data/test/test_builder.rb +11 -22
  125. data/test/test_catalog.rb +17 -18
  126. data/test/test_catalog_converter_cmd.rb +5 -5
  127. data/test/test_compiler.rb +18 -16
  128. data/test/test_configure.rb +35 -38
  129. data/test/test_converter.rb +3 -4
  130. data/test/test_epub3maker.rb +136 -117
  131. data/test/test_epubmaker.rb +107 -114
  132. data/test/test_epubmaker_cmd.rb +2 -4
  133. data/test/test_extentions_hash.rb +32 -33
  134. data/test/test_helper.rb +9 -11
  135. data/test/test_htmlbuilder.rb +454 -420
  136. data/test/test_htmltoc.rb +8 -12
  137. data/test/test_htmlutils.rb +0 -2
  138. data/test/test_i18n.rb +159 -150
  139. data/test/test_idgxmlbuilder.rb +190 -197
  140. data/test/test_image_finder.rb +21 -22
  141. data/test/test_index.rb +24 -29
  142. data/test/test_latexbuilder.rb +274 -264
  143. data/test/test_lineinput.rb +7 -10
  144. data/test/test_location.rb +7 -7
  145. data/test/test_makerhelper.rb +13 -25
  146. data/test/test_markdownbuilder.rb +23 -26
  147. data/test/test_md2inaobuilder.rb +8 -11
  148. data/test/test_pdfmaker.rb +114 -123
  149. data/test/test_pdfmaker_cmd.rb +1 -3
  150. data/test/test_review_ext.rb +3 -5
  151. data/test/test_rstbuilder.rb +92 -97
  152. data/test/test_template.rb +3 -7
  153. data/test/test_textutils.rb +27 -27
  154. data/test/test_tocparser.rb +2 -2
  155. data/test/test_topbuilder.rb +98 -103
  156. data/test/test_webtocprinter.rb +5 -6
  157. data/test/test_yamlloader.rb +42 -42
  158. data/test/test_zip_exporter.rb +12 -18
  159. metadata +86 -9
  160. data/lib/review/ewbbuilder.rb +0 -382
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # Copyright (c) 2002-2007 Minero Aoki
4
2
  # 2008-2009 Minero Aoki, Kenshi Muto
5
3
  # 2010-2017 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
@@ -15,15 +13,11 @@ require 'review/latexutils'
15
13
  require 'review/textutils'
16
14
 
17
15
  module ReVIEW
18
-
19
16
  class LATEXBuilder < Builder
20
-
21
17
  include LaTeXUtils
22
18
  include TextUtils
23
19
 
24
- [:dtp, :hd_chap].each {|e|
25
- Compiler.definline(e)
26
- }
20
+ %i[dtp hd_chap].each { |e| Compiler.definline(e) }
27
21
 
28
22
  Compiler.defsingle(:latextsize, 1)
29
23
 
@@ -32,7 +26,7 @@ module ReVIEW
32
26
  end
33
27
 
34
28
  def builder_init_file
35
- @chapter.book.image_types = %w(.ai .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif)
29
+ @chapter.book.image_types = %w[.ai .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif]
36
30
  @blank_needed = false
37
31
  @latex_tsize = nil
38
32
  @tsize = nil
@@ -41,24 +35,23 @@ module ReVIEW
41
35
  @first_line_num = nil
42
36
  @sec_counter = SecCounter.new(5, @chapter)
43
37
  setup_index
44
- initialize_metachars(@book.config["texcommand"])
38
+ initialize_metachars(@book.config['texcommand'])
45
39
  end
46
40
  private :builder_init_file
47
41
 
48
42
  def setup_index
49
43
  @index_db = {}
50
44
  @index_mecab = nil
51
- if @book.config["pdfmaker"]["makeindex"]
52
- @index_db = load_idxdb(@book.config["pdfmaker"]["makeindex_dic"]) if @book.config["pdfmaker"]["makeindex_dic"]
53
- if @book.config["pdfmaker"]["makeindex_mecab"]
54
- begin
55
- require 'MeCab'
56
- require 'nkf'
57
- @index_mecab = MeCab::Tagger.new(@book.config["pdfmaker"]["makeindex_mecab_opts"])
58
- rescue LoadError
59
- error "not found MeCab"
60
- end
61
- end
45
+ return true unless @book.config['pdfmaker']['makeindex']
46
+
47
+ @index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic']) if @book.config['pdfmaker']['makeindex_dic']
48
+ return true unless @book.config['pdfmaker']['makeindex_mecab']
49
+ begin
50
+ require 'MeCab'
51
+ require 'nkf'
52
+ @index_mecab = MeCab::Tagger.new(@book.config['pdfmaker']['makeindex_mecab_opts'])
53
+ rescue LoadError
54
+ error 'not found MeCab'
62
55
  end
63
56
  end
64
57
 
@@ -101,50 +94,48 @@ module ReVIEW
101
94
  4 => 'subsubsection',
102
95
  5 => 'paragraph',
103
96
  6 => 'subparagraph'
104
- }
97
+ }.freeze
105
98
 
106
99
  def headline(level, label, caption)
107
100
  _, anchor = headline_prefix(level)
108
101
  headline_name = HEADLINE[level]
109
- if @chapter.kind_of? ReVIEW::Book::Part
110
- headline_name = "part"
111
- end
112
- prefix = ""
113
- if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
114
- prefix = "*"
115
- end
102
+ headline_name = 'part' if @chapter.is_a? ReVIEW::Book::Part
103
+ prefix = if level > @book.config['secnolevel'] || (@chapter.number.to_s.empty? && level > 1)
104
+ '*'
105
+ else
106
+ ''
107
+ end
116
108
  blank unless @output.pos == 0
117
- puts macro(headline_name+prefix, compile_inline(caption))
118
- if prefix == "*" && level <= @book.config["toclevel"].to_i
119
- puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}"
120
- end
109
+ puts macro(headline_name + prefix, compile_inline(caption))
110
+ puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}" if prefix == '*' && level <= @book.config['toclevel'].to_i
121
111
  if level == 1
122
112
  puts macro('label', chapter_label)
123
113
  else
124
114
  puts macro('label', sec_label(anchor))
115
+ puts macro('label', label) if label
125
116
  end
126
117
  rescue
127
118
  error "unknown level: #{level}"
128
119
  end
129
120
 
130
- def nonum_begin(level, label, caption)
121
+ def nonum_begin(level, _label, caption)
131
122
  blank unless @output.pos == 0
132
- puts macro(HEADLINE[level]+"*", compile_inline(caption))
123
+ puts macro(HEADLINE[level] + '*', compile_inline(caption))
133
124
  puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
134
125
  end
135
126
 
136
127
  def nonum_end(level)
137
128
  end
138
129
 
139
- def notoc_begin(level, label, caption)
130
+ def notoc_begin(level, _label, caption)
140
131
  blank unless @output.pos == 0
141
- puts macro(HEADLINE[level]+"*", compile_inline(caption))
132
+ puts macro(HEADLINE[level] + '*', compile_inline(caption))
142
133
  end
143
134
 
144
135
  def notoc_end(level)
145
136
  end
146
137
 
147
- def nodisp_begin(level, label, caption)
138
+ def nodisp_begin(level, _label, caption)
148
139
  blank unless @output.pos == 0
149
140
  puts macro('clearpage') if @output.pos == 0
150
141
  puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
@@ -163,21 +154,17 @@ module ReVIEW
163
154
  puts "\\hypertarget{#{column_label(caption)}}{}"
164
155
  end
165
156
  puts macro('reviewcolumnhead', nil, compile_inline(caption))
166
- if level <= @book.config["toclevel"].to_i
167
- puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
168
- end
157
+ puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}" if level <= @book.config['toclevel'].to_i
169
158
  end
170
159
 
171
- def column_end(level)
160
+ def column_end(_level)
172
161
  puts "\\end{reviewcolumn}\n"
173
162
  blank
174
163
  end
175
164
 
176
- def captionblock(type, lines, caption)
165
+ def captionblock(_type, lines, caption)
177
166
  puts "\\begin{reviewminicolumn}\n"
178
- unless caption.nil?
179
- puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
180
- end
167
+ puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n" if caption
181
168
 
182
169
  blocked_lines = split_paragraph(lines)
183
170
  puts blocked_lines.join("\n\n")
@@ -187,13 +174,9 @@ module ReVIEW
187
174
 
188
175
  def box(lines, caption = nil)
189
176
  blank
190
- if caption
191
- puts macro('reviewboxcaption', "#{compile_inline(caption)}")
192
- end
177
+ puts macro('reviewboxcaption', compile_inline(caption)) if caption
193
178
  puts '\begin{reviewbox}'
194
- lines.each do |line|
195
- puts detab(line)
196
- end
179
+ lines.each { |line| puts detab(line) }
197
180
  puts '\end{reviewbox}'
198
181
  blank
199
182
  end
@@ -205,7 +188,7 @@ module ReVIEW
205
188
 
206
189
  def ul_item(lines)
207
190
  str = lines.join
208
- str.sub!(/\A(\[)/){'\lbrack{}'}
191
+ str.sub!(/\A(\[)/) { '\lbrack{}' }
209
192
  puts '\item ' + str
210
193
  end
211
194
 
@@ -217,15 +200,14 @@ module ReVIEW
217
200
  def ol_begin
218
201
  blank
219
202
  puts '\begin{enumerate}'
220
- if @ol_num
221
- puts "\\setcounter{enumi}{#{@ol_num - 1}}"
222
- @ol_num = nil
223
- end
203
+ return true unless @ol_num
204
+ puts "\\setcounter{enumi}{#{@ol_num - 1}}"
205
+ @ol_num = nil
224
206
  end
225
207
 
226
- def ol_item(lines, num)
208
+ def ol_item(lines, _num)
227
209
  str = lines.join
228
- str.sub!(/\A(\[)/){'\lbrack{}'}
210
+ str.sub!(/\A(\[)/) { '\lbrack{}' }
229
211
  puts '\item ' + str
230
212
  end
231
213
 
@@ -240,8 +222,8 @@ module ReVIEW
240
222
  end
241
223
 
242
224
  def dt(str)
243
- str.sub!(/\[/){'\lbrack{}'}
244
- str.sub!(/\]/){'\rbrack{}'}
225
+ str.sub!(/\[/) { '\lbrack{}' }
226
+ str.sub!(/\]/) { '\rbrack{}' }
245
227
  puts '\item[' + str + '] \mbox{} \\\\'
246
228
  end
247
229
 
@@ -256,9 +238,7 @@ module ReVIEW
256
238
 
257
239
  def paragraph(lines)
258
240
  blank
259
- lines.each do |line|
260
- puts line
261
- end
241
+ lines.each { |line| puts line }
262
242
  blank
263
243
  end
264
244
 
@@ -273,7 +253,7 @@ module ReVIEW
273
253
  alias_method :lead, :read
274
254
 
275
255
  def highlight_listings?
276
- @book.config["highlight"] && @book.config["highlight"]["latex"] == "listings"
256
+ @book.config['highlight'] && @book.config['highlight']['latex'] == 'listings'
277
257
  end
278
258
  private :highlight_listings?
279
259
 
@@ -282,21 +262,17 @@ module ReVIEW
282
262
  if highlight_listings?
283
263
  common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
284
264
  else
285
- common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
286
- detab(line) + "\n"
287
- end
265
+ common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, _idx| detab(line) + "\n" }
288
266
  end
289
267
  end
290
268
 
291
269
  def emlistnum(lines, caption = nil, lang = nil)
292
270
  blank
293
- first_line_num = get_line_num
271
+ first_line_num = line_num
294
272
  if highlight_listings?
295
273
  common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang, first_line_num: first_line_num)
296
274
  else
297
- common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
298
- detab((idx+first_line_num).to_s.rjust(2)+": " + line) + "\n"
299
- end
275
+ common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" }
300
276
  end
301
277
  end
302
278
 
@@ -305,21 +281,17 @@ module ReVIEW
305
281
  if highlight_listings?
306
282
  common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
307
283
  else
308
- common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
309
- detab(line) + "\n"
310
- end
284
+ common_code_block(id, lines, 'reviewlist', caption, lang) { |line, _idx| detab(line) + "\n" }
311
285
  end
312
286
  end
313
287
 
314
288
  ## override Builder#listnum
315
289
  def listnum(lines, id, caption, lang = nil)
316
- first_line_num = get_line_num
290
+ first_line_num = line_num
317
291
  if highlight_listings?
318
292
  common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang, first_line_num: first_line_num)
319
293
  else
320
- common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
321
- detab((idx+first_line_num).to_s.rjust(2)+": " + line) + "\n"
322
- end
294
+ common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" }
323
295
  end
324
296
  end
325
297
 
@@ -328,75 +300,65 @@ module ReVIEW
328
300
  common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
329
301
  else
330
302
  blank
331
- common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx|
332
- detab(line) + "\n"
333
- end
303
+ common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line, _idx| detab(line) + "\n" }
334
304
  end
335
305
  end
336
306
 
337
- def common_code_block(id, lines, command, caption, lang)
307
+ def common_code_block(id, lines, command, caption, _lang)
338
308
  if caption
339
309
  if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/
340
- puts macro(command + 'caption', "#{compile_inline(caption)}")
310
+ puts macro(command + 'caption', compile_inline(caption))
341
311
  else
342
312
  begin
343
313
  if get_chap.nil?
344
- puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
314
+ puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
345
315
  else
346
- puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
316
+ puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
347
317
  end
348
318
  rescue KeyError
349
319
  error "no such list: #{id}"
350
320
  end
351
321
  end
352
322
  end
353
- body = ""
354
- lines.each_with_index do |line, idx|
355
- body.concat(yield(line, idx))
356
- end
357
- puts macro('begin',command)
323
+ body = ''
324
+ lines.each_with_index { |line, idx| body.concat(yield(line, idx)) }
325
+ puts macro('begin', command)
358
326
  print body
359
- puts macro('end',command)
327
+ puts macro('end', command)
360
328
  blank
361
329
  end
362
330
 
363
- def common_code_block_lst(id, lines, command, title, caption, lang, first_line_num: 1)
364
- if title == "title" && caption.blank?
365
- print "\\vspace{-1.5em}"
366
- end
367
- body = lines.inject(''){|i, j| i + detab(unescape_latex(j)) + "\n"}
331
+ def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1)
332
+ print '\vspace{-1.5em}' if title == 'title' && caption.blank?
333
+ body = lines.inject('') { |i, j| i + detab(unescape_latex(j)) + "\n" }
368
334
  args = make_code_block_args(title, caption, lang, first_line_num: first_line_num)
369
- puts "\\begin{"+command+"}[" + args + "]"
335
+ puts %Q(\\begin{#{command}}[#{args}])
370
336
  print body
371
- puts "\\end{"+ command + "}"
337
+ puts %Q(\\end{#{command}})
372
338
  blank
373
339
  end
374
340
 
375
341
  def make_code_block_args(title, caption, lang, first_line_num: 1)
376
- caption_str = compile_inline((caption || ""))
377
- if title == "title" && caption_str == ""
378
- caption_str = "\\relax" ## dummy charactor to remove lstname
379
- end
380
- if @book.config["highlight"] && @book.config["highlight"]["lang"]
381
- lexer = @book.config["highlight"]["lang"] # default setting
382
- else
383
- lexer = ""
384
- end
342
+ caption_str = compile_inline((caption || ''))
343
+ if title == 'title' && caption_str == ''
344
+ caption_str = '\relax' ## dummy charactor to remove lstname
345
+ end
346
+ lexer = if @book.config['highlight'] && @book.config['highlight']['lang']
347
+ @book.config['highlight']['lang'] # default setting
348
+ else
349
+ ''
350
+ end
385
351
  lexer = lang if lang.present?
386
- args = title + "={" + caption_str + "},language={" + lexer + "}"
387
- if first_line_num != 1
388
- args += ",firstnumber=#{first_line_num}"
389
- end
352
+ args = %Q(#{title}={#{caption_str}},language={#{lexer}})
353
+ args += ",firstnumber=#{first_line_num}" if first_line_num != 1
390
354
  args
391
355
  end
392
356
 
393
- def source(lines, caption, lang = nil)
357
+ def source(lines, caption = nil, lang = nil)
394
358
  if highlight_listings?
395
359
  common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang)
396
360
  else
397
- common_code_block(nil, lines, 'reviewsource', caption, lang) do |line, idx|
398
- detab(line) + "\n"
399
- end
361
+ common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, _idx| detab(line) + "\n" }
400
362
  end
401
363
  end
402
364
 
@@ -404,18 +366,18 @@ module ReVIEW
404
366
  end
405
367
 
406
368
  def handle_metric(str)
407
- if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/
369
+ if @book.config['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
408
370
  return "width=#{$1}\\maxwidth"
409
371
  end
410
372
  str
411
373
  end
412
374
 
413
375
  def result_metric(array)
414
- "#{array.join(',')}"
376
+ array.join(',')
415
377
  end
416
378
 
417
379
  def image_image(id, caption, metric)
418
- metrics = parse_metric("latex", metric)
380
+ metrics = parse_metric('latex', metric)
419
381
  # image is always bound here
420
382
  puts '\begin{reviewimage}'
421
383
  if metrics.present?
@@ -423,20 +385,17 @@ module ReVIEW
423
385
  else
424
386
  puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
425
387
  end
426
- if caption.present?
427
- puts macro('caption', compile_inline(caption))
428
- end
388
+ puts macro('caption', compile_inline(caption)) if caption.present?
429
389
  puts macro('label', image_label(id))
430
390
  puts '\end{reviewimage}'
431
391
  end
432
392
 
433
393
  def image_dummy(id, caption, lines)
394
+ warn "image not bound: #{id}"
434
395
  puts '\begin{reviewdummyimage}'
435
- path = @chapter.image(id).path
436
- puts "--[[path = #{path} (#{existence(id)})]]--"
437
- lines.each do |line|
438
- puts detab(line.rstrip)
439
- end
396
+ # path = @chapter.image(id).path
397
+ puts "--[[path = #{id} (#{existence(id)})]]--"
398
+ lines.each { |line| puts detab(line.rstrip) }
440
399
  puts macro('label', image_label(id))
441
400
  puts compile_inline(caption)
442
401
  puts '\end{reviewdummyimage}'
@@ -447,7 +406,7 @@ module ReVIEW
447
406
  end
448
407
  private :existence
449
408
 
450
- def image_label(id, chapter=nil)
409
+ def image_label(id, chapter = nil)
451
410
  chapter ||= @chapter
452
411
  "image:#{chapter.id}:#{id}"
453
412
  end
@@ -463,7 +422,7 @@ module ReVIEW
463
422
  end
464
423
  private :sec_label
465
424
 
466
- def table_label(id, chapter=nil)
425
+ def table_label(id, chapter = nil)
467
426
  chapter ||= @chapter
468
427
  "table:#{chapter.id}:#{id}"
469
428
  end
@@ -474,26 +433,37 @@ module ReVIEW
474
433
  end
475
434
  private :bib_label
476
435
 
477
- def column_label(id)
478
- filename = @chapter.id
479
- num = @chapter.column(id).number
436
+ def column_label(id, chapter = @chapter)
437
+ filename = chapter.id
438
+ num = chapter.column(id).number
480
439
  "column:#{filename}:#{num}"
481
440
  end
482
441
  private :column_label
483
442
 
484
- def indepimage(id, caption=nil, metric=nil)
485
- metrics = parse_metric("latex", metric)
486
- puts '\begin{reviewimage}'
487
- if metrics.present?
488
- puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
443
+ def indepimage(lines, id, caption = nil, metric = nil)
444
+ metrics = parse_metric('latex', metric)
445
+
446
+ if @chapter.image(id).path
447
+ puts '\begin{reviewimage}'
448
+ if metrics.present?
449
+ puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
450
+ else
451
+ puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
452
+ end
489
453
  else
490
- puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
454
+ warn "image not bound: #{id}"
455
+ puts '\begin{reviewdummyimage}'
456
+ puts "--[[path = #{id} (#{existence(id)})]]--"
457
+ lines.each { |line| puts detab(line.rstrip) }
491
458
  end
492
- if caption.present?
493
- puts macro('reviewindepimagecaption',
494
- %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
459
+
460
+ puts macro('reviewindepimagecaption', %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})) if caption.present?
461
+
462
+ if @chapter.image(id).path
463
+ puts '\end{reviewimage}'
464
+ else
465
+ puts '\end{reviewdummyimage}'
495
466
  end
496
- puts '\end{reviewimage}'
497
467
  end
498
468
 
499
469
  alias_method :numberlessimage, :indepimage
@@ -504,11 +474,11 @@ module ReVIEW
504
474
  lines.each_with_index do |line, idx|
505
475
  if /\A[\=\{\-\}]{12}/ =~ line
506
476
  # just ignore
507
- #error "too many table separator" if sepidx
477
+ # error "too many table separator" if sepidx
508
478
  sepidx ||= idx
509
479
  next
510
480
  end
511
- rows.push(line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') })
481
+ rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
512
482
  end
513
483
  rows = adjust_n_cols(rows)
514
484
 
@@ -520,16 +490,12 @@ module ReVIEW
520
490
  return if rows.empty?
521
491
  table_begin rows.first.size
522
492
  if sepidx
523
- sepidx.times do
524
- tr(rows.shift.map {|s| th(s) })
525
- end
526
- rows.each do |cols|
527
- tr(cols.map {|s| td(s) })
528
- end
493
+ sepidx.times { tr(rows.shift.map { |s| th(s) }) }
494
+ rows.each { |cols| tr(cols.map { |s| td(s) }) }
529
495
  else
530
496
  rows.each do |cols|
531
497
  h, *cs = *cols
532
- tr([th(h)] + cs.map {|s| td(s) })
498
+ tr([th(h)] + cs.map { |s| td(s) })
533
499
  end
534
500
  end
535
501
  table_end
@@ -558,7 +524,7 @@ module ReVIEW
558
524
  elsif @tsize
559
525
  if @tsize =~ /\A[\d., ]+\Z/
560
526
  cellwidth = @tsize.split(/\s*,\s*/)
561
- puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
527
+ puts macro('begin', 'reviewtable', '|' + cellwidth.collect { |i| "p{#{i}mm}" }.join('|') + '|')
562
528
  else
563
529
  puts macro('begin', 'reviewtable', @tsize)
564
530
  end
@@ -571,7 +537,7 @@ module ReVIEW
571
537
  end
572
538
 
573
539
  def table_separator
574
- #puts '\hline'
540
+ # puts '\hline'
575
541
  end
576
542
 
577
543
  def th(s)
@@ -599,9 +565,7 @@ module ReVIEW
599
565
 
600
566
  def table_end
601
567
  puts macro('end', 'reviewtable')
602
- if @table_caption
603
- puts '\end{table}'
604
- end
568
+ puts '\end{table}' if @table_caption
605
569
  @table_caption = nil
606
570
  blank
607
571
  end
@@ -611,7 +575,7 @@ module ReVIEW
611
575
  end
612
576
 
613
577
  def imgtable(lines, id, caption = nil, metric = nil)
614
- if !@chapter.image(id).bound?
578
+ unless @chapter.image(id).bound?
615
579
  warn "image not bound: #{id}"
616
580
  image_dummy id, caption, lines
617
581
  return
@@ -634,8 +598,8 @@ module ReVIEW
634
598
  blank
635
599
  end
636
600
 
637
- def imgtable_image(id, caption, metric)
638
- metrics = parse_metric("latex", metric)
601
+ def imgtable_image(id, _caption, metric)
602
+ metrics = parse_metric('latex', metric)
639
603
  # image is always bound here
640
604
  puts '\begin{reviewimage}'
641
605
  if metrics.present?
@@ -662,10 +626,8 @@ module ReVIEW
662
626
 
663
627
  def texequation(lines)
664
628
  blank
665
- puts macro('begin','equation*')
666
- lines.each do |line|
667
- puts unescape_latex(line)
668
- end
629
+ puts macro('begin', 'equation*')
630
+ lines.each { |line| puts unescape_latex(line) }
669
631
  puts macro('end', 'equation*')
670
632
  blank
671
633
  end
@@ -682,18 +644,15 @@ module ReVIEW
682
644
 
683
645
  def direct(lines, fmt)
684
646
  return unless fmt == 'latex'
685
- lines.each do |line|
686
- puts line
687
- end
647
+ lines.each { |line| puts line }
688
648
  end
689
649
 
690
650
  def comment(lines, comment = nil)
691
651
  lines ||= []
692
652
  lines.unshift comment unless comment.blank?
693
- if @book.config["draft"]
694
- str = lines.join('\par ')
695
- puts macro('pdfcomment', escape(str))
696
- end
653
+ return true unless @book.config['draft']
654
+ str = lines.join('\par ')
655
+ puts macro('pdfcomment', escape(str))
697
656
  end
698
657
 
699
658
  def hr
@@ -718,7 +677,7 @@ module ReVIEW
718
677
 
719
678
  def inline_chapref(id)
720
679
  title = super
721
- if @book.config["chapterlink"]
680
+ if @book.config['chapterlink']
722
681
  "\\hyperref[chap:#{id}]{#{title}}"
723
682
  else
724
683
  title
@@ -729,7 +688,7 @@ module ReVIEW
729
688
  end
730
689
 
731
690
  def inline_chap(id)
732
- if @book.config["chapterlink"]
691
+ if @book.config['chapterlink']
733
692
  "\\hyperref[chap:#{id}]{#{@book.chapter_index.number(id)}}"
734
693
  else
735
694
  @book.chapter_index.number(id)
@@ -741,7 +700,7 @@ module ReVIEW
741
700
 
742
701
  def inline_title(id)
743
702
  title = super
744
- if @book.config["chapterlink"]
703
+ if @book.config['chapterlink']
745
704
  "\\hyperref[chap:#{id}]{#{title}}"
746
705
  else
747
706
  title
@@ -751,53 +710,54 @@ module ReVIEW
751
710
  nofunc_text("[UnknownChapter:#{id}]")
752
711
  end
753
712
 
713
+ def inline_pageref(id)
714
+ "\\pageref{#{id}}"
715
+ end
716
+
754
717
  # FIXME: use TeX native label/ref.
755
718
  def inline_list(id)
756
719
  chapter, id = extract_chapter_id(id)
757
720
  if get_chap(chapter).nil?
758
- macro('reviewlistref', I18n.t("format_number_without_header", [chapter.list(id).number]))
721
+ macro('reviewlistref', I18n.t('format_number_without_chapter', [chapter.list(id).number]))
759
722
  else
760
- macro('reviewlistref', I18n.t("format_number", [get_chap(chapter), chapter.list(id).number]))
723
+ macro('reviewlistref', I18n.t('format_number', [get_chap(chapter), chapter.list(id).number]))
761
724
  end
762
725
  end
763
726
 
764
727
  def inline_table(id)
765
728
  chapter, id = extract_chapter_id(id)
766
729
  if get_chap(chapter).nil?
767
- macro('reviewtableref', I18n.t("format_number_without_header", [chapter.table(id).number]), table_label(id, chapter))
730
+ macro('reviewtableref', I18n.t('format_number_without_chapter', [chapter.table(id).number]), table_label(id, chapter))
768
731
  else
769
- macro('reviewtableref', I18n.t("format_number", [get_chap(chapter), chapter.table(id).number]), table_label(id, chapter))
732
+ macro('reviewtableref', I18n.t('format_number', [get_chap(chapter), chapter.table(id).number]), table_label(id, chapter))
770
733
  end
771
734
  end
772
735
 
773
736
  def inline_img(id)
774
737
  chapter, id = extract_chapter_id(id)
775
738
  if get_chap(chapter).nil?
776
- macro('reviewimageref', I18n.t("format_number_without_header", [chapter.image(id).number]), image_label(id, chapter))
739
+ macro('reviewimageref', I18n.t('format_number_without_chapter', [chapter.image(id).number]), image_label(id, chapter))
777
740
  else
778
- macro('reviewimageref', I18n.t("format_number", [get_chap(chapter), chapter.image(id).number]), image_label(id, chapter))
741
+ macro('reviewimageref', I18n.t('format_number', [get_chap(chapter), chapter.image(id).number]), image_label(id, chapter))
779
742
  end
780
743
  end
781
744
 
782
745
  def footnote(id, content)
783
- if @book.config["footnotetext"]
784
- puts macro("footnotetext[#{@chapter.footnote(id).number}]",
785
- compile_inline(content.strip))
786
- end
746
+ puts macro("footnotetext[#{@chapter.footnote(id).number}]", compile_inline(content.strip)) if @book.config['footnotetext']
787
747
  end
788
748
 
789
749
  def inline_fn(id)
790
- if @book.config["footnotetext"]
791
- macro("footnotemark[#{@chapter.footnote(id).number}]", "")
750
+ if @book.config['footnotetext']
751
+ macro("footnotemark[#{@chapter.footnote(id).number}]", '')
792
752
  else
793
753
  macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
794
754
  end
795
755
  end
796
756
 
797
- BOUTEN = ""
757
+ BOUTEN = ''.freeze
798
758
 
799
759
  def inline_bou(str)
800
- str.split(//).map {|c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
760
+ str.split(//).map { |c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
801
761
  end
802
762
 
803
763
  def compile_ruby(base, ruby)
@@ -824,7 +784,7 @@ module ReVIEW
824
784
  escape(str) + index(str)
825
785
  end
826
786
 
827
- # hidden index??
787
+ # hidden index
828
788
  def inline_hidx(str)
829
789
  index(str)
830
790
  end
@@ -835,13 +795,13 @@ module ReVIEW
835
795
  end
836
796
 
837
797
  # line break
838
- def inline_br(str)
798
+ def inline_br(_str)
839
799
  "\\\\\n"
840
800
  end
841
801
 
842
- def inline_dtp(str)
802
+ def inline_dtp(_str)
843
803
  # ignore
844
- ""
804
+ ''
845
805
  end
846
806
 
847
807
  ## @<code> is same as @<tt>
@@ -875,13 +835,13 @@ module ReVIEW
875
835
 
876
836
  def inline_hd_chap(chap, id)
877
837
  n = chap.headline_index.number(id)
878
- if chap.number and @book.config["secnolevel"] >= n.split('.').size
879
- str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
838
+ if chap.number and @book.config['secnolevel'] >= n.split('.').size
839
+ str = I18n.t('chapter_quote', "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
880
840
  else
881
- str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
841
+ str = I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
882
842
  end
883
- if @book.config["chapterlink"]
884
- anchor = n.gsub(/\./, "-")
843
+ if @book.config['chapterlink']
844
+ anchor = n.gsub(/\./, '-')
885
845
  macro('reviewsecref', str, sec_label(anchor))
886
846
  else
887
847
  str
@@ -890,8 +850,8 @@ module ReVIEW
890
850
 
891
851
  def inline_column_chap(chapter, id)
892
852
  macro('reviewcolumnref',
893
- I18n.t("chapter_quote", compile_inline(chapter.column(id).caption)),
894
- column_label(id))
853
+ I18n.t('chapter_quote', compile_inline(chapter.column(id).caption)),
854
+ column_label(id, chapter))
895
855
  end
896
856
 
897
857
  def inline_raw(str)
@@ -923,7 +883,12 @@ module ReVIEW
923
883
  end
924
884
 
925
885
  def inline_icon(id)
926
- macro('includegraphics', @chapter.image(id).path)
886
+ if @chapter.image(id).path
887
+ macro('includegraphics', @chapter.image(id).path)
888
+ else
889
+ warn "image not bound: #{id}"
890
+ "\\verb|--[[path = #{id} (#{existence(id)})]]--|"
891
+ end
927
892
  end
928
893
 
929
894
  def inline_uchar(str)
@@ -932,10 +897,10 @@ module ReVIEW
932
897
  end
933
898
 
934
899
  def inline_comment(str)
935
- if @book.config["draft"]
900
+ if @book.config['draft']
936
901
  macro('pdfcomment', escape(str))
937
902
  else
938
- ""
903
+ ''
939
904
  end
940
905
  end
941
906
 
@@ -948,9 +913,9 @@ module ReVIEW
948
913
  puts macro('label', bib_label(id))
949
914
  end
950
915
 
951
- def bibpaper_bibpaper(id, caption, lines)
952
- print split_paragraph(lines).join("")
953
- puts ""
916
+ def bibpaper_bibpaper(_id, _caption, lines)
917
+ print split_paragraph(lines).join
918
+ puts ''
954
919
  end
955
920
 
956
921
  def index(str)
@@ -958,7 +923,7 @@ module ReVIEW
958
923
 
959
924
  sa.map! do |item|
960
925
  if @index_db[item]
961
- item = escape_index(escape_latex(@index_db[item])) + "@" + escape_index(escape_latex(item))
926
+ escape_index(escape_latex(@index_db[item])) + '@' + escape_index(escape_latex(item))
962
927
  else
963
928
  if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
964
929
  esc_item = escape_index(escape_latex(item))
@@ -968,8 +933,8 @@ module ReVIEW
968
933
  esc_item
969
934
  end
970
935
  else
971
- yomi = NKF.nkf("-w --hiragana", @index_mecab.parse(item).force_encoding("UTF-8").chomp)
972
- escape_index(escape_latex(yomi)) + "@" + escape_index(escape_latex(item))
936
+ yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
937
+ escape_index(escape_latex(yomi)) + '@' + escape_index(escape_latex(item))
973
938
  end
974
939
  end
975
940
  end
@@ -988,12 +953,12 @@ module ReVIEW
988
953
  def compile_href(url, label)
989
954
  if /\A[a-z]+:/ =~ url
990
955
  if label
991
- macro("href", escape_url(url), escape(label))
956
+ macro('href', escape_url(url), escape(label))
992
957
  else
993
- macro("url", escape_url(url))
958
+ macro('url', escape_url(url))
994
959
  end
995
960
  else
996
- macro("ref", url)
961
+ macro('ref', url)
997
962
  end
998
963
  end
999
964
 
@@ -1002,13 +967,11 @@ module ReVIEW
1002
967
  end
1003
968
 
1004
969
  def image_ext
1005
- "pdf"
970
+ 'pdf'
1006
971
  end
1007
972
 
1008
973
  def olnum(num)
1009
974
  @ol_num = num.to_i
1010
975
  end
1011
-
1012
976
  end
1013
-
1014
977
  end