review 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,8 +1,5 @@
1
- #
2
- # $Id: preprocessor.rb 4250 2009-05-24 14:03:01Z aamine $
3
- #
4
- # Copyright (c) 2002-2009 Minero Aoki
5
- # Copyright (c) 2010 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2010-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2009 Minero Aoki
6
3
  #
7
4
  # This program is free software.
8
5
  # You can distribute or modify this program under the terms of
@@ -15,25 +12,23 @@ require 'review/exception'
15
12
  require 'nkf'
16
13
 
17
14
  module ReVIEW
18
-
19
15
  module ErrorUtils
20
-
21
- def init_ErrorUtils(f)
16
+ def init_errorutils(f)
22
17
  @errutils_file = f
23
18
  @errutils_err = false
24
19
  end
25
20
 
26
21
  def warn(msg)
27
- $stderr.puts "#{location()}: warning: #{msg}"
22
+ @logger.warn "#{location}: #{msg}"
28
23
  end
29
24
 
30
25
  def error(msg)
31
26
  @errutils_err = true
32
- raise ApplicationError, "#{location()}: #{msg}"
27
+ raise ApplicationError, "#{location}: #{msg}"
33
28
  end
34
29
 
35
30
  def location
36
- "#{filename()}:#{lineno()}"
31
+ "#{filename}:#{lineno}"
37
32
  end
38
33
 
39
34
  def filename
@@ -43,19 +38,14 @@ module ReVIEW
43
38
  def lineno
44
39
  @errutils_file.lineno
45
40
  end
46
-
47
41
  end
48
42
 
49
-
50
43
  class Preprocessor
51
-
52
44
  include ErrorUtils
53
45
 
54
- def Preprocessor.strip(f)
46
+ def self.strip(f)
55
47
  buf = ''
56
- Strip.new(f).each do |line|
57
- buf << line.rstrip << "\n"
58
- end
48
+ Strip.new(f).each { |line| buf << line.rstrip << "\n" }
59
49
  buf
60
50
  end
61
51
 
@@ -73,12 +63,9 @@ module ReVIEW
73
63
  end
74
64
 
75
65
  def gets
76
- while line = @f.gets
77
- if /\A\#@/ =~ line
78
- return "\#@\#\n"
79
- else
80
- return line
81
- end
66
+ @f.each_line do |line|
67
+ return "\#@\#\n" if /\A\#@/ =~ line
68
+ return line
82
69
  end
83
70
  nil
84
71
  end
@@ -93,10 +80,11 @@ module ReVIEW
93
80
  def initialize(repo, param)
94
81
  @repository = repo
95
82
  @config = param
83
+ @logger = ReVIEW.logger
96
84
  end
97
85
 
98
86
  def process(inf, outf)
99
- init_ErrorUtils inf
87
+ init_errorutils inf
100
88
  @f = outf
101
89
  begin
102
90
  preproc inf
@@ -107,11 +95,11 @@ module ReVIEW
107
95
 
108
96
  private
109
97
 
110
- TYPES = %w(file range)
98
+ TYPES = %w[file range].freeze
111
99
 
112
100
  def preproc(f)
113
101
  init_vars
114
- while line = f.gets
102
+ f.each_line do |line|
115
103
  case line
116
104
  when /\A\#@\#/, /\A\#\#\#\#/
117
105
  @f.print line
@@ -124,9 +112,7 @@ module ReVIEW
124
112
  when /\A\#@mapoutput/
125
113
  direc = parse_directive(line, 1, 'stderr')
126
114
  @f.print line
127
- get_output(expand(direc.arg), direc['stderr']).each do |out|
128
- @f.print out.string
129
- end
115
+ get_output(expand(direc.arg), direc['stderr']).each { |out| @f.print out.string }
130
116
  skip_list f
131
117
 
132
118
  when /\A\#@mapfile/
@@ -140,7 +126,7 @@ module ReVIEW
140
126
  direc = parse_directive(line, 2, 'unindent')
141
127
  path = expand(direc.args[0])
142
128
  ent = @repository.fetch_range(path, direc.args[1]) or
143
- error "unknown range: #{path}: #{direc.args[1]}"
129
+ error "unknown range: #{path}: #{direc.args[1]}"
144
130
  ent = (direc['unindent'] ? unindent(ent, direc['unindent']) : ent)
145
131
  replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
146
132
 
@@ -149,8 +135,7 @@ module ReVIEW
149
135
 
150
136
  when /\A\#@/
151
137
  op = line.slice(/@(\w+)/, 1)
152
- #error "unkown directive: #{line.strip}" unless known_directive?(op)
153
- warn "unkown directive: #{line.strip}" unless known_directive?(op)
138
+ warn "unknown directive: #{line.strip}" unless known_directive?(op)
154
139
  @f.print line
155
140
 
156
141
  when /\A\s*\z/ # empty line
@@ -161,7 +146,7 @@ module ReVIEW
161
146
  end
162
147
  end
