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
@@ -12,7 +9,6 @@
12
9
  module ReVIEW
13
10
  module Book
14
11
  class PageMetric
15
-
16
12
  MetricData = Struct.new(:n_lines, :n_columns)
17
13
 
18
14
  def initialize(list_lines, list_columns, text_lines, text_columns, page_per_kbyte)
@@ -31,7 +27,6 @@ module ReVIEW
31
27
  def ==(other)
32
28
  self.list == other.list && self.text == other.text && self.page_per_kbyte == other.page_per_kbyte
33
29
  end
34
-
35
30
  end
36
31
  end
37
32
  end
@@ -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-2016 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
@@ -10,6 +7,7 @@
10
7
  # For details of the GNU LGPL, see the file "COPYING".
11
8
  #
12
9
  require 'review/book/compilable'
10
+
13
11
  module ReVIEW
14
12
  module Book
15
13
  class Part
@@ -17,24 +15,21 @@ module ReVIEW
17
15
 
18
16
  # if Part is dummy, `number` is nil.
19
17
  #
20
- def initialize(book, number, chapters, name = "", io = nil)
18
+ def initialize(book, number, chapters, name = '', io = nil)
21
19
  @book = book
22
20
  @number = number
23
21
  @chapters = chapters
24
- @name = name ? File.basename(name, '.re') : nil
22
+ @name = name
25
23
  @path = name
24
+ @content = nil
26
25
  if io
27
26
  @content = io.read
28
27
  elsif @path && File.exist?(@path)
29
- @content = File.read(@path, :mode => 'r:BOM|utf-8')
30
- else
31
- @content = nil
32
- end
33
- if file?
34
- @title = nil
35
- else
36
- @title = name
28
+ @content = File.read(@path, mode: 'r:BOM|utf-8')
29
+ @name = File.basename(@name, '.re')
37
30
  end
31
+ @title = name
32
+ @title = nil if file?
38
33
  @volume = nil
39
34
  end
40
35
 
@@ -47,26 +42,29 @@ module ReVIEW
47
42
  end
48
43
 
49
44
  def volume
50
- vol = Volume.sum(@chapters.map {|chap| chap.volume })
45
+ vol = Volume.sum(@chapters.map(&:volume))
51
46
  vol.page_per_kbyte = @book.page_metric.page_per_kbyte
52
47
  vol
53
48
  end
54
49
 
55
50
  def file?
56
- (name.present? and path.end_with?('.re')) ? true : false
51
+ name.present? and path.end_with?('.re') ? true : false
57
52
  end
58
53
 
59
54
  def format_number(heading = true)
60
55
  if heading
61
- "#{I18n.t("part", @number)}"
56
+ I18n.t('part', @number)
62
57
  else
63
- "#{@number}"
58
+ @number.to_s
64
59
  end
65
60
  end
66
61
 
67
- def on_APPENDIX?
62
+ def on_appendix?
68
63
  false
69
64
  end
65
+
66
+ # backward compatibility
67
+ alias_method :on_APPENDIX?, :on_appendix?
70
68
  end
71
69
  end
72
70
  end
@@ -1,7 +1,5 @@
1
- #
2
- # $Id: volume.rb 3883 2008-02-10 11:48:23Z aamine $
3
- #
4
- # Copyright (c) 2002-2007 Minero Aoki
1
+ # Copyright (c) 2007-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2007 Minero Aoki
5
3
  #
6
4
  # This program is free software.
7
5
  # You can distribute or modify this program under the terms of
@@ -11,11 +9,10 @@
11
9
  module ReVIEW
12
10
  module Book
13
11
  class Volume
14
-
15
- def Volume.count_file(path)
12
+ def self.count_file(path)
16
13
  b = c = l = 0
17
14
  File.foreach(path) do |line|
18
- next if %r<\A\#@> =~ line
15
+ next if /\A\#@/ =~ line
19
16
  text = line.gsub(/\s+/, '')
20
17
  b += text.bytesize
21
18
  c += text.charsize
@@ -24,11 +21,11 @@ module ReVIEW
24
21
  new(b, c, l)
25
22
  end
26
23
 
27
- def Volume.sum(vols)
28
- vols.inject(new()) {|sum, i| sum + i }
24
+ def self.sum(vols)
25
+ vols.inject(new) { |sum, i| sum + i }
29
26
  end
30
27
 
31
- def Volume.dummy
28
+ def self.dummy
32
29
  new(-1, -1, -1)
33
30
  end
34
31
 
