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,8 +1,5 @@
1
- #
2
- # $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
3
- #
4
- # Copyright (c) 2002-2008 Minero Aoki
5
- # 2009 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2008 Minero Aoki
6
3
  #
7
4
  # This program is free software.
8
5
  # You can distribute or modify this program under the terms of
@@ -22,7 +19,7 @@ require 'review/book/index'
22
19
  module ReVIEW
23
20
  @default_book = nil
24
21
 
25
- def ReVIEW.book
22
+ def self.book
26
23
  @default_book ||= Book::Base.load
27
24
  end
28
25
 
@@ -1,6 +1,6 @@
1
1
  #
2
- # Copyright (c) 2002-2008 Minero Aoki
3
- # 2009-2017 Minero Aoki, Kenshi Muto
2
+ # Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
3
+ # 2002-2008 Minero Aoki
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -13,18 +13,17 @@ require 'review/catalog'
13
13
  module ReVIEW
14
14
  module Book
15
15
  class Base
16
-
17
16
  attr_writer :config
18
17
  attr_writer :parts
19
18
  attr_writer :catalog
20
19
  attr_reader :basedir
21
20
 
22
21
  def self.load_default
23
- warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().'
24
- load()
22
+ ReVIEW.logger.warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().'
23
+ load
25
24
  end
26
25
 
27
- def self.load(dir = ".")
26
+ def self.load(dir = '.')
28
27
  update_rubyenv dir
29
28
  new(dir)
30
29
  end
@@ -34,8 +33,8 @@ module ReVIEW
34
33
  def self.update_rubyenv(dir)
35
34
  return if @basedir_seen.key?(dir)
36
35
  if File.file?("#{dir}/review-ext.rb")
37
- if ENV["REVIEW_SAFE_MODE"].to_i & 2 > 0
38
- warn "review-ext.rb is prohibited in safe mode. ignored."
36
+ if ENV['REVIEW_SAFE_MODE'].to_i & 2 > 0
37
+ ReVIEW.logger.warn 'review-ext.rb is prohibited in safe mode. ignored.'
39
38
  else
40
39
  Kernel.load File.expand_path("#{dir}/review-ext.rb")
41
40
  end
@@ -58,59 +57,57 @@ module ReVIEW
58
57
  end
59
58
 
60
59
  def bib_file
61
- config["bib_file"]
60
+ config['bib_file']
62
61
  end
63
62
 
64
63
  def reject_file
65
- config["reject_file"]
64
+ config['reject_file']
66
65
  end
67
66
 
68
67
  def ext
69
- config["ext"]
68
+ config['ext']
70
69
  end
71
70
 
72
71
  def image_dir
73
- config["image_dir"]
72
+ config['image_dir']
74
73
  end
75
74
 
76
75
  def image_types
77
- config["image_types"]
76
+ config['image_types']
78
77
  end
79
78
 
80
79
  def image_types=(types)
81
- config["image_types"] = types
80
+ config['image_types'] = types
82
81
  end
83
82
 
84
83
  def page_metric
85
- if config["page_metric"].respond_to?(:downcase) && config["page_metric"].upcase =~ /^[A-Z0-9_]+$/
86
- ReVIEW::Book::PageMetric.const_get(config["page_metric"].upcase)
87
- elsif config["page_metric"].kind_of?(Array) && config["page_metric"].size == 5
88
- ReVIEW::Book::PageMetric.new(*config["page_metric"])
84
+ if config['page_metric'].respond_to?(:downcase) && config['page_metric'].upcase =~ /\A[A-Z0-9_]+\Z/
85
+ ReVIEW::Book::PageMetric.const_get(config['page_metric'].upcase)
86
+ elsif config['page_metric'].is_a?(Array) && config['page_metric'].size == 5
87
+ ReVIEW::Book::PageMetric.new(*config['page_metric'])
89
88
  else
90
- config["page_metric"]
89
+ config['page_metric']
91
90
  end
92
91
  end
93
92
 
94
93
  def htmlversion
95
- if config["htmlversion"].blank?
94
+ if config['htmlversion'].blank?
96
95
  nil
97
96
  else
98
- config["htmlversion"].to_i
97
+ config['htmlversion'].to_i
99
98
  end