163
148
 
164
- KNOWN_DIRECTIVES = %w(require provide warn ok)
149
+ KNOWN_DIRECTIVES = %w[require provide warn ok].freeze
165
150
 
166
151
  def known_directive?(op)
167
152
  KNOWN_DIRECTIVES.index(op)
@@ -182,19 +167,19 @@ module ReVIEW
182
167
 
183
168
  def skip_list(f)
184
169
  begline = f.lineno
185
- while line = f.gets
170
+ f.each_line do |line|
186
171
  case line
187
- when %r[\A\#@end]
172
+ when /\A\#@end/
188
173
  @f.print line
189
- return
190
- when %r[\A//\}]
174
+ return nil
175
+ when %r{\A//\}}
191
176
  warn '//} seen in list'
192
177
  @f.print line
193
- return
194
- when %r[\A\#@\w]
178
+ return nil
179
+ when /\A\#@\w/
195
180
  warn "#{line.slice(/\A\#@\w+/)} seen in list"
196
181
  @f.print line
197
- when %r[\A\#@]
182
+ when /\A\#@/
198
183
  @f.print line
199
184
  end
200
185
  end
@@ -227,7 +212,7 @@ module ReVIEW
227
212
 
228
213
  def parse_directive(line, argc, *optdecl)
229
214
  m = /\A\#@(\w+)\((.*?)\)(?:\[(.*?)\])?\z/.match(line.strip) or
230
- error "wrong directive: #{line.strip}"
215
+ error "wrong directive: #{line.strip}"
231
216
  op = m[1]
232
217
  args = m[2].split(/,\s*/)
233
218
  opts = parse_optargs(m[3])
@@ -235,7 +220,7 @@ module ReVIEW
235
220
  if argc == -1
236
221
  # Any number of arguments are allowed.
237
222
  elsif args.size != argc
238
- error "wrong arg size"
223
+ error 'wrong arg size'
239
224
  end
240
225
  if opts
241
226
  wrong_opts = opts.keys - optdecl
@@ -250,7 +235,7 @@ module ReVIEW
250
235
  return nil unless str
251
236
  table = {}
252
237
  str.split(/,\s*/).each do |a|
253
- name, spec = a.split(/=/, 2)
238
+ name, spec = a.split('=', 2)
254
239
  table[name] = optarg_value(spec)
255
240
  end
256
241
  table
@@ -277,65 +262,59 @@ module ReVIEW
277
262
  end
278
263
 
279
264
  def expand(str)
280
- str.gsub(/\$\w+/) {|name|
265
+ str.gsub(/\$\w+/) do |name|
281
266
  s = @vartable[name.sub('$', '')]
282
267
  s ? expand(s) : name
283
- }
268
+ end
284
269
  end
285
270
 
286
271
  def unindent(chunk, n)
287
- n = minimum_indent(chunk) unless n.kind_of?(Integer)
272
+ n = minimum_indent(chunk) unless n.is_a?(Integer)
288
273
  re = /\A#{' ' * n}/
289
- chunk.map {|line| line.edit {|s| s.sub(re,'') } }
274
+ chunk.map { |line| line.edit { |s| s.sub(re, '') } }
290
275
  end
291
276
 
292
277
  INF_INDENT = 9999
293
278
 
294
279
  def minimum_indent(chunk)
295
- n = chunk.map {|line| line.empty? ? INF_INDENT : line.num_indent }.min
280
+ n = chunk.map { |line| line.empty? ? INF_INDENT : line.num_indent }.min
296
281
  n == INF_INDENT ? 0 : n
297
282
  end
298
283
 
299
284
  def evaluate(path, chunk)
300
- outputs = get_output("ruby #{path}", false).split(/\n/).map {|s| s.strip }
301
- chunk.map {|line|
285
+ outputs = get_output("ruby #{path}", false).split(/\n/).map(&:strip)
286
+ chunk.map do |line|
302
287
  if /\# \$\d+/ =~ line.string
303
288
  # map result into source.
304
- line.edit {|s|
305
- s.sub(/\$(\d+)/) { outputs[$1.to_i - 1] }
306
- }
289
+ line.edit { |s| s.sub(/\$(\d+)/) { outputs[$1.to_i - 1] } }
307
290
  else
308
291
  line
309
292
  end
310
- }
293
+ end
311
294
  end
312
295
 
313
296
  require 'open3'
314
297
 
315
298
  def get_output(cmd, use_stderr)
316
299
  out = err = nil
317
- Open3.popen3(cmd) {|stdin, stdout, stderr|
300
+ Open3.popen3(cmd) do |_stdin, stdout, stderr|
318
301
  out = stdout.readlines
319
302
  if use_stderr
320
303
  out.concat stderr.readlines
321
304
  else
322
305
  err = stderr.readlines
323
306
  end
324
- }
307
+ end
325
308
  if err and !err.empty?
326
- $stderr.puts "[unexpected stderr message]"
327
- err.each do |line|
328
- $stderr.print line
329
- end
330
- error "get_output: got unexpected output"
309
+ $stderr.puts '[unexpected stderr message]'
310
+ err.each { |line| $stderr.print line }
311
+ error 'get_output: got unexpected output'
331
312
  end
332
313
  num = 0
333
- out.map {|line| Line.new(num += 1, line) }
314
+ out.map { |line| Line.new(num += 1, line) }
334
315
  end
335
-
336
316
  end
337
317
 
338
-
339
318
  class Line
340
319
  def initialize(number, string)
341
320
  @number = number
@@ -359,15 +338,14 @@ module ReVIEW
359
338
  end
360
339
  end
361
340
 
362
-
363
341
  class Repository
364
-
365
342
  include TextUtils
366
343
  include ErrorUtils
367
344
 
368
345
  def initialize(param)
369
346
  @repository = {}
370
347
  @config = param
348
+ @logger = ReVIEW.logger
371
349
  end
372
350
 
373
351
  def fetch_file(file)
@@ -397,22 +375,22 @@ module ReVIEW
397
375
 
398
376
  def parse_git_blob(g_obj)
399
377
  IO.popen('git show ' + g_obj.sub(/\Agit\|/, ''), 'r') do |f|
400
- init_ErrorUtils f
378
+ init_errorutils f
401
379
  return _parse_file(f)
402
380
  end
403
381
  end
404
382
 
405
383
  def parse_file(fname)
406
- File.open(fname, 'r:BOM|utf-8') {|f|
407
- init_ErrorUtils f
384
+ File.open(fname, 'r:BOM|utf-8') do |f|
385
+ init_errorutils f
408
386
  return _parse_file(f)
409
- }
387
+ end
410
388
  end
411
389
 
412
390
  def _parse_file(f)
413
391
  whole = []
414
- repo = {'file' => whole}
415
- curr = {'WHOLE' => whole}
392
+ repo = { 'file' => whole }
393
+ curr = { 'WHOLE' => whole }
416
394
  lineno = 1
417
395
  yacchack = false # remove ';'-only lines.
418
396
  opened = [['(not opened)', '(not opened)']] * 3
@@ -430,12 +408,12 @@ module ReVIEW
430
408
  (repo[type] ||= {})[spec] = curr[key] = []
431
409
  when 'end'
432
410
  curr.delete("#{type}/#{spec}") or
433
- error "end before begin: #{type}/#{spec}"
411
+ error "end before begin: #{type}/#{spec}"
434
412
  else
435
413
  raise 'must not happen'
436
414
  end
437
415
 
438
- when %r<(?:\A\#@|\#@@)([a-z]+)/(\w+)\{>
416
+ when %r{(?:\A\#@|\#@@)([a-z]+)/(\w+)\{}
439
417
  type = check_type($1)
440
418
  spec = check_spec($2)
441
419
  key = "#{type}/#{spec}"
@@ -443,17 +421,17 @@ module ReVIEW
443
421
  (repo[type] ||= {})[spec] = curr[key] = []
444
422
  opened.push [type, spec]
445
423
 
446
- when %r<(?:\A\#@|\#@@)([a-z]+)/(\w+)\}>
424
+ when %r{(?:\A\#@|\#@@)([a-z]+)/(\w+)\}}
447
425
  type = check_type($1)
448
426
  spec = check_spec($2)
449
427
  curr.delete("#{type}/#{spec}") or
450
- error "end before begin: #{type}/#{spec}"
428
+ error "end before begin: #{type}/#{spec}"
451
429
  opened.delete "#{type}/#{spec}"
452
430
 
453
- when %r<(?:\A\#@|\#@@)\}>
431
+ when /(?:\A\#@|\#@@)\}/
454
432
  type, spec = opened.last
455
433
  curr.delete("#{type}/#{spec}") or
456
- error "closed before open: #{type}/#{spec}"
434
+ error "closed before open: #{type}/#{spec}"
457
435
  opened.pop
458
436
 
459
437
  when /(?:\A\#@|\#@@)yacchack/
@@ -461,35 +439,26 @@ module ReVIEW
461
439
 
462
440
  when /\A\#@-/ # does not increment line number.
463
441
  line = canonical($')
464
- curr.each_value do |list|
465
- list.push Line.new(nil, line)
466
- end
442
+ curr.each_value { |list| list.push Line.new(nil, line) }
467
443
 
468
444
  else
469
445
  next if yacchack and line.strip == ';'
470
446
  line = canonical(line)
471
- curr.each_value do |list|
472
- list.push Line.new(lineno, line)
473
- end
447
+ curr.each_value { |list| list.push Line.new(lineno, line) }
474
448
  lineno += 1
475
449
  end
476
450
  end
477
451
  if curr.size > 1
478
452
  curr.delete 'WHOLE'
479
- curr.each do |range, lines|
480
- $stderr.puts "#{filename()}: unclosed range: #{range} (begin @#{lines.first.number})"
481
- end
482
- raise ApplicationError, "ERROR"
453
+ curr.each { |range, lines| @logger.warn "#{filename}: unclosed range: #{range} (begin @#{lines.first.number})" }
454
+ raise ApplicationError, 'ERROR'
483
455
  end
484
456
 
485
457
  repo
486
458
  end
487
459
 
488
460
  def canonical(line)
489
- tabwidth = 8
490
- if @config['tabwidth']
491
- tabwidth = @config['tabwidth']
492
- end
461
+ tabwidth = @config['tabwidth'] || 8
493
462
  if tabwidth > 0
494
463
  detab(line, tabwidth).rstrip + "\n"
495
464
  else
@@ -498,19 +467,13 @@ module ReVIEW
498
467
  end
499
468
 
500
469
  def check_type(type)
501
- unless Preprocessor::TYPES.index(type)
502
- error "wrong type: #{type.inspect}"
503
- end
470
+ error "wrong type: #{type.inspect}" unless Preprocessor::TYPES.index(type)
504
471
  type
505
472
  end
506
473
 
507
474
  def check_spec(spec)
508
- unless /\A\w+\z/ =~ spec
509
- error "wrong spec: #{spec.inspect}"
510
- end
475
+ error "wrong spec: #{spec.inspect}" unless /\A\w+\z/ =~ spec
511
476
  spec
512
477
  end
513
-
514
478
  end
515
-
516
479
  end
@@ -1,7 +1,5 @@
1
- # encoding: utf-8
2
-
3
- # Copyright (c) 2002-2006 Minero Aoki
4
- # 2008-2017 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2006 Minero Aoki
5
3
  #
6
4
  # This program is free software.
7
5
  # You can distribute or modify this program under the terms of
@@ -12,7 +10,6 @@ require 'review/builder'
12
10
  require 'review/textutils'
13
11
 
14
12
  module ReVIEW
15
-
16
13
  #
17
14
  # RSTBuilder is a builder for reStructuredText (http://docutils.sourceforge.net/rst.html).
18
15
  # reStructuredText is used in Sphinx (http://www.sphinx-doc.org/).
@@ -21,12 +18,9 @@ module ReVIEW
21
18
  # package (https://pypi.python.org/pypi/sphinxcontrib-textstyle).
22
19
  #
23
20
  class RSTBuilder < Builder
24
-
25
21
  include TextUtils
26
22
 
27
- [:ttbold, :hint, :maru, :keytop, :labelref, :ref, :pageref, :balloon, :strong].each {|e|
28
- Compiler.definline(e)
29
- }
23
+ %i[ttbold hint maru keytop labelref ref balloon strong].each { |e| Compiler.definline(e) }
30
24
  Compiler.defsingle(:dtp, 1)
31
25
 
32
26
  Compiler.defblock(:insn, 1)
@@ -50,7 +44,7 @@ module ReVIEW
50
44
  end
51
45
 
52
46
  def image_ext
53
- "png"
47
+ 'png'
54
48
  end
55
49
 
56
50
  def extname
@@ -93,39 +87,31 @@ module ReVIEW
93
87
  @output.string
94
88
  end
95
89
 
96
- def warn(msg)
97
- $stderr.puts "#{@location.filename}:#{@location.lineno}: warning: #{msg}"
98
- end
99
-
100
- def error(msg)
101
- $stderr.puts "#{@location.filename}:#{@location.lineno}: error: #{msg}"
102
- end
103
-
104
90
  def headline(level, label, caption)
105
91
  blank
106
92
  if label
107
93
  puts ".. _#{label}:"
108
94
  blank
109
95
  end
110
- p = "="
96
+ p = '='
111
97
  case level
112
98
  when 1 then
113
99
  unless label
114
100
  puts ".. _#{@chapter.name}:"
115
101
  blank
116
102
  end
117
- puts "=" * caption.size * 2
103
+ puts '=' * caption.size * 2
118
104
  when 2 then
119
- p = "="
105
+ p = '='
120
106
  when 3 then
121
- p = "-"
107
+ p = '-'
122
108
  when 4 then
123
- p = "`"
109
+ p = '`'
124
110
  when 5 then
125
- p = "~"
111
+ p = '~'
126
112
  end
127
113
 
128
- puts "#{caption}"
114
+ puts caption
129
115
  puts p * caption.size * 2
130
116
  blank
131
117
  end
@@ -136,7 +122,7 @@ module ReVIEW
136
122
  end
137
123
 
138
124
  def ul_item(lines)
139
- puts " " * (@ul_indent - 1) + "* #{lines.join}"
125
+ puts ' ' * (@ul_indent - 1) + "* #{lines.join}"
140
126
  end
141
127
 
142
128
  def ul_end
@@ -149,8 +135,8 @@ module ReVIEW
149
135
  @ol_indent += 1
150
136
  end
151
137
 
152
- def ol_item(lines, num)
153
- puts " " * (@ol_indent - 1) + "#. #{lines.join}"
138
+ def ol_item(lines, _num)
139
+ puts ' ' * (@ol_indent - 1) + "#. #{lines.join}"
154
140
  end
155
141
 
156
142
  def ol_end
@@ -162,56 +148,50 @@ module ReVIEW
162
148
  end
163
149
 
164
150
  def dt(line)
165
- puts "#{line}"
151
+ puts line
166
152
  end
167
153
 
168
154
  def dd(lines)
169
- split_paragraph(lines).each do |paragraph|
170
- puts " #{paragraph.gsub(/\n/, '')}"
171
- end
155
+ split_paragraph(lines).each { |paragraph| puts " #{paragraph.gsub(/\n/, '')}" }
172
156
  end
173
157
 
174
158
  def dl_end
175
159
  end
176
160
 
177
161
  def paragraph(lines)
178
- pre = ""
179
- if @in_role == true
180
- pre = " "
181
- end
162
+ pre = ''
163
+ pre = ' ' if @in_role == true
182
164
  puts pre + lines.join
183
165
  puts "\n"
184
166
  end
185
167
 
186
168
  def read(lines)
187
- puts split_paragraph(lines).map{|line| " #{line}"}.join("")
169
+ puts split_paragraph(lines).map { |line| " #{line}" }.join
188
170
  blank
189
171
  end
190
172
 
191
173
  alias_method :lead, :read
192
174
 
193
175
  def hr
194
- puts "----"
176
+ puts '----'
195
177
  end
196
178
 
197
179
  def inline_list(id)
198
180
  " :numref:`#{id}` "
199
181
  end
200
182
 
201
- def list_header(id, caption, lang)
183
+ def list_header(id, _caption, _lang)
202
184
  puts ".. _#{id}:"
203
185
  blank
204
186
  end
205
187
 
206
- def list_body(id, lines, lang)
207
- lines.each do |line|
208
- puts '-' + detab(line)
209
- end
188
+ def list_body(_id, lines, _lang)
189
+ lines.each { |line| puts '-' + detab(line) }
210
190
  end
211
191
 
212
- def base_block(type, lines, caption = nil)
192
+ def base_block(_type, lines, caption = nil)
213
193
  blank
214
- puts "#{compile_inline(caption)}" unless caption.nil?
194
+ puts compile_inline(caption) unless caption.nil?
215
195
  puts lines.join("\n")
216
196
  blank
217
197
  end
@@ -220,7 +200,7 @@ module ReVIEW
220
200
  puts ".. #{type}::"
221
201
  blank
222
202
  puts " #{compile_inline(caption)}" unless caption.nil?
223
- puts " " + split_paragraph(lines).join("\n")
203
+ puts ' ' + split_paragraph(lines).join("\n")
224
204
  blank
225
205
  end
226
206
 
@@ -230,12 +210,10 @@ module ReVIEW
230
210
  puts caption
231
211
  print "\n"
232
212
  end
233
- lang ||= "none"
213
+ lang ||= 'none'
234
214
  puts ".. code-block:: #{lang}"
235
215
  blank
236
- lines.each do |line|
237
- puts " " + detab(line)
238
- end
216
+ lines.each { |line| puts ' ' + detab(line) }
239
217
  blank
240
218
  end
241
219
 
@@ -245,33 +223,27 @@ module ReVIEW
245
223
  puts caption
246
224
  print "\n"
247
225
  end
248
- lang ||= "none"
226
+ lang ||= 'none'
249
227
  puts ".. code-block:: #{lang}"
250
- puts " :linenos:"
228
+ puts ' :linenos:'
251
229
  blank
252
- lines.each do |line|
253
- puts " " + detab(line)
254
- end
230
+ lines.each { |line| puts ' ' + detab(line) }
255
231
  blank
256
232
  end
257
233
 
258
- def listnum_body(lines, lang)
259
- lines.each_with_index do |line, i|
260
- puts(i + 1).to_s.rjust(2) + ": #{line}"
261
- end
234
+ def listnum_body(lines, _lang)
235
+ lines.each_with_index { |line, i| puts(i + 1).to_s.rjust(2) + ": #{line}" }
262
236
  blank
263
237
  end
264
238
 
265
- def cmd(lines, caption = nil)
266
- puts ".. code-block:: bash"
267
- lines.each do |line|
268
- puts " " + detab(line)
269
- end
239
+ def cmd(lines, _caption = nil)
240
+ puts '.. code-block:: bash'
241
+ lines.each { |line| puts ' ' + detab(line) }
270
242
  end
271
243
 
272
244
  def quote(lines)
273
245
  blank
274
- puts lines.map{|line| " #{line}"}.join("")
246
+ puts lines.map { |line| " #{line}" }.join
275
247
  blank
276
248
  end
277
249
 
@@ -285,9 +257,7 @@ module ReVIEW
285
257
 
286
258
  def image_image(id, caption, metric)
287
259
  chapter, id = extract_chapter_id(id)
288
- if metric
289
- scale = metric.split("=")[1].to_f * 100
290
- end
260
+ scale = metric.split('=')[1].to_f * 100 if metric
291
261
 
292
262
  puts ".. _#{id}:"
293
263
  blank
@@ -310,9 +280,9 @@ module ReVIEW
310
280
  end
311
281
 
312
282
  def texequation(lines)
313
- puts ".. math::"
283
+ puts '.. math::'
314
284
  blank
315
- puts lines.map{|line| " #{line}"}.join("")
285
+ puts lines.map { |line| " #{line}" }.join
316
286
  blank
317
287
  end
318
288
 
@@ -323,7 +293,7 @@ module ReVIEW
323
293
  end
324
294
  blank
325
295
  puts ".. list-table:: #{compile_inline(caption)}"
326
- puts " :header-rows: 1"
296
+ puts ' :header-rows: 1'
327
297
  blank
328
298
  end
329
299
 
@@ -332,14 +302,14 @@ module ReVIEW
332
302
 
333
303
  def tr(rows)
334
304
  first = true
335
- rows.each{|row|
305
+ rows.each do |row|
336
306
  if first
337
307
  puts " * - #{row}"
338
308
  first = false
339
309
  else
340
310
  puts " - #{row}"
341
311
  end
342
- }
312
+ end
343
313
  end
344
314
 
345
315
  def th(str)
@@ -358,17 +328,17 @@ module ReVIEW
358
328
  table(lines, nil, caption)
359
329
  end
360
330
 
361
- def comment(lines, comment = nil)
362
- puts lines.map{|line| " .. #{line}"}.join("")
331
+ def comment(lines, _comment = nil)
332
+ puts lines.map { |line| " .. #{line}" }.join
363
333
  end
364
334
 
365
335
  def footnote(id, str)
366
- puts ".. [##{id.sub(" ", "_")}] #{compile_inline(str)}"
336
+ puts ".. [##{id.sub(' ', '_')}] #{compile_inline(str)}"
367
337
  blank
368
338
  end
369
339
 
370
340
  def inline_fn(id)
371
- " [##{id.sub(" ", "_")}]_ "
341
+ " [##{id.sub(' ', '_')}]_ "
372
342
  end
373
343
 
374
344
  def compile_ruby(base, ruby)
@@ -388,19 +358,19 @@ module ReVIEW
388
358
  end
389
359
 
390
360
  def inline_sup(str)
391
- " :superscript:`str` "
361
+ " :superscript:`#{str}` "
392
362
  end
393
363
 
394
364
  def inline_sub(str)
395
- " :subscript:`str` "
365
+ " :subscript:`#{str}` "
396
366
  end
397
367
 
398
368
  def inline_raw(str)
399
369
  matched = str.match(/\|(.*?)\|(.*)/)
400
370
  if matched
401
- matched[2].gsub("\\n", "\n")
371
+ matched[2].gsub('\\n', "\n")
402
372
  else
403
- str.gsub("\\n", "\n")
373
+ str.gsub('\\n', "\n")
404
374
  end
405
375
  end
406
376
 
@@ -428,11 +398,11 @@ module ReVIEW
428
398
  end
429
399
 
430
400
  def inline_i(str)
431
- " *#{str.gsub(/\*/, '\*')}* "
401
+ " *#{str.gsub('*', '\*')}* "
432
402
  end
433
403
 
434
404
  def inline_b(str)
435
- " **#{str.gsub(/\*/, '\*')}** "
405
+ " **#{str.gsub('*', '\*')}** "
436
406
  end
437
407
 
438
408
  alias_method :inline_strong, :inline_b
@@ -447,7 +417,7 @@ module ReVIEW
447
417
  alias_method :inline_ttbold, :inline_ttb
448
418
 
449
419
  def inline_u(str)
450
- " :subscript:`str` "
420
+ " :subscript:`#{str}` "
451
421
  end
452
422
 
453
423
  def inline_icon(id)
@@ -469,14 +439,14 @@ module ReVIEW
469
439
  end
470
440
 
471
441
  def inline_uchar(str)
472
- [str.to_i(16)].pack("U")
442
+ [str.to_i(16)].pack('U')
473
443
  end
474
444
 
475
445
  def inline_comment(str)
476
- if @book.config["draft"]
477
- "#{str}"
446
+ if @book.config['draft']
447
+ str
478
448
  else
479
- ""
449
+ ''
480
450
  end
481
451
  end
482
452
 
@@ -484,7 +454,7 @@ module ReVIEW
484
454
  " :math:`#{str}` "
485
455
  end
486
456
 
487
- def inline_hd_chap(chap, id)
457
+ def inline_hd_chap(_chap, id)
488
458
  " :ref:`#{id}` "
489
459
  end
490
460
 
@@ -492,7 +462,7 @@ module ReVIEW
492
462
  # TODO
493
463
  end
494
464
 
495
- def nonum_begin(level, label, caption)
465
+ def nonum_begin(_level, _label, caption)
496
466
  puts ".. rubric: #{compile_inline(caption)}"
497
467
  blank
498
468
  end
@@ -500,169 +470,169 @@ module ReVIEW
500
470
  def nonum_end(level)
501
471
  end
502
472
 
503
- def common_column_begin(type, caption)
473
+ def common_column_begin(_type, caption)
504
474
  blank
505
475
  puts ".. column:: #{compile_inline(caption)}"
506
476
  blank
507
477
  @in_role = true
508
478
  end
509
479
 
510
- def common_column_end(type)
480
+ def common_column_end(_type)
511
481
  @in_role = false
512
482
  blank
513
483
  end
514
484
 
515
- def column_begin(level, label, caption)
516
- common_column_begin("column", caption)
485
+ def column_begin(_level, _label, caption)
486
+ common_column_begin('column', caption)
517
487
  end
518
488
 
519
- def column_end(level)
520
- common_column_end("column")
489
+ def column_end(_level)
490
+ common_column_end('column')
521
491
  end
522
492
 
523
- def xcolumn_begin(level, label, caption)
524
- common_column_begin("xcolumn", caption)
493
+ def xcolumn_begin(_level, _label, caption)
494
+ common_column_begin('xcolumn', caption)
525
495
  end
526
496
 
527
- def xcolumn_end(level)
528
- common_column_end("xcolumn")
497
+ def xcolumn_end(_level)
498
+ common_column_end('xcolumn')
529
499
  end
530
500
 
531
- def world_begin(level, label, caption)
532
- common_column_begin("world", caption)
501
+ def world_begin(_level, _label, caption)
502
+ common_column_begin('world', caption)
533
503
  end
534
504
 
535
- def world_end(level)
536
- common_column_end("world")
505
+ def world_end(_level)
506
+ common_column_end('world')
537
507
  end
538
508
 
539
- def hood_begin(level, label, caption)
540
- common_column_begin("hood", caption)
509
+ def hood_begin(_level, _label, caption)
510
+ common_column_begin('hood', caption)
541
511
  end
542
512
 
543
- def hood_end(level)
544
- common_column_end("hood")
513
+ def hood_end(_level)
514
+ common_column_end('hood')
545
515
  end
546
516
 
547
- def edition_begin(level, label, caption)
548
- common_column_begin("edition", caption)
517
+ def edition_begin(_level, _label, caption)
518
+ common_column_begin('edition', caption)
549
519
  end
550
520
 
551
- def edition_end(level)
552
- common_column_end("edition")
521
+ def edition_end(_level)
522
+ common_column_end('edition')
553
523
  end
554
524
 
555
- def insideout_begin(level, label, caption)
556
- common_column_begin("insideout", caption)
525
+ def insideout_begin(_level, _label, caption)
526
+ common_column_begin('insideout', caption)
557
527
  end
558
528
 
559
- def insideout_end(level)
560
- common_column_end("insideout")
529
+ def insideout_end(_level)
530
+ common_column_end('insideout')
561
531
  end
562
532
 
563
- def ref_begin(level, label, caption)
564
- common_column_begin("ref", caption)
533
+ def ref_begin(_level, _label, caption)
534
+ common_column_begin('ref', caption)
565
535
  end
566
536
 
567
- def ref_end(level)
568
- common_column_end("ref")
537
+ def ref_end(_level)
538
+ common_column_end('ref')
569
539
  end
570
540
 
571
- def sup_begin(level, label, caption)
572
- common_column_begin("sup", caption)
541
+ def sup_begin(_level, _label, caption)
542
+ common_column_begin('sup', caption)
573
543
  end
574
544
 
575
- def sup_end(level)
576
- common_column_end("sup")
545
+ def sup_end(_level)
546
+ common_column_end('sup')
577
547
  end
578
548
 
579
549
  def flushright(lines)
580
- base_parablock "flushright", lines, nil
550
+ base_parablock 'flushright', lines, nil
581
551
  end
582
552
 
583
553
  def centering(lines)
584
- base_parablock "centering", lines, nil
554
+ base_parablock 'centering', lines, nil
585
555
  end
586
556
 
587
557
  def note(lines, caption = nil)
588
- base_parablock "note", lines, caption
558
+ base_parablock 'note', lines, caption
589
559
  end
590
560
 
591
561
  def memo(lines, caption = nil)
592
- base_parablock "memo", lines, caption
562
+ base_parablock 'memo', lines, caption
593
563
  end
594
564
 
595
565
  def tip(lines, caption = nil)
596
- base_parablock "tip", lines, caption
566
+ base_parablock 'tip', lines, caption
597
567
  end
598
568
 
599
569
  def info(lines, caption = nil)
600
- base_parablock "info", lines, caption
570
+ base_parablock 'info', lines, caption
601
571
  end
602
572
 
603
573
  def planning(lines, caption = nil)
604
- base_parablock "planning", lines, caption
574
+ base_parablock 'planning', lines, caption
605
575
  end
606
576
 
607
577
  def best(lines, caption = nil)
608
- base_parablock "best", lines, caption
578
+ base_parablock 'best', lines, caption
609
579
  end
610
580
 
611
581
  def important(lines, caption = nil)
612
- base_parablock "important", lines, caption
582
+ base_parablock 'important', lines, caption
613
583
  end
614
584
 
615
585
  def security(lines, caption = nil)
616
- base_parablock "security", lines, caption
586
+ base_parablock 'security', lines, caption
617
587
  end
618
588
 
619
589
  def caution(lines, caption = nil)
620
- base_parablock "caution", lines, caption
590
+ base_parablock 'caution', lines, caption
621
591
  end
622
592
 
623
593
  def term(lines)
624
- base_parablock "term", lines, nil
594
+ base_parablock 'term', lines, nil
625
595
  end
626
596
 
627
597
  def link(lines, caption = nil)
628
- base_parablock "link", lines, caption
598
+ base_parablock 'link', lines, caption
629
599
  end
630
600
 
631
601
  def notice(lines, caption = nil)
632
- base_parablock "notice", lines, caption
602
+ base_parablock 'notice', lines, caption
633
603
  end
634
604
 
635
605
  def point(lines, caption = nil)
636
- base_parablock "point", lines, caption
606
+ base_parablock 'point', lines, caption
637
607
  end
638
608
 
639
609
  def shoot(lines, caption = nil)
640
- base_parablock "shoot", lines, caption
610
+ base_parablock 'shoot', lines, caption
641
611
  end
642
612
 
643
613
  def reference(lines)
644
- base_parablock "reference", lines, nil
614
+ base_parablock 'reference', lines, nil
645
615
  end
646
616
 
647
617
  def practice(lines)
648
- base_parablock "practice", lines, nil
618
+ base_parablock 'practice', lines, nil
649
619
  end
650
620
 
651
621
  def expert(lines)
652
- base_parablock "expert", lines, nil
622
+ base_parablock 'expert', lines, nil
653
623
  end
654
624
 
655
625
  def insn(lines, caption = nil)
656
- base_block "insn", lines, caption
626
+ base_block 'insn', lines, caption
657
627
  end
658
628
 
659
629
  def warning(lines, caption = nil)
660
- base_parablock "warning", lines, caption
630
+ base_parablock 'warning', lines, caption
661
631
  end
662
632
 
663
633
  alias_method :box, :insn
664
634
 
665
- def indepimage(id, caption = "", metric = nil)
635
+ def indepimage(_lines, id, caption = '', _metric = nil)
666
636
  chapter, id = extract_chapter_id(id)
667
637
  puts ".. _#{id}:"
668
638
  blank
@@ -684,23 +654,23 @@ module ReVIEW
684
654
  end
685
655
 
686
656
  def bpo(lines)
687
- base_block "bpo", lines, nil
657
+ base_block 'bpo', lines, nil
688
658
  end
689
659
 
690
- def inline_dtp(str)
691
- ""
660
+ def inline_dtp(_str)
661
+ ''
692
662
  end
693
663
 
694
664
  def inline_del(str)
695
- " :del:`str` "
665
+ " :del:`#{str}` "
696
666
  end
697
667
 
698
668
  def inline_code(str)
699
669
  " :code:`#{str}` "
700
670
  end
701
671
 
702
- def inline_br(str)
703
- %Q(\n)
672
+ def inline_br(_str)
673
+ "\n"
704
674
  end
705
675
 
706
676
  def text(str)
@@ -715,8 +685,8 @@ module ReVIEW
715
685
  " :numref:`#{id}` "
716
686
  end
717
687
 
718
- def source(lines, caption = nil, lang = nil)
719
- base_block "source", lines, caption
688
+ def source(lines, caption = nil, _lang = nil)
689
+ base_block 'source', lines, caption
720
690
  end
721
691
 
722
692
  def inline_ttibold(str)
@@ -733,7 +703,7 @@ module ReVIEW
733
703
  " :ref:`#{idref}` "
734
704
  end
735
705
 
736
- def circle_begin(level, label, caption)
706
+ def circle_begin(_level, _label, caption)
737
707
  puts "・\t#{caption}"
738
708
  end
739
709
 
@@ -753,7 +723,7 @@ module ReVIEW
753
723
  end
754
724
 
755
725
  def bibpaper_bibpaper(id, caption, lines)
756
- puts ".. [#{id}] #{compile_inline(caption)} #{split_paragraph(lines).join("")}"
726
+ puts ".. [#{id}] #{compile_inline(caption)} #{split_paragraph(lines).join}"
757
727
  end
758
728
 
759
729
  def inline_warn(str)
@@ -763,7 +733,5 @@ module ReVIEW
763
733
  def inline_bib(id)
764
734
  " [#{id}]_ "
765
735
  end
766
-
767
736
  end
768
-
769
737
  end # module ReVIEW