@@ -49,11 +46,11 @@ module ReVIEW
49
46
  end
50
47
 
51
48
  def page
52
- (kbytes.to_f/@page_per_kbyte).ceil
49
+ (kbytes.to_f / @page_per_kbyte).ceil
53
50
  end
54
51
 
55
52
  def to_s
56
- "#{kbytes()}KB #{@chars}C #{@lines}L #{page()}P"
53
+ "#{kbytes}KB #{@chars}C #{@lines}L #{page}P"
57
54
  end
58
55
 
59
56
  def +(other)
@@ -61,7 +58,6 @@ module ReVIEW
61
58
  @chars + other.chars,
62
59
  @lines + other.lines)
63
60
  end
64
-
65
61
  end
66
62
  end
67
63
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # Copyright (c) 2002-2017 Minero Aoki, Kenshi Muto
4
2
  #
5
3
  # This program is free software.
@@ -16,11 +14,10 @@ require 'stringio'
16
14
  require 'cgi'
17
15
 
18
16
  module ReVIEW
19
-
20
17
  class Builder
21
18
  include TextUtils
22
19
 
23
- CAPTION_TITLES = %w(note memo tip info warning important caution notice)
20
+ CAPTION_TITLES = %w[note memo tip info warning important caution notice].freeze
24
21
 
25
22
  def pre_paragraph
26
23
  nil
@@ -33,6 +30,7 @@ module ReVIEW
33
30
  def initialize(strict = false, *args)
34
31
  @strict = strict
35
32
  @output = nil
33
+ @logger = ReVIEW.logger
36
34
  builder_init(*args)
37
35
  end
38
36
 
@@ -48,9 +46,7 @@ module ReVIEW
48
46
  @book = @chapter.book if @chapter.present?
49
47
  @tabwidth = nil
50
48
  @tsize = nil
51
- if @book && @book.config && @book.config["tabwidth"]
52
- @tabwidth = @book.config["tabwidth"]
53
- end
49
+ @tabwidth = @book.config['tabwidth'] if @book && @book.config && @book.config['tabwidth']
54
50
  builder_init_file
55
51
  end
56
52
 
@@ -80,7 +76,7 @@ module ReVIEW
80
76
  def headline_prefix(level)
81
77
  @sec_counter.inc(level)
82
78
  anchor = @sec_counter.anchor(level)
83
- prefix = @sec_counter.prefix(level, @book.config["secnolevel"])
79
+ prefix = @sec_counter.prefix(level, @book.config['secnolevel'])
84
80
  [prefix, anchor]
85
81
  end
86
82
  private :headline_prefix
@@ -90,14 +86,12 @@ module ReVIEW
90
86
  @first_line_num = num.to_i
91
87
  end
92
88
 
93
- def get_line_num
94
- if !@first_line_num
95
- return 1
96
- end
97
- line_num = @first_line_num
89
+ def line_num
90
+ return 1 unless @first_line_num
91
+ line_n = @first_line_num
98
92
  @first_line_num = nil
99
93
 
100
- line_num
94
+ line_n
101
95
  end
102
96
 
103
97
  def list(lines, id, caption, lang = nil)
@@ -138,47 +132,37 @@ module ReVIEW
138
132
  lines.each_with_index do |line, idx|
139
133
  if /\A[\=\-]{12}/ =~ line
140
134
  # just ignore
141
- #error "too many table separator" if sepidx
135
+ # error "too many table separator" if sepidx
142
136
  sepidx ||= idx
143
137
  next
144
138
  end