100
99
  end
101
100
 
102
101
  def parts
103
- @parts ||= read_parts()
102
+ @parts ||= read_parts
104
103
  end
105
104
 
106
105
  def parts_in_file
107
- parts.find_all{|part|
108
- part if part.present? and part.file?
109
- }
106
+ parts.find_all { |part| part if part.present? and part.file? }
110
107
  end
111
108
 
112
109
  def part(n)
113
- parts.detect {|part| part.number == n }
110
+ parts.detect { |part| part.number == n }
114
111
  end
115
112
 
116
113
  def each_part(&block)
@@ -127,7 +124,7 @@ module ReVIEW
127
124
  end
128
125
 
129
126
  def chapters
130
- parts().map {|p| p.chapters }.flatten
127
+ parts.map(&:chapters).flatten
131
128
  end
132
129
 
133
130
  def each_chapter(&block)
@@ -141,17 +138,13 @@ module ReVIEW
141
138
  def chapter_index
142
139
  return @chapter_index if @chapter_index
143
140
 
144
- contents = chapters()
145
- parts().each do |prt|
146
- if prt.id.present?
147
- contents << prt
148
- end
149
- end
141
+ contents = chapters
142
+ parts.each { |prt| contents << prt if prt.id.present? }
150
143
  @chapter_index = ChapterIndex.new(contents)
151
144
  end
152
145
 
153
146
  def chapter(id)
154
- chapter_index()[id]
147
+ chapter_index[id]
155
148
  end
156
149
 
157
150
  def next_chapter(chapter)
@@ -173,7 +166,7 @@ module ReVIEW
173
166
  end
174
167
 
175
168
  def volume
176
- vol = Volume.sum(chapters.map {|chap| chap.volume })
169
+ vol = Volume.sum(chapters.map(&:volume))
177
170
  vol.page_per_kbyte = page_metric.page_per_kbyte
178
171
  vol
179
172
  end
@@ -190,53 +183,50 @@ module ReVIEW
190
183
  def catalog
191
184
  return @catalog if @catalog.present?
192
185
 
193
- catalogfile_path = "#{basedir}/#{config["catalogfile"]}"
194
- if File.file? catalogfile_path
195
- @catalog = File.open(catalogfile_path){|f| Catalog.new(f) }
196
- end
197
-
186
+ catalogfile_path = "#{basedir}/#{config['catalogfile']}"
187
+ @catalog = File.open(catalogfile_path) { |f| Catalog.new(f) } if File.file? catalogfile_path
198
188
  @catalog
199
189
  end
200
190
 
201
- def read_CHAPS
191
+ def read_chaps
202
192
  if catalog
203
193
  catalog.chaps
204
194
  else
205
- read_FILE(config["chapter_file"])
195
+ read_file(config['chapter_file'])
206
196
  end
207
197
  end
208
198
 
209
- def read_PREDEF
199
+ def read_predef
210
200
  if catalog
211
201
  catalog.predef
212
202
  else
213
- read_FILE(config["predef_file"])
203
+ read_file(config['predef_file'])
214
204
  end
215
205
  end
216
206
 
217
- def read_APPENDIX
207
+ def read_appendix
218
208
  if catalog
219
209
  catalog.appendix
220
210
  else
221
- read_FILE(config["postdef_file"]) # for backward compatibility
211
+ read_file(config['postdef_file']) # for backward compatibility
222
212
  end
223
213
  end
224
214
 
225
- def read_POSTDEF
215
+ def read_postdef
226
216
  if catalog
227
217
  catalog.postdef
228
218
  else
229
- ""
219
+ ''
230
220
  end
231
221
  end
232
222
 
233
- def read_PART
223
+ def read_part
234
224
  return @read_part if @read_part
235
225
 
236
226
  if catalog
237
227
  @read_part = catalog.parts
238
228
  else
239
- @read_part = File.read("#{@basedir}/#{config["part_file"]}")
229
+ @read_part = File.read("#{@basedir}/#{config['part_file']}")
240
230
  end
241
231
  end
242
232
 
@@ -244,7 +234,7 @@ module ReVIEW
244
234
  if catalog
245
235
  catalog.parts.present?
246
236
  else
