review 5.3.0 → 5.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +1 -1
  3. data/.github/workflows/ruby.yml +1 -1
  4. data/.rubocop.yml +1 -322
  5. data/NEWS.ja.md +48 -0
  6. data/NEWS.md +48 -0
  7. data/README.md +9 -8
  8. data/bin/review +1 -1
  9. data/bin/review-catalog-converter +15 -15
  10. data/bin/review-check +7 -7
  11. data/bin/review-compile +6 -8
  12. data/bin/review-index +1 -1
  13. data/bin/review-preproc +1 -1
  14. data/bin/review-validate +2 -2
  15. data/doc/config.yml.sample +7 -1
  16. data/doc/config.yml.sample-simple +1 -1
  17. data/lib/review/book/base.rb +3 -3
  18. data/lib/review/book/book_unit.rb +1 -1
  19. data/lib/review/book/chapter.rb +1 -1
  20. data/lib/review/book/index.rb +3 -3
  21. data/lib/review/book/part.rb +12 -13
  22. data/lib/review/book/volume.rb +1 -1
  23. data/lib/review/builder.rb +10 -12
  24. data/lib/review/catalog.rb +5 -5
  25. data/lib/review/compiler.rb +13 -13
  26. data/lib/review/configure.rb +5 -2
  27. data/lib/review/epub2html.rb +12 -12
  28. data/lib/review/epubmaker/content.rb +1 -1
  29. data/lib/review/epubmaker/epubcommon.rb +44 -42
  30. data/lib/review/epubmaker/epubv2.rb +2 -1
  31. data/lib/review/epubmaker/epubv3.rb +5 -4
  32. data/lib/review/epubmaker/producer.rb +3 -3
  33. data/lib/review/epubmaker/reviewheaderlistener.rb +1 -1
  34. data/lib/review/epubmaker.rb +32 -31
  35. data/lib/review/extentions/string.rb +1 -1
  36. data/lib/review/htmlbuilder.rb +16 -15
  37. data/lib/review/htmlutils.rb +17 -17
  38. data/lib/review/i18n.rb +3 -3
  39. data/lib/review/idgxmlbuilder.rb +22 -21
  40. data/lib/review/idgxmlmaker.rb +15 -13
  41. data/lib/review/index_builder.rb +4 -20
  42. data/lib/review/init.rb +4 -4
  43. data/lib/review/latexbuilder.rb +30 -32
  44. data/lib/review/lineinput.rb +3 -3
  45. data/lib/review/location.rb +1 -1
  46. data/lib/review/logger.rb +21 -21
  47. data/lib/review/makerhelper.rb +3 -3
  48. data/lib/review/markdownbuilder.rb +6 -6
  49. data/lib/review/pdfmaker.rb +23 -19
  50. data/lib/review/plaintextbuilder.rb +5 -5
  51. data/lib/review/preprocessor/repository.rb +1 -1
  52. data/lib/review/preprocessor.rb +5 -5
  53. data/lib/review/textmaker.rb +20 -18
  54. data/lib/review/textutils.rb +3 -5
  55. data/lib/review/topbuilder.rb +71 -12
  56. data/lib/review/update.rb +16 -8
  57. data/lib/review/version.rb +1 -1
  58. data/lib/review/webmaker.rb +32 -32
  59. data/lib/review/webtocprinter.rb +10 -10
  60. data/lib/review/yamlloader.rb +35 -2
  61. data/review.gemspec +1 -0
  62. data/samples/sample-book/src/config.yml +0 -1
  63. data/templates/html/_titlepage.html.erb +9 -17
  64. data/templates/opf/opf_manifest_epubv2.opf.erb +1 -1
  65. data/templates/opf/opf_manifest_epubv3.opf.erb +1 -1
  66. data/test/book_test_helper.rb +10 -10
  67. data/test/test_epub3maker.rb +3 -3
  68. data/test/test_epubmaker.rb +14 -29
  69. data/test/test_epubmaker_cmd.rb +2 -2
  70. data/test/test_htmlbuilder.rb +4 -5
  71. data/test/test_idgxmlbuilder.rb +10 -10
  72. data/test/test_idgxmlmaker_cmd.rb +1 -1
  73. data/test/test_img_math.rb +11 -2
  74. data/test/test_latexbuilder.rb +2 -3
  75. data/test/test_pdfmaker_cmd.rb +10 -10
  76. data/test/test_textmaker_cmd.rb +1 -1
  77. data/test/test_topbuilder.rb +151 -11
  78. data/test/test_yamlloader.rb +28 -42
  79. metadata +8 -7
