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,7 +1,6 @@
1
1
  #
2
- # $Id: exception.rb 3881 2008-02-09 14:44:17Z aamine $
3
- #
4
- # Copyright (c) 2002-2007 Minero Aoki
2
+ # Copyright (c) 2007-2017 Minero Aoki, Kenshi Muto
3
+ # 2002-2007 Minero Aoki
5
4
  #
6
5
  # This program is free software.
7
6
  # You can distribute or modify this program under the terms of
@@ -10,7 +9,6 @@
10
9
  #
11
10
 
12
11
  module ReVIEW
13
-
14
12
  class Error < ::StandardError; end
15
13
  class ApplicationError < Error; end
16
14
  class ConfigError < ApplicationError; end
@@ -1,4 +1,3 @@
1
1
  require 'review/extentions/object'
2
2
  require 'review/extentions/string'
3
3
  require 'review/extentions/hash'
4
-
@@ -1,7 +1,7 @@
1
1
  class Hash
2
2
  def deep_merge!(other)
3
- self.merge!(other) do |key, v_self, v_other|
4
- if v_self.kind_of?(Hash) && v_other.kind_of?(Hash)
3
+ self.merge!(other) do |_key, v_self, v_other|
4
+ if v_self.is_a?(Hash) && v_other.is_a?(Hash)
5
5
  v_self.deep_merge(v_other)
6
6
  else
7
7
  v_other
@@ -1,34 +1,9 @@
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
- Encoding.default_external = "UTF-8"
3
+ Encoding.default_external = 'UTF-8'
4
4
  end
5
5
 
6
- unless String.method_defined?(:lines)
7
- # Ruby 1.8
8
- class String
9
- alias_method :lines, :to_a
10
- end
11
- end
12
-
13
- if String.method_defined?(:bytesize)
14
- # Ruby 1.9
15
- class String
16
- alias_method :charsize, :size
17
- end
18
- else
19
- # Ruby 1.8
20
- class String
21
- alias_method :bytesize, :size
22
-
23
- def charsize
24
- split(//).size
25
- end
26
- end
27
- end
28
-
29
- unless String.method_defined?(:each)
30
- # Ruby 1.9
31
- class String
32
- alias_method :each, :each_line
33
- end
6
+ class String
7
+ alias_method :charsize, :size
8
+ alias_method :each, :each_line
34
9
  end
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
2
-
3
- # Copyright (c) 2002-2007 Minero Aoki
4
- # 2008-2017 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
1
+ # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
5
2
  # KADO Masanori
3
+ # 2002-2007 Minero Aoki
6
4
  #
7
5
  # This program is free software.
8
6
  # You can distribute or modify this program under the terms of
@@ -18,13 +16,11 @@ require 'digest'
18
16
  require 'tmpdir'
19
17
 
20
18
  module ReVIEW
21
-
22
19
  class HTMLBuilder < Builder
23
-
24
20
  include TextUtils
25
21
  include HTMLUtils
26
22
 
27
- [:ref].each {|e| Compiler.definline(e) }
23
+ [:ref].each { |e| Compiler.definline(e) }
28
24
  Compiler.defblock(:planning, 0..1)
29
25
  Compiler.defblock(:best, 0..1)
30
26
  Compiler.defblock(:security, 0..1)
@@ -40,7 +36,7 @@ module ReVIEW
40
36
  end
41
37
 
42
38
  def extname
43
- ".#{@book.config["htmlext"]}"
39
+ ".#{@book.config['htmlext']}"
44
40
  end
45
41
 
46
42
  def builder_init(no_error = false)
@@ -55,7 +51,7 @@ module ReVIEW
55
51
  def builder_init_file
56
52
  @warns = []
57
53
  @errors = []
58
- @chapter.book.image_types = %w(.png .jpg .jpeg .gif .svg)
54
+ @chapter.book.image_types = %w[.png .jpg .jpeg .gif .svg]
59
55
  @column = 0
60
56
  @sec_counter = SecCounter.new(5, @chapter)
61
57
  @nonum_counter = 0
@@ -66,26 +62,26 @@ module ReVIEW
66
62
  private :builder_init_file
67
63
 
68
64
  def layoutfile
69
- if @book.config.maker == "webmaker"
70
- htmldir = "web/html"
71
- localfilename = "layout-web.html.erb"
65
+ if @book.config.maker == 'webmaker'
66
+ htmldir = 'web/html'
67
+ localfilename = 'layout-web.html.erb'
72
68
  else
73
- htmldir = "html"
74
- localfilename = "layout.html.erb"
69
+ htmldir = 'html'
70
+ localfilename = 'layout.html.erb'
75
71
  end
76
72
  if @book.htmlversion == 5
77
- htmlfilename = File.join(htmldir, "layout-html5.html.erb")
73
+ htmlfilename = File.join(htmldir, 'layout-html5.html.erb')
78
74
  else
79
- htmlfilename = File.join(htmldir, "layout-xhtml1.html.erb")
75
+ htmlfilename = File.join(htmldir, 'layout-xhtml1.html.erb')
80
76
  end
81
77
 
82
- layout_file = File.join(@book.basedir, "layouts", localfilename)
83
- if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, "layouts", "layout.erb"))
84
- raise ReVIEW::ConfigError, "layout.erb is obsoleted. Please use layout.html.erb."
78
+ layout_file = File.join(@book.basedir, 'layouts', localfilename)
79
+ if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb'))
80
+ raise ReVIEW::ConfigError, 'layout.erb is obsoleted. Please use layout.html.erb.'
85
81
  end
86
82
  if File.exist?(layout_file)
87
- if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
88
- warn "user's layout is prohibited in safe mode. ignored."
83
+ if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
84
+ warn %Q(user's layout is prohibited in safe mode. ignored.)
89
85
  layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
90
86
  end
91
87
  else
@@ -99,77 +95,50 @@ module ReVIEW
99
95
  @title = strip_html(compile_inline(@chapter.title))
100
96
  @body = @output.string
101
97
  @language = @book.config['language']
102
- @stylesheets = @book.config["stylesheet"]
98
+ @stylesheets = @book.config['stylesheet']
103
99
  @next = @chapter.next_chapter
104
100
  @prev = @chapter.prev_chapter
105
- @next_title = @next ? compile_inline(@next.title) : ""
106
- @prev_title = @prev ? compile_inline(@prev.title) : ""
101
+ @next_title = @next ? compile_inline(@next.title) : ''
102
+ @prev_title = @prev ? compile_inline(@prev.title) : ''
107
103
 
108
- if @book.config.maker == "webmaker"
109
- @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
110
- end
104
+ @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book) if @book.config.maker == 'webmaker'
111
105
 
112
- tmpl = ReVIEW::Template.load(layoutfile)
113
- tmpl.result(binding)
106
+ ReVIEW::Template.load(layoutfile).result(binding)
114
107
  end
115
108
 
116
109
  def xmlns_ops_prefix