145
- rows.push(line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') })
139
+ rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
146
140
  end
147
141
  rows = adjust_n_cols(rows)
148
142
 
149
143
  begin
150
- table_header id, caption unless caption.nil?
144
+ table_header id, caption if caption.present?
151
145
  rescue KeyError
152
146
  error "no such table: #{id}"
153
147
  end
154
148
  return if rows.empty?
155
149
  table_begin rows.first.size
156
150
  if sepidx
157
- sepidx.times do
158
- tr(rows.shift.map {|s| th(s) })
159
- end
160
- rows.each do |cols|
161
- tr(cols.map {|s| td(s) })
162
- end
151
+ sepidx.times { tr(rows.shift.map { |s| th(s) }) }
152
+ rows.each { |cols| tr(cols.map { |s| td(s) }) }
163
153
  else
164
154
  rows.each do |cols|
165
155
  h, *cs = *cols
166
- tr([th(h)] + cs.map {|s| td(s) })
156
+ tr([th(h)] + cs.map { |s| td(s) })
167
157
  end
168
158
  end
169
159
  table_end
170
160
  end
171
161
 
172
162
  def adjust_n_cols(rows)
173
- rows.each do |cols|
174
- while cols.last and cols.last.strip.empty?
175
- cols.pop
176
- end
177
- end
178
- n_maxcols = rows.map {|cols| cols.size }.max
179
- rows.each do |cols|
180
- cols.concat [''] * (n_maxcols - cols.size)
181
- end
163
+ rows.each { |cols| cols.pop while cols.last and cols.last.strip.empty? }
164
+ n_maxcols = rows.map(&:size).max
165
+ rows.each { |cols| cols.concat [''] * (n_maxcols - cols.size) }
182
166
  rows
183
167
  end
184
168
  private :adjust_n_cols
@@ -187,17 +171,17 @@ module ReVIEW
187
171
  table(lines, nil, caption)
188
172
  end
189
173
 
190
- #def footnote(id, str)
191
- # @footnotes.push [id, str]
192
- #end
174
+ # def footnote(id, str)
175
+ # @footnotes.push [id, str]
176
+ # end
193
177
  #
194
- #def flush_footnote
195
- # footnote_begin
196
- # @footnotes.each do |id, str|
197
- # footnote_item(id, str)
198
- # end
199
- # footnote_end
200
- #end
178
+ # def flush_footnote
179
+ # footnote_begin
180
+ # @footnotes.each do |id, str|
181
+ # footnote_item(id, str)
182
+ # end
183
+ # footnote_end
184
+ # end
201
185
 
202
186
  def compile_inline(s)
203
187
  @compiler.text(s)
@@ -225,14 +209,14 @@ module ReVIEW
225
209
  end
226
210
 
227
211
  def inline_list(id)
228
- "#{I18n.t("list")}#{@chapter.list(id).number}"
212
+ "#{I18n.t('list')}#{@chapter.list(id).number}"
229
213
  rescue KeyError
230
214
  error "unknown list: #{id}"
231
215
  nofunc_text("[UnknownList:#{id}]")
232
216
  end
233
217
 
234
218
  def inline_img(id)
235
- "#{I18n.t("image")}#{@chapter.image(id).number}"
219
+ "#{I18n.t('image')}#{@chapter.image(id).number}"
236
220
  rescue KeyError
237
221
  error "unknown image: #{id}"
238
222
  nofunc_text("[UnknownImage:#{id}]")
@@ -249,7 +233,7 @@ module ReVIEW
249
233
  end
250
234
 
251
235
  def inline_table(id)
252
- "#{I18n.t("table")}#{@chapter.table(id).number}"
236
+ "#{I18n.t('table')}#{@chapter.table(id).number}"
253
237
  rescue KeyError
254
238
  error "unknown table: #{id}"
255
239
  nofunc_text("[UnknownTable:#{id}]")
@@ -268,8 +252,8 @@ module ReVIEW
268
252
 
269
253
  def inline_ruby(arg)
270
254
  base, *ruby = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/)
271
- base = base.gsub(/\\,/, ",") if base
272
- ruby = ruby.join(",").gsub(/\\,/, ",") if ruby
255
+ base = base.gsub(/\\,/, ',') if base
256
+ ruby = ruby.join(',').gsub(/\\,/, ',') if ruby
273
257
  compile_ruby(base, ruby)
274
258
  end
275
259
 
@@ -280,8 +264,8 @@ module ReVIEW
280
264
 
281
265
  def inline_href(arg)
282
266
  url, label = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/).map(&:lstrip)
283
- url = url.gsub(/\\,/, ",").strip
284
- label = label.gsub(/\\,/, ",").strip if label
267
+ url = url.gsub(/\\,/, ',').strip
268
+ label = label.gsub(/\\,/, ',').strip if label
285
269
  compile_href(url, label)
286
270
  end
287
271
 
@@ -292,17 +276,15 @@ module ReVIEW
292
276
  def bibpaper(lines, id, caption)
293
277
  bibpaper_header id, caption
294
278
  unless lines.empty?
295
- puts ""
279
+ puts
296
280
  bibpaper_bibpaper id, caption, lines
297
281
  end
298
- puts ""
282
+ puts
299
283
  end
300
284
 
301
285
  def inline_hd(id)
302
286
  m = /\A([^|]+)\|(.+)/.match(id)