247
- File.exist?("#{@basedir}/#{config["part_file"]}")
237
+ File.exist?("#{@basedir}/#{config['part_file']}")
248
238
  end
249
239
  end
250
240
 
@@ -257,47 +247,38 @@ module ReVIEW
257
247
  end
258
248
 
259
249
  def prefaces
260
- if catalog
261
- return mkpart_from_namelist(catalog.predef.split("\n"))
262
- end
250
+ return mkpart_from_namelist(catalog.predef.split("\n")) if catalog
263
251
 
264
- if File.file?("#{@basedir}/#{config["predef_file"]}")
265
- begin
266
- return mkpart_from_namelistfile("#{@basedir}/#{config["predef_file"]}")
267
- rescue FileNotFound => err
268
- raise FileNotFound, "preface #{err.message}"
269
- end
252
+ begin
253
+ mkpart_from_namelistfile("#{@basedir}/#{config['predef_file']}") if File.file?("#{@basedir}/#{config['predef_file']}")
254
+ rescue FileNotFound => err
255
+ raise FileNotFound, "preface #{err.message}"
270
256
  end
271
257
  end
272
258
 
273
259
  def appendix
274
260
  if catalog
275
261
  names = catalog.appendix.split("\n")
276
- chaps = names.each_with_index.map {|n, idx|
277
- mkchap_ifexist(n, idx)
278
- }.compact
262
+ chaps = names.each_with_index.map { |n, idx| mkchap_ifexist(n, idx) }.compact
279
263
  return mkpart(chaps)
280
264
  end
281
265
 
282
- if File.file?("#{@basedir}/#{config["postdef_file"]}")
283
- begin
284
- return mkpart_from_namelistfile("#{@basedir}/#{config["postdef_file"]}")
285
- rescue FileNotFound => err
286
- raise FileNotFound, "postscript #{err.message}"
287
- end
266
+ begin
267
+ mkpart_from_namelistfile("#{@basedir}/#{config['postdef_file']}") if File.file?("#{@basedir}/#{config['postdef_file']}")
268
+ rescue FileNotFound => err
269
+ raise FileNotFound, "postscript #{err.message}"
288
270
  end
289
271
  end
290
272
 
291
273
  def postscripts
292
- if catalog
293
- mkpart_from_namelist(catalog.postdef.split("\n"))
294
- end
274
+ mkpart_from_namelist(catalog.postdef.split("\n")) if catalog
295
275
  end
296
276
 
297
277
  private
298
278
 
299
279
  def read_parts
300
280
  list = parse_chapters
281
+ # NOTE: keep this = style to work this logic.
301
282
  if pre = prefaces
302
283
  list.unshift pre
303
284
  end
@@ -318,14 +299,14 @@ module ReVIEW
318
299
 
319
300
  if catalog
320
301
  return catalog.parts_with_chaps.map do |entry|
321
- if entry.is_a? Hash
302
+ if entry.is_a?(Hash)
322
303
  chaps = entry.values.first.map do |chap|
323
- chap = Chapter.new(self, (num += 1), chap, "#{@basedir}/#{chap}")
304
+ chap = Chapter.new(self, num += 1, chap, "#{@basedir}/#{chap}")
324
305
  chap
325
306
  end
326
- Part.new(self, (part += 1), chaps, read_PART.split("\n")[part - 1])
307
+ Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1])
327
308
  else
328
- chap = Chapter.new(self, (num += 1), entry, "#{@basedir}/#{entry}")
309
+ chap = Chapter.new(self, num += 1, entry, "#{@basedir}/#{entry}")
329
310
  if chap.number
330
311
  num = chap.number
331
312
  else
@@ -336,24 +317,22 @@ module ReVIEW
336
317
  end
337
318
  end
338
319
 
339
- chap = read_CHAPS().
340
- strip.lines.map {|line| line.strip }.join("\n").split(/\n{2,}/).
341
- map {|part_chunk|
342
- chaps = part_chunk.split.map {|chapid|
343
- Chapter.new(self, (num += 1), chapid, "#{@basedir}/#{chapid}")
344
- }
345
- if part_exist? && read_PART.split("\n").size > part
346
- Part.new(self, (part += 1), chaps, read_PART.split("\n")[part-1])
320
+ chap = read_chaps.
321
+ strip.lines.map(&:strip).join("\n").split(/\n{2,}/).
322
+ map do |part_chunk|
323
+ chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, "#{@basedir}/#{chapid}") }
324
+ if part_exist? && read_part.split("\n").size > part
325
+ Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1])
347
326
  else