@@ -1,6 +1,6 @@
1
1
  # = epubcommon.rb -- super class for EPUBv2 and EPUBv3
2
2
  #
3
- # Copyright (c) 2010-2021 Kenshi Muto and Masayoshi Takahashi
3
+ # Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -27,6 +27,7 @@ module ReVIEW
27
27
  @contents = producer.contents
28
28
  @body_ext = nil
29
29
  @logger = ReVIEW.logger
30
+ @workdir = nil
30
31
  end
31
32
 
32
33
  attr_reader :config
@@ -36,7 +37,8 @@ module ReVIEW
36
37
  CGI.escapeHTML(str)
37
38
  end
38
39
 
39
- def produce(epubfile, basedir, tmpdir)
40
+ def produce(_epubfile, _basedir, _tmpdir, base_dir:)
41
+ @workdir = base_dir
40
42
  raise NotImplementedError # should be overridden
41
43
  end
42
44
 
@@ -99,27 +101,43 @@ module ReVIEW
99
101
  end
100
102
  end
101
103
 
104
+ def template_name(localfile: 'layout.html.erb', systemfile: nil)
105
+ if @workdir
106
+ layoutfile = File.join(@workdir, 'layouts', localfile)
107
+ if File.exist?(layoutfile)
108
+ return layoutfile
109
+ end
110
+ end
111
+
112
+ if systemfile
113
+ return systemfile
114
+ end
115
+
116
+ if config['htmlversion'].to_i == 5
117
+ './html/layout-html5.html.erb'
118
+ else
119
+ './html/layout-xhtml1.html.erb'
120
+ end
121
+ end
122
+
102
123
  # Return cover content.
103
124
  # If Producer#config["coverimage"] is defined, it will be used for
104
125
  # the cover image.
105
126
  def cover
106
- @body_ext = config['epubversion'] >= 3 ? %Q( epub:type="cover") : ''
127
+ @body_ext = config['epubversion'] >= 3 ? %Q( epub:type="cover") : nil
107
128
 
108
129
  if config['coverimage']
109
130
  @coverimage_src = coverimage
110
131
  raise ApplicationError, "coverimage #{config['coverimage']} not found. Abort." unless @coverimage_src
111
132
  end
112
- @body = ReVIEW::Template.generate(path: './html/_cover.html.erb', binding: binding)
133
+ @body = ReVIEW::Template.generate(path: template_name(localfile: '_cover.html.erb', systemfile: 'html/_cover.html.erb'), binding: binding)
113
134
 
114
135
  @title = h(config.name_of('title'))
115
136
  @language = config['language']
116
137
  @stylesheets = config['stylesheet']
117
- template_path = if config['htmlversion'].to_i == 5
118
- './html/layout-html5.html.erb'
119
- else
120
- './html/layout-xhtml1.html.erb'
121
- end
122
- ReVIEW::Template.generate(path: template_path, binding: binding)
138
+ ret = ReVIEW::Template.generate(path: template_name, binding: binding)
139
+ @body_ext = nil
140
+ ret
123
141
  end
124
142
 
125
143
  # Return title (copying) content.
@@ -138,16 +156,11 @@ module ReVIEW
138
156
  if config.names_of('pbl')
139
157
  @publisher_str = join_with_separator(config.names_of('pbl'), ReVIEW::I18n.t('names_splitter'))
140
158
  end
141
- @body = ReVIEW::Template.generate(path: './html/_titlepage.html.erb', binding: binding)
159
+ @body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: './html/_titlepage.html.erb'), binding: binding)
142
160
 
143
161
  @language = config['language']
144
162
  @stylesheets = config['stylesheet']