303
- if m && m[1]
304
- chapter = @book.contents.detect{|chap| chap.id == m[1]}
305
- end
287
+ chapter = @book.contents.detect { |chap| chap.id == m[1] } if m && m[1]
306
288
  if chapter
307
289
  inline_hd_chap(chapter, m[2])
308
290
  else
@@ -315,7 +297,7 @@ module ReVIEW
315
297
 
316
298
  def inline_column(id)
317
299
  m = /\A([^|]+)\|(.+)/.match(id)
318
- chapter = @book.chapters.detect{|chap| chap.id == m[1]} if m && m[1]
300
+ chapter = @book.chapters.detect { |chap| chap.id == m[1] } if m && m[1]
319
301
  if chapter
320
302
  inline_column_chap(chapter, m[2])
321
303
  else
@@ -330,43 +312,40 @@ module ReVIEW
330
312
  chapter.column(id).caption
331
313
  end
332
314
 
315
+ def inline_pageref(id)
316
+ "[link:#{id}]"
317
+ end
318
+
333
319
  def inline_tcy(arg)
334
320
  "#{arg}[rotate 90 degree]"
335
321
  end
336
322
 
337
323
  def raw(str)
338
324
  if matched = str.match(/\|(.*?)\|(.*)/)
339
- builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
325
+ builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
340
326
  c = target_name
341
- if builders.include?(c)
342
- print matched[2].gsub("\\n", "\n")
343
- else
344
- ""
345
- end
327
+ print matched[2].gsub('\\n', "\n") if builders.include?(c)
346
328
  else
347
- print str.gsub("\\n", "\n")
329
+ print str.gsub('\\n', "\n")
348
330
  end
349
331
  end
350
332
 
351
333
  def embed(lines, arg = nil)
352
334
  if arg
353
- builders = arg.gsub(/^\s*\|/, "").gsub(/\|\s*$/, "").gsub(/\s/, "").split(/,/)
335
+ builders = arg.gsub(/^\s*\|/, '').gsub(/\|\s*$/, '').gsub(/\s/, '').split(',')
354
336
  c = target_name
355
- if builders.include?(c)
356
- print lines.join()
357
- else
358
- ""
359
- end
337
+ print lines.join if builders.include?(c)
360
338
  else
361
- print lines.join()
339
+ print lines.join
362
340
  end
363
341
  end
364
342
 
365
343
  def warn(msg)
366
- $stderr.puts "#{@location}: warning: #{msg}"
344
+ @logger.warn "#{@location}: #{msg}"
367
345
  end
368
346
 
369
347
  def error(msg)
348
+ raise ApplicationError, msg if msg =~ /:\d+: error: /
370
349
  raise ApplicationError, "#{@location}: error: #{msg}"
371
350
  end
372
351
 
@@ -379,53 +358,44 @@ module ReVIEW
379
358
  end
380
359
 
381
360
  def parse_metric(type, metric)
382
- return "" if metric.blank?
361
+ return '' if metric.blank?
383
362
  params = metric.split(/,\s*/)
384
363
  results = []
385
364
  params.each do |param|
386
365
  if param =~ /\A.+?::/