348
327
  Part.new(self, nil, chaps)
349
328
  end
350
- }
351
- return chap
329
+ end
330
+ chap
352
331
  end
353
332
 
354
333
  def mkpart_from_namelistfile(path)
355
334
  chaps = []
356
- File.read(path, :mode => 'r:BOM|utf-8').split.each_with_index do |name, idx|
335
+ File.read(path, mode: 'r:BOM|utf-8').split.each_with_index do |name, idx|
357
336
  if path =~ /PREDEF/
358
337
  chaps << mkchap(name)
359
338
  else
@@ -364,7 +343,7 @@ module ReVIEW
364
343
  end
365
344
 
366
345
  def mkpart_from_namelist(names)
367
- mkpart(names.map {|n| mkchap_ifexist(n) }.compact)
346
+ mkpart(names.map { |n| mkchap_ifexist(n) }.compact)
368
347
  end
369
348
 
370
349
  def mkpart(chaps)
@@ -372,14 +351,14 @@ module ReVIEW
372
351
  end
373
352
 
374
353
  def mkchap(name, number = nil)
375
- name += ext if File.extname(name) == ""
354
+ name += ext if File.extname(name).empty?
376
355
  path = "#{@basedir}/#{name}"
377
356
  raise FileNotFound, "file not exist: #{path}" unless File.file?(path)
378
357
  Chapter.new(self, number, name, path)
379
358
  end
380
359
 
381
360
  def mkchap_ifexist(name, idx = nil)
382
- name += ext if File.extname(name) == ""
361
+ name += ext if File.extname(name).empty?
383
362
  path = "#{@basedir}/#{name}"
384
363
  if File.file?(path)
385
364
  idx += 1 if idx
@@ -387,28 +366,24 @@ module ReVIEW
387
366
  end
388
367
  end
389
368
 
390
- def read_FILE(filename)
391
- if !@warn_old_files[filename]
369
+ def read_file(filename)
370
+ unless @warn_old_files[filename]
392
371
  @warn_old_files[filename] = true
393
- if caller().none? {|item| item =~ %r|/review/test/test_|}
394
- warn "!!! #{filename} is obsoleted. please use catalog.yml."
395
- end
372
+ warn "!!! #{filename} is obsoleted. please use catalog.yml." if caller.none? { |item| item =~ %r{/review/test/test_} }
396
373
  end
397
- res = ""
374
+ res = ''
398
375
  File.open("#{@basedir}/#{filename}", 'r:BOM|utf-8') do |f|