117
- if @book.config["epubversion"].to_i == 3
118
- "epub"
119
- else
120
- "ops"
121
- end
122
- end
123
-
124
- def warn(msg)
125
- if @no_error
126
- @warns.push [@location.filename, @location.lineno, msg]
127
- puts "----WARNING: #{escape_html(msg)}----"
128
- else
129
- $stderr.puts "#{@location}: warning: #{msg}"
130
- end
131
- end
132
-
133
- def error(msg)
134
- if @no_error
135
- @errors.push [@location.filename, @location.lineno, msg]
136
- puts "----ERROR: #{escape_html(msg)}----"
110
+ if @book.config['epubversion'].to_i == 3
111
+ 'epub'
137
112
  else
138
- $stderr.puts "#{@location}: error: #{msg}"
113
+ 'ops'
139
114
  end
140
115
  end
141
116
 
142
117
  def headline(level, label, caption)
143
118
  prefix, anchor = headline_prefix(level)
144
- unless prefix.nil?
145
- prefix = %Q[<span class="secno">#{prefix}</span>]
146
- end
119
+ prefix = %Q(<span class="secno">#{prefix}</span>) if prefix
147
120
  puts '' if level > 1
148
- a_id = ""
149
- unless anchor.nil?
150
- a_id = %Q[<a id="h#{anchor}"></a>]
151
- end
121
+ a_id = ''
122
+ a_id = %Q(<a id="h#{anchor}"></a>) if anchor
123
+
152
124
  if caption.empty?
153
- puts a_id unless label.nil?
125
+ puts a_id if label
126
+ elsif label
127
+ puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>)
154
128
  else
155
- if label.nil?
156
- puts %Q[<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
157
- else
158
- puts %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
159
- end
129
+ puts %Q(<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>)
160
130
  end
161
131
  end
162
132
 
163
133
  def nonum_begin(level, label, caption)
164
134
  @nonum_counter += 1
165
- puts '' if level > 1
166
- unless caption.empty?
167
- if label.nil?
168
- id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
169
- puts %Q[<h#{level} id="#{id}">#{compile_inline(caption)}</h#{level}>]
170
- else
171
- puts %Q[<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>]
172
- end
135
+ puts if level > 1
136
+ return unless caption.present?
137
+ if label
138
+ puts %Q(<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>)
139
+ else
140
+ id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
141
+ puts %Q(<h#{level} id="#{id}">#{compile_inline(caption)}</h#{level}>)
173
142
  end
174
143
  end
175
144
 
@@ -178,14 +147,13 @@ module ReVIEW
178
147
 
179
148
  def notoc_begin(level, label, caption)
180
149
  @nonum_counter += 1
181
- puts '' if level > 1
182
- unless caption.empty?
183
- if label.nil?
184
- id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
185
- puts %Q[<h#{level} id="#{id}" notoc="true">#{compile_inline(caption)}</h#{level}>]
186
- else
187
- puts %Q[<h#{level} id="#{normalize_id(label)}" notoc="true">#{compile_inline(caption)}</h#{level}>]
188
- end
150
+ puts if level > 1
151
+ return unless caption.present?
152
+ if label
153
+ puts %Q(<h#{level} id="#{normalize_id(label)}" notoc="true">#{compile_inline(caption)}</h#{level}>)
154
+ else
155
+ id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
156
+ puts %Q(<h#{level} id="#{id}" notoc="true">#{compile_inline(caption)}</h#{level}>)
189
157
  end
190
158
  end
191
159
 
@@ -195,13 +163,12 @@ module ReVIEW
195
163
  def nodisp_begin(level, label, caption)
196
164
  @nonum_counter += 1
197
165
  puts '' if level > 1
198
- unless caption.empty?
199
- if label.nil?
200
- id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
201
- puts %Q[<a id="#{id}" /><h#{level} id="#{id}" hidden="true">#{compile_inline(caption)}</h#{level}>]
202
- else
203
- puts %Q[<a id="#{normalize_id(label)}" /><h#{level} id="#{normalize_id(label)}" hidden="true">#{compile_inline(caption)}</h#{level}>]
204
- end
166
+ return unless caption.present?
167
+ if label
168
+ puts %Q(<a id="#{normalize_id(label)}" /><h#{level} id="#{normalize_id(label)}" hidden="true">#{compile_inline(caption)}</h#{level}>)
169
+ else
170
+ id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
171
+ puts %Q(<a id="#{id}" /><h#{level} id="#{id}" hidden="true">#{compile_inline(caption)}</h#{level}>)
205
172
  end
206
173
  end
207
174
 
@@ -209,124 +176,119 @@ module ReVIEW
209
176
  end
210
177
 
211
178
  def column_begin(level, label, caption)
212
- puts %Q[<div class="column">]
179
+ puts %Q(<div class="column">)
213
180
 
214
181
  @column += 1
215
- puts '' if level > 1
216
- a_id = %Q[<a id="column-#{@column}"></a>]
182
+ puts if level > 1
183
+ a_id = %Q(<a id="column-#{@column}"></a>)
217
184
 
218
185
  if caption.empty?
219
- puts a_id unless label.nil?
186
+ puts a_id if label
187
+ elsif label
188
+ puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{compile_inline(caption)}</h#{level}>)
220
189
  else
221
- if label.nil?
222
- puts %Q[<h#{level}>#{a_id}#{compile_inline(caption)}</h#{level}>]
223
- else
224
- puts %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{compile_inline(caption)}</h#{level}>]
225
- end
190
+ puts %Q(<h#{level}>#{a_id}#{compile_inline(caption)}</h#{level}>)
226
191
  end
227
- # headline(level, label, caption)
228
192
  end
229
193
 
230
- def column_end(level)
194
+ def column_end(_level)
231
195
  puts '</div>'
232
196
  end
233
197
 
234
198
  def xcolumn_begin(level, label, caption)
235
- puts %Q[<div class="xcolumn">]
199
+ puts %Q(<div class="xcolumn">)
236
200
  headline(level, label, caption)
237
201
  end
238
202
 
239
- def xcolumn_end(level)
203
+ def xcolumn_end(_level)
240
204
  puts '</div>'
241
205
  end
242
206
 
243
207
  def ref_begin(level, label, caption)
244
- print %Q[<div class="reference">]
208
+ print %Q(<div class="reference">)
245
209
  headline(level, label, caption)
246
210
  end
247
211
 
248
- def ref_end(level)
212
+ def ref_end(_level)
249
213
  puts '</div>'
250
214
  end
251
215
 
252
216
  def sup_begin(level, label, caption)
253
- print %Q[<div class="supplement">]
217
+ print %Q(<div class="supplement">)
254
218
  headline(level, label, caption)
255
219
  end
256
220
 
257
- def sup_end(level)
221
+ def sup_end(_level)
258
222
  puts '</div>'
259
223
  end
260
224
 
261
225
  def captionblock(type, lines, caption)
262
- puts %Q[<div class="#{type}">]
263
- unless caption.nil?
264
- puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
265
- end
226
+ puts %Q(<div class="#{type}">)
227
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
266
228
  blocked_lines = split_paragraph(lines)
267
229
  puts blocked_lines.join("\n")
268
230
  puts '</div>'
269
231
  end
270
232
 
271
233
  def memo(lines, caption = nil)
272
- captionblock("memo", lines, caption)
234
+ captionblock('memo', lines, caption)
273
235
  end
274
236
 
275
237
  def tip(lines, caption = nil)
276
- captionblock("tip", lines, caption)
238
+ captionblock('tip', lines, caption)
277
239
  end
278
240
 
279
241
  def info(lines, caption = nil)
280
- captionblock("info", lines, caption)
242
+ captionblock('info', lines, caption)
281
243
  end
282
244
 
283
245
  def planning(lines, caption = nil)
284
- captionblock("planning", lines, caption)
246
+ captionblock('planning', lines, caption)
285
247
  end
286
248
 
287
249
  def best(lines, caption = nil)
288
- captionblock("best", lines, caption)
250
+ captionblock('best', lines, caption)
289
251
  end
290
252
 
291
253
  def important(lines, caption = nil)
292
- captionblock("important", lines, caption)
254
+ captionblock('important', lines, caption)
293
255
  end
294
256
 
295
257
  def security(lines, caption = nil)
296
- captionblock("security", lines, caption)
258
+ captionblock('security', lines, caption)
297
259
  end
298
260
 
299
261
  def caution(lines, caption = nil)
300
- captionblock("caution", lines, caption)
262
+ captionblock('caution', lines, caption)
301
263
  end
302
264
 
303
265
  def notice(lines, caption = nil)
304
- captionblock("notice", lines, caption)
266
+ captionblock('notice', lines, caption)
305
267
  end
306
268
 
307
269
  def warning(lines, caption = nil)
308
- captionblock("warning", lines, caption)
270
+ captionblock('warning', lines, caption)
309
271
  end
310
272
 
311
273
  def point(lines, caption = nil)
312
- captionblock("point", lines, caption)
274
+ captionblock('point', lines, caption)
313
275
  end
314
276
 
315
277
  def shoot(lines, caption = nil)
316
- captionblock("shoot", lines, caption)
278
+ captionblock('shoot', lines, caption)
317
279
  end
318
280
 
319
281
  def box(lines, caption = nil)
320
- puts %Q[<div class="syntax">]
321
- puts %Q[<p class="caption">#{compile_inline(caption)}</p>] unless caption.nil?
322
- print %Q[<pre class="syntax">]
323
- lines.each {|line| puts detab(line) }
282
+ puts %Q(<div class="syntax">)
283
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
284
+ print %Q(<pre class="syntax">)
285
+ lines.each { |line| puts detab(line) }
324
286
  puts '</pre>'
325
287
  puts '</div>'
326
288
  end
327
289
 
328
290
  def note(lines, caption = nil)
329
- captionblock("note", lines, caption)
291
+ captionblock('note', lines, caption)
330
292
  end
331
293
 
332
294
  def ul_begin
@@ -338,7 +300,7 @@ module ReVIEW
338
300
  end
339
301
 
340
302
  def ul_item_end
341
- puts "</li>"
303
+ puts '</li>'
342
304
  end
343
305
 
344
306
  def ul_end
@@ -347,14 +309,14 @@ module ReVIEW
347
309
 
348
310
  def ol_begin
349
311
  if @ol_num
350
- puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
312
+ puts %Q(<ol start="#{@ol_num}">) # it's OK in HTML5, but not OK in XHTML1.1
351
313
  @ol_num = nil
352
314
  else
353
315
  puts '<ol>'
354
316
  end
355
317
  end
356
318
 
357
- def ol_item(lines, num)
319
+ def ol_item(lines, _num)
358
320
  puts "<li>#{lines.join}</li>"
359
321
  end
360
322
 
@@ -379,11 +341,11 @@ module ReVIEW
379
341
  end
380
342
 
381
343
  def paragraph(lines)
382
- if @noindent.nil?
383
- puts "<p>#{lines.join}</p>"
384
- else
385
- puts %Q[<p class="noindent">#{lines.join}</p>]
344
+ if @noindent
345
+ puts %Q(<p class="noindent">#{lines.join}</p>)
386
346
  @noindent = nil
347
+ else
348
+ puts "<p>#{lines.join}</p>"
387
349
  end
388
350
  end
389
351
 
@@ -393,13 +355,13 @@ module ReVIEW
393
355
 
394
356
  def read(lines)
395
357
  blocked_lines = split_paragraph(lines)
396
- puts %Q[<div class="lead">\n#{blocked_lines.join("\n")}\n</div>]
358
+ puts %Q(<div class="lead">\n#{blocked_lines.join("\n")}\n</div>)
397
359
  end
398
360
 
399
361
  alias_method :lead, :read
400
362
 
401
363
  def list(lines, id, caption, lang = nil)
402
- puts %Q[<div id="#{normalize_id(id)}" class="caption-code">]
364
+ puts %Q(<div id="#{normalize_id(id)}" class="caption-code">)
403
365
  begin
404
366
  list_header id, caption, lang
405
367
  rescue KeyError
@@ -409,50 +371,48 @@ module ReVIEW
409
371
  puts '</div>'
410
372
  end
411
373
 
412
- def list_header(id, caption, lang)
413
- if get_chap.nil?
414
- puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
374
+ def list_header(id, caption, _lang)
375
+ if get_chap
376
+ puts %Q(<p class="caption">#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>)
415
377
  else
416
- puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
378
+ puts %Q(<p class="caption">#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>)
417
379
  end
418
380
  end
419
381
 
420
382
  def list_body(id, lines, lang)
421
383
  id ||= ''
422
- class_names = ["list"]
423
- lexer = lang || File.extname(id).gsub(/\./, '')
384
+ class_names = ['list']
385
+ lexer = lang || File.extname(id).gsub('.', '')
424
386
  class_names.push("language-#{lexer}") unless lexer.blank?
425
- class_names.push("highlight") if highlight?
426
- print %Q[<pre class="#{class_names.join(" ")}">]
427
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
428
- puts highlight(:body => body, :lexer => lexer, :format => 'html')
387
+ class_names.push('highlight') if highlight?
388
+ print %Q(<pre class="#{class_names.join(' ')}">)
389
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
390
+ puts highlight(body: body, lexer: lexer, format: 'html')
429
391
  puts '</pre>'
430
392
  end
431
393
 
432
394
  def source(lines, caption = nil, lang = nil)
433
- puts %Q[<div class="source-code">]
395
+ puts %Q(<div class="source-code">)
434
396
  source_header caption
435
397
  source_body caption, lines, lang
436
398
  puts '</div>'
437
399
  end
438
400
 
439
401
  def source_header(caption)
440
- if caption.present?
441
- puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
442
- end
402
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
443
403
  end
444
404
 
445
405
  def source_body(id, lines, lang)
446
406
  id ||= ''
447
- print %Q[<pre class="source">]
448
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
449
- lexer = lang || File.extname(id).gsub(/\./, '')
450
- puts highlight(:body => body, :lexer => lexer, :format => 'html')
407
+ print %Q(<pre class="source">)
408
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
409
+ lexer = lang || File.extname(id).gsub('.', '')
410
+ puts highlight(body: body, lexer: lexer, format: 'html')
451
411
  puts '</pre>'
452
412
  end
453
413
 
454
414
  def listnum(lines, id, caption, lang = nil)
455
- puts %Q[<div id="#{normalize_id(id)}" class="code">]
415
+ puts %Q(<div id="#{normalize_id(id)}" class="code">)
456
416
  begin
457
417
  list_header id, caption, lang
458
418
  rescue KeyError
@@ -464,61 +424,53 @@ module ReVIEW
464
424
 
465
425
  def listnum_body(lines, lang)
466
426
  if highlight?
467
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
427
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
468
428
  lexer = lang
469
- first_line_number = get_line_num
470
- puts highlight(:body => body, :lexer => lexer, :format => 'html', :linenum => true,
471
- :options => {:linenostart => first_line_number})
429
+ first_line_number = line_num
430
+ puts highlight(body: body, lexer: lexer, format: 'html', linenum: true,
431
+ options: { linenostart: first_line_number })
472
432
  else
473
- class_names = ["list"]
433
+ class_names = ['list']
474
434
  class_names.push("language-#{lang}") unless lang.blank?
475
- class_names.push("highlight") if highlight?
476
- print %Q[<pre class="#{class_names.join(" ")}">]
477
- first_line_num = get_line_num
478
- lines.each_with_index do |line, i|
479
- puts detab((i+first_line_num).to_s.rjust(2) + ": " + line)
480
- end
435
+ class_names.push('highlight') if highlight?
436
+ print %Q(<pre class="#{class_names.join(' ')}">)
437
+ first_line_num = line_num
438
+ lines.each_with_index { |line, i| puts detab((i + first_line_num).to_s.rjust(2) + ': ' + line) }
481
439
  puts '</pre>'
482
440
  end
483
441
  end
484
442
 
485
443
  def emlist(lines, caption = nil, lang = nil)
486
- puts %Q[<div class="emlist-code">]
487
- if caption.present?
488
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
489
- end
490
- class_names = ["emlist"]
444
+ puts %Q(<div class="emlist-code">)
445
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
446
+ class_names = ['emlist']
491
447
  class_names.push("language-#{lang}") unless lang.blank?
492
- class_names.push("highlight") if highlight?
493
- print %Q[<pre class="#{class_names.join(" ")}">]
494
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
448
+ class_names.push('highlight') if highlight?
449
+ print %Q(<pre class="#{class_names.join(' ')}">)
450
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
495
451
  lexer = lang
496
- puts highlight(:body => body, :lexer => lexer, :format => 'html')
452
+ puts highlight(body: body, lexer: lexer, format: 'html')
497
453
  puts '</pre>'
498
454
  puts '</div>'
499
455
  end
500
456
 
501
457
  def emlistnum(lines, caption = nil, lang = nil)
502
- puts %Q[<div class="emlistnum-code">]
503
- if caption.present?
504
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
505
- end
458
+ puts %Q(<div class="emlistnum-code">)
459
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
506
460
 
507
461
  if highlight?
508
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
462
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
509
463
  lexer = lang
510
- first_line_number = get_line_num
511
- puts highlight(:body => body, :lexer => lexer, :format => 'html', :linenum => true,
512
- :options => {:linenostart => first_line_number})
464
+ first_line_number = line_num
465
+ puts highlight(body: body, lexer: lexer, format: 'html', linenum: true,
466
+ options: { linenostart: first_line_number })
513
467
  else
514
- class_names = ["emlist"]
468
+ class_names = ['emlist']
515
469
  class_names.push("language-#{lang}") unless lang.blank?
516
- class_names.push("highlight") if highlight?
517
- print %Q[<pre class="#{class_names.join(" ")}">]
518
- first_line_num = get_line_num
519
- lines.each_with_index do |line, i|
520
- puts detab((i+first_line_num).to_s.rjust(2) + ": " + line)
521
- end
470
+ class_names.push('highlight') if highlight?
471
+ print %Q(<pre class="#{class_names.join(' ')}">)
472
+ first_line_num = line_num
473
+ lines.each_with_index { |line, i| puts detab((i + first_line_num).to_s.rjust(2) + ': ' + line) }
522
474
  puts '</pre>'
523
475
  end
524
476
 
@@ -526,77 +478,73 @@ module ReVIEW
526
478
  end
527
479
 
528
480
  def cmd(lines, caption = nil)
529
- puts %Q[<div class="cmd-code">]
530
- if caption.present?
531
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
532
- end
533
- print %Q[<pre class="cmd">]
534
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
481
+ puts %Q(<div class="cmd-code">)
482
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
483
+ print %Q(<pre class="cmd">)
484
+ body = lines.inject('') { |i, j| i + detab(j) + "\n" }
535
485
  lexer = 'shell-session'
536
- puts highlight(:body => body, :lexer => lexer, :format => 'html')
486
+ puts highlight(body: body, lexer: lexer, format: 'html')
537
487
  puts '</pre>'
538
488
  puts '</div>'
539
489
  end
540
490
 
541
491
  def quotedlist(lines, css_class)
542
- print %Q[<blockquote><pre class="#{css_class}">]
543
- lines.each do |line|
544
- puts detab(line)
545
- end
492
+ print %Q(<blockquote><pre class="#{css_class}">)
493
+ lines.each { |line| puts detab(line) }
546
494
  puts '</pre></blockquote>'
547
495
  end
548
496
  private :quotedlist
549
497
 
550
498
  def quote(lines)
551
499
  blocked_lines = split_paragraph(lines)
552
- puts "<blockquote>#{blocked_lines.join("\n")}</blockquote>"
500
+ puts %Q(<blockquote>#{blocked_lines.join("\n")}</blockquote>)
553
501
  end
554
502
 
555
503
  def doorquote(lines, ref)
556
504
  blocked_lines = split_paragraph(lines)
557
- puts %Q[<blockquote style="text-align:right;">]
558
- puts "#{blocked_lines.join("\n")}"
559
- puts %Q[<p>#{ref}より</p>]
560
- puts %Q[</blockquote>]
505
+ puts %Q(<blockquote style="text-align:right;">)
506
+ puts blocked_lines.join("\n")
507
+ puts %Q(<p>#{ref}より</p>)
508
+ puts '</blockquote>'
561
509
  end
562
510
 
563
511
  def talk(lines)
564
- puts %Q[<div class="talk">]
512
+ puts %Q(<div class="talk">)
565
513
  blocked_lines = split_paragraph(lines)
566
- puts "#{blocked_lines.join("\n")}"
514
+ puts blocked_lines.join("\n")
567
515
  puts '</div>'
568
516
  end
569
517
 
570
518
  def texequation(lines)
571
- puts %Q[<div class="equation">]
572
- if @book.config["mathml"]
519
+ puts %Q(<div class="equation">)
520
+ if @book.config['mathml']
573
521
  require 'math_ml'
574
522
  require 'math_ml/symbol/character_reference'
575
- p = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
523
+ p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
576
524
  puts p.parse(unescape_html(lines.join("\n")), true)
577
- elsif @book.config["imgmath"]
578
- puts %Q[<div class="equation">]
525
+ elsif @book.config['imgmath']
526
+ puts %Q(<div class="equation">)
579
527
  math_str = "\\begin{equation*}\n" + unescape_html(lines.join("\n")) + "\n\\end{equation*}\n"
580
528
  key = Digest::SHA256.hexdigest(math_str)
581
- img_path = "./images/_gen_#{key}.png"
529
+ math_dir = "./#{@book.config['imagedir']}/_review_math"
530
+ Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
531
+ img_path = "./#{math_dir}/_gen_#{key}.png"
582
532
  make_math_image(math_str, img_path)
583
- puts %Q[<img src="#{img_path}" />]
533
+ puts %Q(<img src="#{img_path}" />)
584
534
  puts '</div>'
585
535
  else
586
536
  print '<pre>'
587
- puts "#{lines.join("\n")}"
537
+ puts lines.join("\n")
588
538
  puts '</pre>'
589
539
  end
590
540
  puts '</div>'
591
541
  end
592
542
 
593
543
  def handle_metric(str)
594
- if str =~ /\Ascale=([\d.]+)\Z/
595
- return {'class' => sprintf("width-%03dper", ($1.to_f * 100).round)}
596
- else
597
- k, v = str.split('=', 2)
598
- return {k => v.sub(/\A["']/, '').sub(/["']\Z/, '')}
599
- end
544
+ return { 'class' => sprintf('width-%03dper', ($1.to_f * 100).round) } if str =~ /\Ascale=([\d.]+)\Z/
545
+
546
+ k, v = str.split('=', 2)
547
+ { k => v.sub(/\A["']/, '').sub(/["']\Z/, '') }
600
548
  end
601
549
 
602
550
  def result_metric(array)
@@ -609,37 +557,35 @@ module ReVIEW
609
557
  attrs[k] = [item[k]]
610
558
  end
611
559
  end
612
- " "+attrs.map{|k, v| %Q|#{k}="#{v.join(' ')}"| }.join(' ')
560
+ ' ' + attrs.map { |k, v| %Q(#{k}="#{v.join(' ')}") }.join(' ')
613
561
  end
614
562
 
615
563
  def image_image(id, caption, metric)
616
- metrics = parse_metric("html", metric)
617
- puts %Q[<div id="#{normalize_id(id)}" class="image">]
618
- puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
564
+ metrics = parse_metric('html', metric)
565
+ puts %Q(<div id="#{normalize_id(id)}" class="image">)
566
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
619
567
  image_header id, caption
620
- puts %Q[</div>]
568
+ puts '</div>'
621
569
  end
622
570
 
623
571
  def image_dummy(id, caption, lines)
624
- puts %Q[<div id="#{normalize_id(id)}" class="image">]
625
- puts %Q[<pre class="dummyimage">]
626
- lines.each do |line|
627
- puts detab(line)
628
- end
629
- puts %Q[</pre>]
572
+ warn "image not bound: #{id}"
573
+ puts %Q(<div id="#{normalize_id(id)}" class="image">)
574
+ puts %Q(<pre class="dummyimage">)
575
+ lines.each { |line| puts detab(line) }
576
+ puts '</pre>'
630
577
  image_header id, caption
631
- puts %Q[</div>]
632
- warn "no such image: #{id}"
578
+ puts '</div>'
633
579
  end
634
580
 
635
581
  def image_header(id, caption)
636
- puts %Q[<p class="caption">]
637
- if get_chap.nil?
638
- puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
582
+ puts %Q(<p class="caption">)
583
+ if get_chap
584
+ puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
639
585
  else
640
- puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
586
+ puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
641
587
  end
642
- puts %Q[</p>]
588
+ puts '</p>'
643
589
  end
644
590
 
645
591
  def table(lines, id = nil, caption = nil)
@@ -648,56 +594,50 @@ module ReVIEW
648
594
  lines.each_with_index do |line, idx|
649
595
  if /\A[\=\-]{12}/ =~ line
650
596
  # just ignore
651
- #error "too many table separator" if sepidx
597
+ # error "too many table separator" if sepidx
652
598
  sepidx ||= idx
653
599
  next
654
600
  end
655
- rows.push(line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') })
601
+ rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
656
602
  end
657
603
  rows = adjust_n_cols(rows)
658
604
 
659
605
  if id
660
- puts %Q[<div id="#{normalize_id(id)}" class="table">]
606
+ puts %Q(<div id="#{normalize_id(id)}" class="table">)
661
607
  else
662
- puts %Q[<div class="table">]
608
+ puts %Q(<div class="table">)
663
609
  end
664
610
  begin
665
- table_header id, caption unless caption.nil?
611
+ table_header id, caption if caption.present?
666
612
  rescue KeyError
667
613
  error "no such table: #{id}"
668
614
  end
669
615
  table_begin rows.first.size
670
616
  return if rows.empty?
671
617
  if sepidx
672
- sepidx.times do
673
- tr (rows.shift.map {|s| th(s) })
674
- end
675
- rows.each do |cols|
676
- tr (cols.map {|s| td(s) })
677
- end
618
+ sepidx.times { tr(rows.shift.map { |s| th(s) }) }
619
+ rows.each { |cols| tr(cols.map { |s| td(s) }) }
678
620
  else
679
621
  rows.each do |cols|
680
622
  h, *cs = *cols
681
- tr ([th(h)] + cs.map {|s| td(s) })
623
+ tr([th(h)] + cs.map { |s| td(s) })
682
624
  end
683
625
  end
684
626
  table_end
685
- puts %Q[</div>]
627
+ puts '</div>'
686
628
  end
687
629
 
688
630
  def table_header(id, caption)
689
631
  if id.nil?
690
- puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
632
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
633
+ elsif get_chap
634
+ puts %Q(<p class="caption">#{I18n.t('table')}#{I18n.t('format_number_header', [get_chap, @chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>)
691
635
  else
692
- if get_chap.nil?
693
- puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
694
- else
695
- puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
696
- end
636
+ puts %Q(<p class="caption">#{I18n.t('table')}#{I18n.t('format_number_header_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>)
697
637
  end
698
638
  end
699
639
 
700
- def table_begin(ncols)
640
+ def table_begin(_ncols)
701
641
  puts '<table>'
702
642
  end
703
643
 
@@ -718,27 +658,27 @@ module ReVIEW
718
658
  end
719
659
 
720
660
  def imgtable(lines, id, caption = nil, metric = nil)
721
- if !@chapter.image(id).bound?
661
+ unless @chapter.image(id).bound?
722
662
  warn "image not bound: #{id}"
723
663
  image_dummy id, caption, lines
724
664
  return
725
665
  end
726
666
 
727
- puts %Q[<div id="#{normalize_id(id)}" class="imgtable image">]
667
+ puts %Q(<div id="#{normalize_id(id)}" class="imgtable image">)
728
668
  begin
729
- table_header id, caption unless caption.nil?
669
+ table_header id, caption if caption.present?
730
670
  rescue KeyError
731
671
  error "no such table: #{id}"
732
672
  end
733
673
 
734
674
  imgtable_image(id, caption, metric)
735
675
 
736
- puts %Q[</div>]
676
+ puts '</div>'
737
677
  end
738
678
 
739
679
  def imgtable_image(id, caption, metric)
740
- metrics = parse_metric("html", metric)
741
- puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
680
+ metrics = parse_metric('html', metric)
681
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
742
682
  end
743
683
 
744
684
  def emtable(lines, caption = nil)
@@ -748,42 +688,46 @@ module ReVIEW
748
688
  def comment(lines, comment = nil)
749
689
  lines ||= []
750
690
  lines.unshift comment unless comment.blank?
751
- if @book.config["draft"]
752
- str = lines.join("<br />")
753
- puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
754
- end
691
+ return unless @book.config['draft']
692
+ str = lines.join('<br />')
693
+ puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
755
694
  end
756
695
 
757
696
  def footnote(id, str)
758
- if @book.config["epubversion"].to_i == 3
697
+ if @book.config['epubversion'].to_i == 3
759
698
  puts %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[*#{@chapter.footnote(id).number}] #{compile_inline(str)}</p></div>)
760
699
  else
761
700
  puts %Q(<div class="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[<a href="#fnb-#{normalize_id(id)}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>)
762
701
  end
763
702
  end
764
703
 
765
- def indepimage(id, caption="", metric=nil)
766
- metrics = parse_metric("html", metric)
767
- caption = "" if caption.nil?
768
- puts %Q[<div id="#{normalize_id(id)}" class="image">]
704
+ def indepimage(lines, id, caption = '', metric = nil)
705
+ metrics = parse_metric('html', metric)
706
+ caption = '' unless caption.present?
707
+ puts %Q(<div id="#{normalize_id(id)}" class="image">)
769
708
  begin
770
- puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
709
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
771
710
  rescue
772
- puts %Q[<pre>missing image: #{id}</pre>]
711
+ warn "image not bound: #{id}"
712
+ if lines
713
+ puts %Q(<pre class="dummyimage">)
714
+ lines.each { |line| puts detab(line) }
715
+ puts '</pre>'
716
+ end
773
717
  end
774
718
 
775
- unless caption.empty?
776
- puts %Q[<p class="caption">]
777
- puts %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
778
- puts %Q[</p>]
719
+ if caption.present?
720
+ puts %Q(<p class="caption">)
721
+ puts %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
722
+ puts '</p>'
779
723
  end
780
- puts %Q[</div>]
724
+ puts '</div>'
781
725
  end
782
726
 
783
727
  alias_method :numberlessimage, :indepimage
784
728
 
785
729
  def hr
786
- puts "<hr />"
730
+ puts '<hr />'
787
731
  end
788
732
 
789
733
  def label(id)
@@ -791,7 +735,7 @@ module ReVIEW
791
735
  end
792
736
 
793
737
  def linebreak
794
- puts "<br />"
738
+ puts '<br />'
795
739
  end
796
740
 
797
741
  def pagebreak
@@ -799,11 +743,9 @@ module ReVIEW
799
743
  end
800
744
 
801
745
  def bpo(lines)
802
- puts "<bpo>"
803
- lines.each do |line|
804
- puts detab(line)
805
- end
806
- puts "</bpo>"
746
+ puts '<bpo>'
747
+ lines.each { |line| puts detab(line) }
748
+ puts '</bpo>'
807
749
  end
808
750
 
809
751
  def noindent
@@ -811,14 +753,18 @@ module ReVIEW
811
753
  end
812
754
 
813
755
  def inline_labelref(idref)
814
- %Q[<a target='#{escape_html(idref)}'>「#{I18n.t("label_marker")}#{escape_html(idref)}」</a>]
756
+ %Q(<a target='#{escape_html(idref)}'>「#{I18n.t('label_marker')}#{escape_html(idref)}」</a>)
815
757
  end
816
758
 
817
759
  alias_method :inline_ref, :inline_labelref
818
760
 
761
+ def inline_pageref(id)
762
+ error "pageref op is unsupported on this builder: #{id}"
763
+ end
764
+
819
765
  def inline_chapref(id)
820
766
  title = super
821
- if @book.config["chapterlink"]
767
+ if @book.config['chapterlink']
822
768
  %Q(<a href="./#{id}#{extname}">#{title}</a>)
823
769
  else
824
770
  title
@@ -829,7 +775,7 @@ module ReVIEW
829
775
  end
830
776
 
831
777
  def inline_chap(id)
832
- if @book.config["chapterlink"]
778
+ if @book.config['chapterlink']
833
779
  %Q(<a href="./#{id}#{extname}">#{@book.chapter_index.number(id)}</a>)
834
780
  else
835
781
  @book.chapter_index.number(id)
@@ -841,7 +787,7 @@ module ReVIEW
841
787
 
842
788
  def inline_title(id)
843
789
  title = super
844
- if @book.config["chapterlink"]
790
+ if @book.config['chapterlink']
845
791
  %Q(<a href="./#{id}#{extname}">#{title}</a>)
846
792
  else
847
793
  title
@@ -852,7 +798,7 @@ module ReVIEW
852
798
  end
853
799
 
854
800
  def inline_fn(id)
855
- if @book.config["epubversion"].to_i == 3
801
+ if @book.config['epubversion'].to_i == 3
856
802
  %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref" epub:type="noteref">*#{@chapter.footnote(id).number}</a>)
857
803
  else
858
804
  %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.footnote(id).number}</a>)
@@ -861,14 +807,14 @@ module ReVIEW
861
807
 
862
808
  def compile_ruby(base, ruby)
863
809
  if @book.htmlversion == 5
864
- %Q[<ruby>#{escape_html(base)}<rp>#{I18n.t("ruby_prefix")}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
810
+ %Q(<ruby>#{escape_html(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
865
811
  else
866
- %Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
812
+ %Q(<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
867
813
  end
868
814
  end
869
815
 
870
816
  def compile_kw(word, alt)
871
- %Q[<b class="kw">] +
817
+ %Q(<b class="kw">) +
872
818
  if alt
873
819
  then escape_html(word + " (#{alt.strip})")
874
820
  else escape_html(word)
@@ -928,24 +874,26 @@ module ReVIEW
928
874
  %Q(<!-- IDX:#{escape_comment(escape_html(str))} -->)
929
875
  end
930
876
 
931
- def inline_br(str)
932
- %Q(<br />)
877
+ def inline_br(_str)
878
+ '<br />'
933
879
  end
934
880
 
935
881
  def inline_m(str)
936
- if @book.config["mathml"]
882
+ if @book.config['mathml']
937
883
  require 'math_ml'
938
884
  require 'math_ml/symbol/character_reference'
939
- parser = MathML::LaTeX::Parser.new(:symbol => MathML::Symbol::CharacterReference)
940
- %Q[<span class="equation">#{parser.parse(str, nil)}</span>]
941
- elsif @book.config["imgmath"]
942
- math_str = "$" + str + "$"
885
+ parser = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
886
+ %Q(<span class="equation">#{parser.parse(str, nil)}</span>)
887
+ elsif @book.config['imgmath']
888
+ math_str = '$' + str + '$'
943
889
  key = Digest::SHA256.hexdigest(str)
944
- img_path = "./images/_gen_#{key}.png"
890
+ math_dir = "./#{@book.config['imagedir']}/_review_math"
891
+ Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
892
+ img_path = "./#{math_dir}/_gen_#{key}.png"
945
893
  make_math_image(math_str, img_path)
946
- %Q[<span class="equation"><img src="#{img_path}" /></span>]
894
+ %Q(<span class="equation"><img src="#{img_path}" /></span>)
947
895
  else
948
- %Q[<span class="equation">#{escape_html(str)}</span>]
896
+ %Q(<span class="equation">#{escape_html(str)}</span>)
949
897
  end
950
898
  end
951
899
 
@@ -954,23 +902,21 @@ module ReVIEW
954
902
  end
955
903
 
956
904
  def bibpaper(lines, id, caption)
957
- puts %Q[<div class="bibpaper">]
905
+ puts %Q(<div class="bibpaper">)
958
906
  bibpaper_header id, caption
959
- unless lines.empty?
960
- bibpaper_bibpaper id, caption, lines
961
- end
962
- puts "</div>"
907
+ bibpaper_bibpaper id, caption, lines unless lines.empty?
908
+ puts '</div>'
963
909
  end
964
910
 
965
911
  def bibpaper_header(id, caption)
966
912
  print %Q(<a id="bib-#{normalize_id(id)}">)
967
913
  print "[#{@chapter.bibpaper(id).number}]"
968
- print %Q(</a>)
914
+ print '</a>'
969
915
  puts " #{compile_inline(caption)}"
970
916
  end
971
917
 
972
- def bibpaper_bibpaper(id, caption, lines)
973
- print split_paragraph(lines).join("")
918
+ def bibpaper_bibpaper(_id, _caption, lines)
919
+ print split_paragraph(lines).join
974
920
  end
975
921
 
976
922
  def inline_bib(id)
@@ -979,42 +925,42 @@ module ReVIEW
979
925
 
980
926
  def inline_hd_chap(chap, id)
981
927
  n = chap.headline_index.number(id)
982
- if chap.number and @book.config["secnolevel"] >= n.split('.').size
983
- str = I18n.t("chapter_quote", "#{n} #{compile_inline(chap.headline(id).caption)}")
928
+ if chap.number and @book.config['secnolevel'] >= n.split('.').size
929
+ str = I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
984
930
  else
985
- str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
931
+ str = I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
986
932
  end
987
- if @book.config["chapterlink"]
988
- anchor = "h"+n.gsub(/\./, "-")
933
+ if @book.config['chapterlink']
934
+ anchor = 'h' + n.gsub('.', '-')
989
935
  %Q(<a href="#{chap.id}#{extname}##{anchor}">#{str}</a>)
990
936
  else
991
937
  str
992
938
  end
993
939
  end
994
940
 
995
- def column_label(id)
996
- num = @chapter.column(id).number
941
+ def column_label(id, chapter = @chapter)
942
+ num = chapter.column(id).number
997
943
  "column-#{num}"
998
944
  end
999
945
  private :column_label
1000
946
 
1001
947
  def inline_column_chap(chapter, id)
1002
- if @book.config["chapterlink"]
1003
- %Q(<a href="\##{column_label(id)}" class="columnref">#{I18n.t("column", compile_inline(chapter.column(id).caption))}</a>)
948
+ if @book.config['chapterlink']
949
+ %Q(<a href="\##{column_label(id, chapter)}" class="columnref">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</a>)
1004
950
  else
1005
- I18n.t("column", compile_inline(chapter.column(id).caption))
951
+ I18n.t('column', compile_inline(chapter.column(id).caption))
1006
952
  end
1007
953
  end
1008
954
 
1009
955
  def inline_list(id)
1010
956
  chapter, id = extract_chapter_id(id)
1011
- str = nil
1012
- if get_chap(chapter).nil?
1013
- str = "#{I18n.t("list")}#{I18n.t("format_number_without_header", [chapter.list(id).number])}"
1014
- else
1015
- str = "#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}"
1016
- end
1017
- if @book.config["chapterlink"]
957
+ str =
958
+ if get_chap(chapter)
959
+ "#{I18n.t('list')}#{I18n.t('format_number', [get_chap(chapter), chapter.list(id).number])}"
960
+ else
961
+ "#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [chapter.list(id).number])}"
962
+ end
963
+ if @book.config['chapterlink']
1018
964
  %Q(<span class="listref"><a href="./#{chapter.id}#{extname}##{id}">#{str}</a></span>)
1019
965
  else
1020
966
  %Q(<span class="listref">#{str}</span>)
@@ -1026,13 +972,13 @@ module ReVIEW
1026
972
 
1027
973
  def inline_table(id)
1028
974
  chapter, id = extract_chapter_id(id)
1029
- str = nil
1030
- if get_chap(chapter).nil?
1031
- str = "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
1032
- else
1033
- str = "#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
1034
- end
1035
- if @book.config["chapterlink"]
975
+ str =
976
+ if get_chap(chapter)
977
+ "#{I18n.t('table')}#{I18n.t('format_number', [get_chap(chapter), chapter.table(id).number])}"
978
+ else
979
+ "#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [chapter.table(id).number])}"
980
+ end
981
+ if @book.config['chapterlink']
1036
982
  %Q(<span class="tableref"><a href="./#{chapter.id}#{extname}##{id}">#{str}</a></span>)
1037
983
  else
1038
984
  %Q(<span class="tableref">#{str}</span>)
@@ -1044,13 +990,13 @@ module ReVIEW
1044
990
 
1045
991
  def inline_img(id)
1046
992
  chapter, id = extract_chapter_id(id)
1047
- str = nil
1048
- if get_chap(chapter).nil?
1049
- str = "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
1050
- else
1051
- str = "#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
1052
- end
1053
- if @book.config["chapterlink"]
993
+ str =
994
+ if get_chap(chapter)
995
+ "#{I18n.t('image')}#{I18n.t('format_number', [get_chap(chapter), chapter.image(id).number])}"
996
+ else
997
+ "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])}"
998
+ end
999
+ if @book.config['chapterlink']
1054
1000
  %Q(<span class="imgref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>)
1055
1001
  else
1056
1002
  %Q(<span class="imgref">#{str}</span>)
@@ -1065,55 +1011,55 @@ module ReVIEW
1065
1011
  end
1066
1012
 
1067
1013
  def inline_abbr(str)
1068
- inline_asis(str, "abbr")
1014
+ inline_asis(str, 'abbr')
1069
1015
  end
1070
1016
 
1071
1017
  def inline_acronym(str)
1072
- inline_asis(str, "acronym")
1018
+ inline_asis(str, 'acronym')
1073
1019
  end
1074
1020
 
1075
1021
  def inline_cite(str)
1076
- inline_asis(str, "cite")
1022
+ inline_asis(str, 'cite')
1077
1023
  end
1078
1024
 
1079
1025
  def inline_dfn(str)
1080
- inline_asis(str, "dfn")
1026
+ inline_asis(str, 'dfn')
1081
1027
  end
1082
1028
 
1083
1029
  def inline_em(str)
1084
- inline_asis(str, "em")
1030
+ inline_asis(str, 'em')
1085
1031
  end
1086
1032
 
1087
1033
  def inline_kbd(str)
1088
- inline_asis(str, "kbd")
1034
+ inline_asis(str, 'kbd')
1089
1035
  end
1090
1036
 
1091
1037
  def inline_samp(str)
1092
- inline_asis(str, "samp")
1038
+ inline_asis(str, 'samp')
1093
1039
  end
1094
1040
 
1095
1041
  def inline_strong(str)
1096
- inline_asis(str, "strong")
1042
+ inline_asis(str, 'strong')
1097
1043
  end
1098
1044
 
1099
1045
  def inline_var(str)
1100
- inline_asis(str, "var")
1046
+ inline_asis(str, 'var')
1101
1047
  end
1102
1048
 
1103
1049
  def inline_big(str)
1104
- inline_asis(str, "big")
1050
+ inline_asis(str, 'big')
1105
1051
  end
1106
1052
 
1107
1053
  def inline_small(str)
1108
- inline_asis(str, "small")
1054
+ inline_asis(str, 'small')
1109
1055
  end
1110
1056
 
1111
1057
  def inline_sub(str)
1112
- inline_asis(str, "sub")
1058
+ inline_asis(str, 'sub')
1113
1059
  end
1114
1060
 
1115
1061
  def inline_sup(str)
1116
- inline_asis(str, "sup")
1062
+ inline_asis(str, 'sup')
1117
1063
  end
1118
1064
 
1119
1065
  def inline_tt(str)
@@ -1125,11 +1071,11 @@ module ReVIEW
1125
1071
  end
1126
1072
 
1127
1073
  def inline_del(str)
1128
- inline_asis(str, "del")
1074
+ inline_asis(str, 'del')
1129
1075
  end
1130
1076
 
1131
1077
  def inline_ins(str)
1132
- inline_asis(str, "ins")
1078
+ inline_asis(str, 'ins')
1133
1079
  end
1134
1080
 
1135
1081
  def inline_u(str)
@@ -1142,9 +1088,10 @@ module ReVIEW
1142
1088
 
1143
1089
  def inline_icon(id)
1144
1090
  begin
1145
- %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="[#{id}]" />]
1091
+ %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="[#{id}]" />)
1146
1092
  rescue
1147
- %Q[<pre>missing image: #{id}</pre>]
1093
+ warn "image not bound: #{id}"
1094
+ %Q(<pre>missing image: #{id}</pre>)
1148
1095
  end
1149
1096
  end
1150
1097
 
@@ -1153,18 +1100,18 @@ module ReVIEW
1153
1100
  end
1154
1101
 
1155
1102
  def inline_comment(str)
1156
- if @book.config["draft"]
1103
+ if @book.config['draft']
1157
1104
  %Q(<span class="draft-comment">#{escape_html(str)}</span>)
1158
1105
  else
1159
- ""
1106
+ ''
1160
1107
  end
1161
1108
  end
1162
1109
 
1163
1110
  def inline_tcy(str)
1164
1111
  # 縦中横用のtcy、uprightのCSSスタイルについては電書協ガイドラインを参照
1165
- style = "tcy"
1166
- style = "upright" if str.size == 1 && str.match(/[[:ascii:]]/)
1167
- %Q[<span class="#{style}">#{escape_html(str)}</span>]
1112
+ style = 'tcy'
1113
+ style = 'upright' if str.size == 1 && str.match(/[[:ascii:]]/)
1114
+ %Q(<span class="#{style}">#{escape_html(str)}</span>)
1168
1115
  end
1169
1116
 
1170
1117
  def inline_raw(str)
@@ -1176,7 +1123,7 @@ module ReVIEW
1176
1123
  end
1177
1124
 
1178
1125
  def compile_href(url, label)
1179
- if @book.config["externallink"]
1126
+ if @book.config['externallink']
1180
1127
  %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
1181
1128
  else
1182
1129
  label.nil? ? escape_html(url) : I18n.t('external_link', [escape_html(label), escape_html(url)])
@@ -1184,23 +1131,23 @@ module ReVIEW
1184
1131
  end
1185
1132
 
1186
1133
  def flushright(lines)
1187
- puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"flushright\">")
1134
+ puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="flushright">))
1188
1135
  end
1189
1136
 
1190
1137
  def centering(lines)
1191
- puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"center\">")
1138
+ puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="center">))
1192
1139
  end
1193
1140
 
1194
1141
  def image_ext
1195
- "png"
1142
+ 'png'
1196
1143
  end
1197
1144
 
1198
1145
  def olnum(num)
1199
1146
  @ol_num = num.to_i
1200
1147
  end
1201
1148
 
1202
- def make_math_image(str, path, fontsize=12)
1203
- fontsize2 = (fontsize*1.2).round.to_i
1149
+ def make_math_image(str, path, fontsize = 12)
1150
+ fontsize2 = (fontsize * 1.2).round.to_i
1204
1151
  texsrc = <<-EOB
1205
1152
  \\documentclass[12pt]{article}
1206
1153
  \\usepackage[utf8]{inputenc}
@@ -1217,13 +1164,11 @@ module ReVIEW
1217
1164
  \\end{document}
1218
1165
  EOB
1219
1166
  Dir.mktmpdir do |tmpdir|
1220
- tex_path = File.join(tmpdir, "tmpmath.tex")
1221
- dvi_path = File.join(tmpdir, "tmpmath.dvi")
1167
+ tex_path = File.join(tmpdir, 'tmpmath.tex')
1168
+ dvi_path = File.join(tmpdir, 'tmpmath.dvi')
1222
1169
  File.write(tex_path, texsrc)
1223
1170
  system("latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}")
1224
1171
  end
1225
1172
  end
1226
-
1227
1173
  end
1228
-
1229
1174
  end # module ReVIEW