387
- if param =~ /\A#{type}::/
388
- param.sub!(/\A#{type}::/, '')
389
- else
390
- next
391
- end
366
+ next unless param =~ /\A#{type}::/
367
+ param.sub!(/\A#{type}::/, '')
392
368
  end
393
369
  param2 = handle_metric(param)
394
370
  results.push(param2)
395
371
  end
396
- return result_metric(results)
372
+ result_metric(results)
397
373
  end
398
374
 
399
375
  def get_chap(chapter = @chapter)
400
- if @book.config["secnolevel"] > 0 && !chapter.number.nil? && !chapter.number.to_s.empty?
401
- if chapter.is_a? ReVIEW::Book::Part
402
- return I18n.t('part_short', chapter.number)
403
- else
404
- return chapter.format_number(nil)
405
- end
376
+ if @book.config['secnolevel'] > 0 && !chapter.number.nil? && !chapter.number.to_s.empty?
377
+ return I18n.t('part_short', chapter.number) if chapter.is_a?(ReVIEW::Book::Part)
378
+ return chapter.format_number(nil)
406
379
  end
407
- return nil
380
+ nil
408
381
  end
409
382
 
410
383
  def extract_chapter_id(chap_ref)
411
384
  m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
412
- if m
413
- return [@book.contents.detect{|chap| chap.id == m[1]}, m[2]]
414
- else
415
- return [@chapter, chap_ref]
416
- end
385
+ return [@book.contents.detect { |chap| chap.id == m[1] }, m[2]] if m
386
+ [@chapter, chap_ref]
417
387
  end
418
388
 
419
- def captionblock(type, lines, caption, specialstyle = nil)
389
+ def captionblock(_type, _lines, _caption, _specialstyle = nil)
420
390
  raise NotImplementedError
421
391
  end
422
392
 
423
393
  CAPTION_TITLES.each do |name|
424
- class_eval %Q{
394
+ class_eval %Q(
425
395
  def #{name}(lines, caption = nil)
426
396
  captionblock("#{name}", lines, caption)
427
397
  end
428
- }
398
+ )
429
399
  end
430
400
 
431
401
  def graph(lines, id, command, caption = nil)
@@ -437,20 +407,20 @@ module ReVIEW
437
407
 
438
408
  line = self.unescape(lines.join("\n"))
439
409
  cmds = {
440
- :graphviz => "echo '#{line}' | dot -T#{image_ext} -o#{file_path}",
441
- :gnuplot => "echo 'set terminal " +
442
- "#{(image_ext == "eps") ? "postscript eps" : image_ext}\n" +
443
- " set output \"#{file_path}\"\n#{line}' | gnuplot",
444
- :blockdiag => "echo '#{line}' "+
410
+ graphviz: "echo '#{line}' | dot -T#{image_ext} -o#{file_path}",
411
+ gnuplot: %Q(echo 'set terminal ) +
412
+ "#{image_ext == 'eps' ? 'postscript eps' : image_ext}\n" +
413
+ %Q(" set output "#{file_path}"\n#{line}' | gnuplot),
414
+ blockdiag: "echo '#{line}' " +
445
415
  "| blockdiag -a -T #{image_ext} -o #{file_path} /dev/stdin",
446
- :aafigure => "echo '#{line}' | aafigure -t#{image_ext} -o#{file_path}",
416
+ aafigure: "echo '#{line}' | aafigure -t#{image_ext} -o#{file_path}"
447
417
  }
448
418
  cmd = cmds[command.to_sym]
449
419
  warn cmd
450
420
  system cmd
451
421
  @chapter.image_index.image_finder.add_entry(file_path)
452
422
 
453
- image(lines, id, caption ||= "")
423
+ image(lines, id, caption)
454
424
  end
455
425
 
456
426
  def image_ext
@@ -462,9 +432,7 @@ module ReVIEW
462
432
  end
463
433
 
464
434
  def include(file_name)
465
- File.foreach(file_name) do |line|
466
- paragraph([line])
467
- end
435
+ File.foreach(file_name) { |line| paragraph([line]) }
468
436
  end
469
437
 
470
438
  def ul_item_begin(lines)
@@ -476,11 +444,9 @@ module ReVIEW
476
444
 
477
445
  def tsize(str)
478
446
  if matched = str.match(/\A\|(.*?)\|(.*)/)
479
- builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
480
- c = self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
481
- if builders.include?(c)
482
- @tsize = matched[2]
483
- end
447
+ builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
448
+ c = self.class.to_s.gsub('ReVIEW::', '').gsub('Builder', '').downcase
449
+ @tsize = matched[2] if builders.include?(c)
484
450
  else
485
451
  @tsize = str
486
452
  end
@@ -488,25 +454,25 @@ module ReVIEW
488
454
 
489
455
  def inline_raw(args)
490
456
  if matched = args.match(/\|(.*?)\|(.*)/)
491
- builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
492
- c = self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
457
+ builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
458
+ c = self.class.to_s.gsub('ReVIEW::', '').gsub('Builder', '').downcase
493
459
  if builders.include?(c)
494
- matched[2].gsub("\\n", "\n")
460
+ matched[2].gsub('\\n', "\n")
495
461
  else
496
- ""
462
+ ''
497
463
  end
498
464
  else
499
- args.gsub("\\n", "\n")
465
+ args.gsub('\\n', "\n")
500
466
  end
501
467
  end
502
468
 
503
469
  def inline_embed(args)
504
470
  if matched = args.match(/\|(.*?)\|(.*)/)
505
- builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
471
+ builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
506
472
  if builders.include?(target_name)
507
473
  matched[2]
508
474
  else
509
- ""
475
+ ''
510
476
  end
511
477
  else
512
478
  args
@@ -524,5 +490,4 @@ module ReVIEW
524
490
  end
525
491
  end
526
492
  end
527
-
528
493
  end # module ReVIEW