145
- template_path = if config['htmlversion'].to_i == 5
146
- './html/layout-html5.html.erb'
147
- else
148
- './html/layout-xhtml1.html.erb'
149
- end
150
- ReVIEW::Template.generate(path: template_path, binding: binding)
163
+ ReVIEW::Template.generate(path: template_name, binding: binding)
151
164
  end
152
165
 
153
166
  # Return colophon content.
@@ -155,24 +168,19 @@ module ReVIEW
155
168
  @title = h(ReVIEW::I18n.t('colophontitle'))
156
169
  @isbn_hyphen = isbn_hyphen
157
170
 
158
- @body = ReVIEW::Template.generate(path: './html/_colophon.html.erb', binding: binding)
171
+ @body = ReVIEW::Template.generate(path: template_name(localfile: '_colophon.html.erb', systemfile: './html/_colophon.html.erb'), binding: binding)
159
172
 
160
173
  @language = config['language']
161
174
  @stylesheets = config['stylesheet']
162
- template_path = if config['htmlversion'].to_i == 5
163
- './html/layout-html5.html.erb'
164
- else
165
- './html/layout-xhtml1.html.erb'
166
- end
167
- ReVIEW::Template.generate(path: template_path, binding: binding)
175
+ ReVIEW::Template.generate(path: template_name, binding: binding)
168
176
  end
169
177
 
170
178
  def isbn_hyphen
171
179
  str = config['isbn'].to_s
172
180
 
173
- if str =~ /\A\d{10}\Z/
181
+ if /\A\d{10}\Z/.match?(str)
174
182
  "#{str[0..0]}-#{str[1..5]}-#{str[6..8]}-#{str[9..9]}"
175
- elsif str =~ /\A\d{13}\Z/
183
+ elsif /\A\d{13}\Z/.match?(str)
176
184
  "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}"
177
185
  end
178
186
  end
@@ -184,9 +192,9 @@ module ReVIEW
184
192
  items.each_with_index do |item, rev|
185
193
  editstr = edit == 0 ? ReVIEW::I18n.t('first_edition') : ReVIEW::I18n.t('nth_edition', (edit + 1).to_s)
186
194
  revstr = ReVIEW::I18n.t('nth_impression', (rev + 1).to_s)
187
- if item =~ /\A\d+-\d+-\d+\Z/
195
+ if /\A\d+-\d+-\d+\Z/.match?(item)
188
196
  @col_history << ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])
189
- elsif item =~ /\A(\d+-\d+-\d+)[\s ](.+)/
197
+ elsif /\A(\d+-\d+-\d+)[\s ](.+)/.match?(item)
190
198
  # custom date with string
191
199
  item.match(/\A(\d+-\d+-\d+)[\s ](.+)/) do |m|
192
200
  @col_history << ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]])
@@ -199,7 +207,7 @@ module ReVIEW
199
207
  end
200
208
  end
201
209
 
202
- ReVIEW::Template.generate(path: './html/_colophon_history.html.erb', binding: binding)
210
+ ReVIEW::Template.generate(path: template_name(localfile: '_colophon_history.html.erb', systemfile: './html/_colophon_history.html.erb'), binding: binding)
203
211
  end
204
212
 
205
213
  def date_to_s(date)
@@ -211,22 +219,16 @@ module ReVIEW
211
219
  # Return own toc content.
212
220
  def mytoc
213
221
  @title = h(ReVIEW::I18n.t('toctitle'))