399
- while line = f.gets
400
- if /\A#/ =~ line
401
- next
402
- end
403
- line.gsub!(/#.*$/, "")
376
+ f.each_line do |line|
377
+ next if /\A#/ =~ line
378
+ line.gsub!(/#.*\Z/, '')
404
379
  res << line
405
380
  end
406
381
  end
407
382
  res
408
383
  rescue Errno::ENOENT
409
- Dir.glob("#{@basedir}/*#{ext()}").sort.join("\n")
384
+ Dir.glob("#{@basedir}/*#{ext}").sort.join("\n")
410
385
  rescue Errno::EISDIR
411
- ""
386
+ ''
412
387
  end
413
388
  end
414
389
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Copyright (c) 2002-2008 Minero Aoki
3
- # 2009-2016 Minero Aoki, Kenshi Muto
2
+ # Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
3
+ # 2002-2008 Minero Aoki
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -35,8 +35,8 @@ module ReVIEW
35
35
  @content = nil
36
36
  end
37
37
  if !@content && @path && File.exist?(@path)
38
- @content = File.read(@path, :mode => 'r:BOM|utf-8')
39
- @number = nil if ['nonum', 'nodisp', 'notoc'].include?(find_first_header_option)
38
+ @content = File.read(@path, mode: 'r:BOM|utf-8')
39
+ @number = nil if %w[nonum nodisp notoc].include?(find_first_header_option)
40
40
  end
41
41
  @list_index = nil
42
42
  @table_index = nil
@@ -57,11 +57,9 @@ module ReVIEW
57
57
  when /\A=+[\[\s\{]/
58
58
  m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(f.gets)
59
59
  return m[2] # tag
60
- when %r</\A//[a-z]+/>
60
+ when %r{/\A//[a-z]+/}
61
61
  line = f.gets
62
- if line.rstrip[-1,1] == "{"
63
- f.until_match(%r<\A//\}>)
64
- end
62
+ f.until_match(%r{\A//\}}) if line.rstrip[-1, 1] == '{'
65
63
  end
66
64
  f.gets
67
65
  end
@@ -69,62 +67,60 @@ module ReVIEW
69
67
  end
70
68
 
71
69
  def inspect
72
- "\#<#{self.class} #{@number} #{@path}>"
70
+ "#<#{self.class} #{@number} #{@path}>"
73
71
  end
74
72
 
75
73
  def format_number(heading = true)
76
- return "" unless @number
74
+ return '' unless @number
75
+ return @number.to_s if on_predef?
77
76
 
78
- if on_PREDEF?
79
- return "#{@number}"
80
- end
81
-
82
- if on_APPENDIX?
83
- return "#{@number}" if @number < 1 || @number > 27
84
- if @book.config["appendix_format"]
85
- raise ReVIEW::ConfigError,
86
- "'appendix_format:' in config.yml is obsoleted."
87
- end
77
+ if on_appendix?
78
+ return @number.to_s if @number < 1 || @number > 27
79
+ raise ReVIEW::ConfigError, %Q('appendix_format:' in config.yml is obsoleted.) if @book.config['appendix_format']
88
80
 
89
- i18n_appendix = I18n.get("appendix")
90
- fmt = i18n_appendix.scan(/%\w{1,3}/).first || "%s"
91
- I18n.update({"appendix_without_heading" => fmt})
81
+ i18n_appendix = I18n.get('appendix')
82
+ fmt = i18n_appendix.scan(/%\w{1,3}/).first || '%s'
83
+ I18n.update('appendix_without_heading' => fmt)
92
84
 
93
- if heading
94
- return I18n.t("appendix", @number)
95
- else
96
- return I18n.t("appendix_without_heading", @number)
97
- end
85
+ return I18n.t('appendix', @number) if heading
86
+ return I18n.t('appendix_without_heading', @number)
98
87
  end
99
88
 
100
89
  if heading
101
- "#{I18n.t("chapter", @number)}"
90
+ I18n.t('chapter', @number)
102
91
  else
103
- "#{@number}"
92
+ @number.to_s
104
93
  end
105
94
  end
106
95
 
107
- def on_CHAPS?
108
- on_FILE?(@book.read_CHAPS)
96
+ def on_chaps?
97
+ on_file?(@book.read_chaps)
109
98
  end
110
99
 
111
- def on_PREDEF?
112
- on_FILE?(@book.read_PREDEF)
100
+ def on_predef?
101
+ on_file?(@book.read_predef)
113
102
  end
114
103
 
115
- def on_APPENDIX?
116
- on_FILE?(@book.read_APPENDIX)
104
+ def on_appendix?
105
+ on_file?(@book.read_appendix)
117
106
  end
118
107
 
119
- def on_POSTDEF?
120
- on_FILE?(@book.read_POSTDEF)
108
+ def on_postdef?
109
+ on_file?(@book.read_postdef)
121
110
  end
122
111
 
123
112
  private
124
113
 
125
- def on_FILE?(contents)
126
- contents.lines.map(&:strip).include?("#{id()}#{@book.ext()}")
114
+ def on_file?(contents)
115
+ contents.lines.map(&:strip).include?("#{id}#{@book.ext}")
127
116
  end
117
+
118
+ # backward compatibility
119
+ alias_method :on_CHAPS?, :on_chaps?
120
+ alias_method :on_PREDEF?, :on_predef?
121
+ alias_method :on_APPENDIX?, :on_appendix?
122
+ alias_method :on_POSTDEF?, :on_postdef?
123
+ alias_method :on_FILE?, :on_file?
128
124
  end
129
125
  end
130
126
  end