214
-
215
222
  @body = %Q( <h1 class="toc-title">#{h(ReVIEW::I18n.t('toctitle'))}</h1>\n)
216
- if config['epubmaker']['flattoc'].nil?
217
- @body << hierarchy_ncx('ul')
218
- else
219
- @body << flat_ncx('ul', config['epubmaker']['flattocindent'])
220
- end
223
+ @body << if config['epubmaker']['flattoc'].nil?
224
+ hierarchy_ncx('ul')
225
+ else
226
+ flat_ncx('ul', config['epubmaker']['flattocindent'])
227
+ end
221
228
 
222
229
  @language = config['language']
223
230
  @stylesheets = config['stylesheet']
224
- template_path = if config['htmlversion'].to_i == 5
225
- './html/layout-html5.html.erb'
226
- else
227
- './html/layout-xhtml1.html.erb'
228
- end
229
- ReVIEW::Template.generate(path: template_path, binding: binding)
231
+ ReVIEW::Template.generate(path: template_name, binding: binding)
230
232
  end
231
233
 
232
234
  def hierarchy_ncx(type)
@@ -334,7 +336,7 @@ module ReVIEW
334
336
  end
335
337
 
336
338
  contents.each do |item|
337
- next if item.file =~ /#/ # skip subgroup
339
+ next if /#/.match?(item.file) # skip subgroup
338
340
 
339
341
  fname = "#{basedir}/#{item.file}"
340
342
  unless File.exist?(fname)
@@ -1,6 +1,6 @@
1
1
  # = epubv2.rb -- EPUB version 2 producer.
2
2
  #
3
- # Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
3
+ # Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -159,6 +159,7 @@ EOT
159
159
  # +basedir+ points the directory has contents.
160
160
  # +tmpdir+ defines temporary directory.
161
161
  def produce(epubfile, work_dir, tmpdir, base_dir:)
162
+ @workdir = base_dir
162
163
  produce_write_common(work_dir, tmpdir)
163
164
 
164
165
  ncx_file = "#{tmpdir}/OEBPS/#{config['bookname']}.ncx"
@@ -1,6 +1,6 @@
1
1
  # = epubv3.rb -- EPUB version 3 producer.
2
2
  #
3
- # Copyright (c) 2010-2017 Kenshi Muto
3
+ # Copyright (c) 2010-2022 Kenshi Muto
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -186,7 +186,7 @@ module ReVIEW
186
186
  @tocx_contents = []
187
187
  toc = nil
188
188
  contents.each do |item|
189
- next if item.media !~ /xhtml\+xml/ # skip non XHTML
189
+ next unless /xhtml\+xml/.match?(item.media) # skip non XHTML
190
190
 
191
191
  @tocx_contents << item
192
192
  end
@@ -210,19 +210,20 @@ module ReVIEW
210
210
  @title = h(ReVIEW::I18n.t('toctitle'))
211
211
  @language = config['language']
212
212
  @stylesheets = config['stylesheet']
213
- ReVIEW::Template.generate(path: './html/layout-html5.html.erb', binding: binding)
213
+ ReVIEW::Template.generate(path: template_name, binding: binding)
214
214
  end
215
215
 
216
216
  # Produce EPUB file +epubfile+.
217
217
  # +work_dir+ points the directory has contents.
218
218
  # +tmpdir+ defines temporary directory.
219
219
  def produce(epubfile, work_dir, tmpdir, base_dir:)
220
+ @workdir = base_dir
220
221
  produce_write_common(work_dir, tmpdir)
221
222
 
222
223
  toc_file = "#{tmpdir}/OEBPS/#{config['bookname']}-toc.#{config['htmlext']}"
223
224
  File.write(toc_file, ncx(config['epubmaker']['ncxindent']))
224
225
 
225
- call_hook('hook_prepack', tmpdir, base_dir: base_dir)
226
+ call_hook('hook_prepack', tmpdir, base_dir: @workdir)
226
227
  expoter = ReVIEW::EPUBMaker::ZipExporter.new(tmpdir, config)
227
228
  expoter.export_zip(epubfile)
228
229
  end
@@ -89,8 +89,8 @@ module ReVIEW
89
89
  Dir.foreach(path) do |f|
90
90
  next if f.start_with?('.')
91
91
 
92
- if f =~ /\.(#{allow_exts.join('|')})\Z/i
93
- path.chop! if path =~ %r{/\Z}
92
+ if /\.(#{allow_exts.join('|')})\Z/i.match?(f)
93
+ path.chop! if %r{/\Z}.match?(path)
94
94
  if base.nil?
95
95
  @contents.push(ReVIEW::EPUBMaker::Content.new(file: "#{path}/#{f}"))
96
96
  else
@@ -115,7 +115,7 @@ module ReVIEW
115
115
 
116
116
  # use Dir to solve a path for Windows (see #1011)
117
117
  new_tmpdir = Dir[File.join(tmpdir.nil? ? Dir.mktmpdir : tmpdir)][0]
118
- if epubfile !~ %r{\A/}
118
+ unless epubfile.start_with?('/')
119
119
  epubfile = "#{current}/#{epubfile}"
120
120
  end
121
121
 
@@ -41,7 +41,7 @@ module ReVIEW
41
41
  end
42
42
 
43
43
  def tag_end(name)
44
- if name =~ /\Ah\d+/
44
+ if /\Ah\d+/.match?(name)
45
45
  if @id.present?
46
46
  @headlines.push({ 'level' => @level,
47
47
  'id' => @id,
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2021 Kenshi Muto and Masayoshi Takahashi
1
+ # Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -75,9 +75,13 @@ module ReVIEW
75
75
  cmd_config, yamlfile, exportfile = parse_opts(args)
76
76
  error! "#{yamlfile} not found." unless File.exist?(yamlfile)
77
77
 
78
- @config = ReVIEW::Configure.create(maker: 'epubmaker',
79
- yamlfile: yamlfile,
80
- config: cmd_config)
78
+ begin
79
+ @config = ReVIEW::Configure.create(maker: 'epubmaker',
80
+ yamlfile: yamlfile,
81
+ config: cmd_config)
82
+ rescue ReVIEW::ConfigError => e
83
+ error! e.message
84
+ end
81
85
  @producer = ReVIEW::EPUBMaker::Producer.new(@config)
82
86
  update_log_level
83
87
  debug("Loaded yaml file (#{yamlfile}).")
@@ -227,7 +231,7 @@ module ReVIEW
227
231
  if @config['epubmaker']['verify_target_images'].present?
228
232
  @config['epubmaker']['force_include_images'].each do |file|
229
233
  unless File.exist?(file)
230
- if file !~ /\Ahttps?:/
234
+ unless /\Ahttps?:/.match?(file)
231
235
  warn "#{file} is not found, skip."
232
236
  end
233
237
  next
@@ -257,7 +261,7 @@ module ReVIEW
257
261
 
258
262
  if FileTest.directory?(File.join(resdir, fname))
259
263
  recursive_copy_files(File.join(resdir, fname), File.join(destdir, fname), allow_exts)
260
- elsif fname =~ /\.(#{allow_exts.join('|')})\Z/i
264
+ elsif /\.(#{allow_exts.join('|')})\Z/i.match?(fname)
261
265
  FileUtils.mkdir_p(destdir)
262
266
  debug("Copy #{resdir}/#{fname} to the temporary directory.")
263
267
  FileUtils.cp(File.join(resdir, fname), destdir, preserve: true)
@@ -315,15 +319,25 @@ module ReVIEW
315
319
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
316
320
  @part_number = part.number
317
321
  @part_title = part.name.strip
318
- @body = ReVIEW::Template.generate(path: 'html/_part_body.html.erb', binding: binding)
319
-
322
+ @body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
320
323
  @language = @producer.config['language']
321
324
  @stylesheets = @producer.config['stylesheet']
322
325
  f.write ReVIEW::Template.generate(path: template_name, binding: binding)
323
326
  end
324
327
  end
325
328
 
326
- def template_name
329
+ def template_name(localfile: 'layout.html.erb', systemfile: nil)
330
+ if @basedir
331
+ layoutfile = File.join(@basedir, 'layouts', localfile)
332
+ if File.exist?(layoutfile)
333
+ return layoutfile
334
+ end
335
+ end
336
+
337
+ if systemfile
338
+ return systemfile
339
+ end
340
+
327
341
  if @producer.config['htmlversion'].to_i == 5
328
342
  './html/layout-html5.html.erb'
329
343
  else
@@ -376,7 +390,7 @@ module ReVIEW
376
390
 
377
391
  if @config['params'].present?
378
392
  warn %Q('params:' in config.yml is obsoleted.)
379
- if @config['params'] =~ /stylesheet=/
393
+ if /stylesheet=/.match?(@config['params'])
380
394
  warn %Q(stylesheets should be defined in 'stylesheet:', not in 'params:')
381
395
  end
382
396
  end
@@ -384,7 +398,7 @@ module ReVIEW
384
398
  @converter.convert(filename, File.join(basetmpdir, htmlfile))
385
399
  write_info_body(basetmpdir, id, htmlfile, ispart, chaptype)
386
400
  remove_hidden_title(basetmpdir, htmlfile)
387
- rescue => e
401
+ rescue StandardError => e
388
402
  @compile_errors = true
389
403
  error "compile error in #{filename} (#{e.class})"
390
404
  error e.message
@@ -436,11 +450,11 @@ module ReVIEW
436
450
  end
437
451
 
438
452
  properties = detect_properties(path)
439
- if properties.present?
440
- prop_str = ',properties=' + properties.join(' ')
441
- else
442
- prop_str = ''
443
- end
453
+ prop_str = if properties.present?
454
+ ',properties=' + properties.join(' ')
455
+ else
456
+ ''
457
+ end
444
458
  first = true
445
459
  headlines.each do |headline|
446
460
  if ispart.present? && headline['level'] == 1
@@ -545,25 +559,12 @@ module ReVIEW
545
559
  end
546
560
 
547
561
  def build_titlepage(basetmpdir, htmlfile)
548
- # TODO: should be created via epubcommon
549
562
  @title = h(@config.name_of('booktitle'))
550
563
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
551
- @body = ''
552
- @body << %Q(<div class="titlepage">\n)
553
- @body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>\n)
554
- if @config['subtitle']
555
- @body << %Q(<h2 class="tp-subtitle">#{h(@config.name_of('subtitle'))}</h2>\n)
556
- end
557
- if @config['aut']
558
- @body << %Q(<h2 class="tp-author">#{h(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter')))}</h2>\n)
559
- end
560
- if @config['pbl']
561
- @body << %Q(<h3 class="tp-publisher">#{h(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n)
562
- end
563
- @body << '</div>'
564
-
564
+ @body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: 'html/_titlepage.html.erb'), binding: binding)
565
565
  @language = @producer.config['language']
566
566
  @stylesheets = @producer.config['stylesheet']
567
+
567
568
  f.write ReVIEW::Template.generate(path: template_name, binding: binding)
568
569
  end
569
570
  end
@@ -1,4 +1,4 @@
1
- if defined?(Encoding) && Encoding.respond_to?('default_external') &&
1
+ if defined?(Encoding) && Encoding.respond_to?(:default_external) &&
2
2
  Encoding.default_external != Encoding::UTF_8
3
3
  Encoding.default_external = 'UTF-8'
4
4
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
1
+ # Copyright (c) 2008-2022 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
2
2
  # KADO Masanori
3
3
  # 2002-2007 Minero Aoki
4
4
  #
@@ -67,11 +67,11 @@ module ReVIEW
67
67
  htmldir = 'html'
68
68
  localfilename = 'layout.html.erb'
69
69
  end
70
- if @book.htmlversion == 5
71
- htmlfilename = File.join(htmldir, 'layout-html5.html.erb')
72
- else
73
- htmlfilename = File.join(htmldir, 'layout-xhtml1.html.erb')
74
- end
70
+ htmlfilename = if @book.htmlversion == 5
71
+ File.join(htmldir, 'layout-html5.html.erb')
72
+ else
73
+ File.join(htmldir, 'layout-xhtml1.html.erb')
74
+ end
75
75
 
76
76
  layout_file = File.join(@book.basedir, 'layouts', localfilename)
77
77
  if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb'))
@@ -861,7 +861,7 @@ EOS
861
861
  end
862
862
  begin
863
863
  puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />)
864
- rescue
864
+ rescue StandardError
865
865
  warn "image not bound: #{id}", location: location
866
866
  if lines
867
867
  puts %Q(<pre class="dummyimage">)
@@ -977,8 +977,9 @@ EOS
977
977
  def compile_kw(word, alt)
978
978
  %Q(<b class="kw">) +
979
979
  if alt
980
- then escape(word + " (#{alt.strip})")
981
- else escape(word)
980
+ escape(word + " (#{alt.strip})")
981
+ else
982
+ escape(word)
982
983
  end +
983
984
  "</b><!-- IDX:#{escape_comment(escape(word))} -->"
984
985
  end
@@ -1096,11 +1097,11 @@ EOS
1096
1097
 
1097
1098
  def inline_hd_chap(chap, id)
1098
1099
  n = chap.headline_index.number(id)
1099
- if n.present? && chap.number && over_secnolevel?(n)
1100
- str = I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
1101
- else
1102
- str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1103
- end
1100
+ str = if n.present? && chap.number && over_secnolevel?(n)
1101
+ I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
1102
+ else
1103
+ I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
1104
+ end
1104
1105
  if @book.config['chapterlink']
1105
1106
  anchor = 'h' + n.tr('.', '-')
1106
1107
  %Q(<a href="#{chap.id}#{extname}##{anchor}">#{str}</a>)
@@ -1250,7 +1251,7 @@ EOS
1250
1251
  def inline_icon(id)
1251
1252
  begin
1252
1253
  %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="[#{id}]" />)
1253
- rescue
1254
+ rescue StandardError
1254
1255
  warn "image not bound: #{id}", location: location
1255
1256
  %Q(<pre>missing image: #{id}</pre>)
1256
1257
  end
@@ -9,7 +9,7 @@
9
9
 
10
10
  begin
11
11
  require 'cgi/escape'
12
- rescue
12
+ rescue StandardError
13
13
  require 'cgi/util'
14
14
  end
15
15
 
@@ -60,13 +60,13 @@ module ReVIEW
60
60
  def highlight_pygments(ops)
61
61
  body = ops[:body] || ''
62
62
  format = ops[:format] || ''
63
- if ops[:lexer].present?
64
- lexer = ops[:lexer]
65
- elsif @book.config['highlight'] && @book.config['highlight']['lang']
66
- lexer = @book.config['highlight']['lang'] # default setting
67
- else
68
- lexer = 'text'
69
- end
63
+ lexer = if ops[:lexer].present?
64
+ ops[:lexer]
65
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
66
+ @book.config['highlight']['lang'] # default setting
67
+ else
68
+ 'text'
69
+ end
70
70
  options = { nowrap: true, noclasses: true }
71
71
  if ops[:linenum]
72
72
  options[:nowrap] = false
@@ -93,13 +93,13 @@ module ReVIEW
93
93
 
94
94
  def highlight_rouge(ops)
95
95
  body = ops[:body] || ''
96
- if ops[:lexer].present?
97
- lexer = ops[:lexer]
98
- elsif @book.config['highlight'] && @book.config['highlight']['lang']
99
- lexer = @book.config['highlight']['lang'] # default setting
100
- else
101
- lexer = 'text'
102
- end
96
+ lexer = if ops[:lexer].present?
97
+ ops[:lexer]
98
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
99
+ @book.config['highlight']['lang'] # default setting
100
+ else
101
+ 'text'
102
+ end
103
103
  # format = ops[:format] || ''
104
104
 
105
105
  first_line_num = 1 ## default
@@ -129,9 +129,9 @@ module ReVIEW
129
129
  end
130
130
 
131
131
  def normalize_id(id)
132
- if id =~ /\A[a-z][a-z0-9_.-]*\Z/i
132
+ if /\A[a-z][a-z0-9_.-]*\Z/i.match?(id)
133
133
  id
134
- elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
134
+ elsif /\A[0-9_.-][a-z0-9_.-]*\Z/i.match?(id)
135
135
  "id_#{id}" # dummy prefix
136
136
  else
137
137
  "id_#{CGI.escape(id.gsub('_', '__')).tr('%', '_').tr('+', '-')}" # escape all
data/lib/review/i18n.rb CHANGED
@@ -75,11 +75,11 @@ module ReVIEW
75
75
  end
76
76
 
77
77
  def load_file(path)
78
- @store = YAML.load_file(path)
78
+ @store = YAMLLoader.safe_load_file(path)
79
79
  end
80
80
 
81
81
  def update_localefile(path)
82
- user_i18n = YAML.load_file(path)
82
+ user_i18n = YAMLLoader.safe_load_file(path)
83
83
  locale = user_i18n['locale']
84
84
  if locale
85
85
  user_i18n.delete('locale')
@@ -171,7 +171,7 @@ module ReVIEW
171
171
  args_matched = (frmt.count('%') <= args.size)
172
172
  frmt.gsub!('##', '%%')
173
173
  args_matched ? (frmt % args) : frmt
174
- rescue
174
+ rescue StandardError
175
175
  str
176
176
  end
177
177
  end