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,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
4
2
  # KADO Masanori
5
3
  #
@@ -9,7 +7,6 @@
9
7
  #
10
8
 
11
9
  module ReVIEW
12
-
13
10
  # Secion Counter class
14
11
  #
15
12
  class SecCounter
@@ -24,21 +21,13 @@ module ReVIEW
24
21
 
25
22
  def inc(level)
26
23
  n = level - 2
27
- if n >= 0
28
- @counter[n] += 1
29
- end
30
- if @counter.size > n
31
- (n+1..@counter.size).each do |i|
32
- @counter[i] = 0
33
- end
34
- end
24
+ @counter[n] += 1 if n >= 0
25
+ (n + 1..@counter.size).each { |i| @counter[i] = 0 } if @counter.size > n
35
26
  end
36
27
 
37
28
  def anchor(level)
38
- str = "#{@chapter.format_number(false)}"
39
- 0.upto(level-2) do |i|
40
- str << "-#{@counter[i]}"
41
- end
29
+ str = @chapter.format_number(false)
30
+ 0.upto(level - 2) { |i| str << "-#{@counter[i]}" }
42
31
  str
43
32
  end
44
33
 
@@ -46,27 +35,22 @@ module ReVIEW
46
35
  return nil if @chapter.number.blank?
47
36
 
48
37
  if level == 1
49
- if secnolevel >= 1
50
- if @chapter.is_a? ReVIEW::Book::Part
51
- num = @chapter.number
52
- return "#{I18n.t('part', num)}#{I18n.t("chapter_postfix")}"
53
- else
54
- return "#{@chapter.format_number}#{I18n.t("chapter_postfix")}"
55
- end
56
- end
57
- elsif secnolevel >= level
58
- prefix = ''
59
- if @chapter.is_a? ReVIEW::Book::Part
60
- prefix = I18n.t('part_short', @chapter.number)
38
+ return nil unless secnolevel >= 1
39
+ if @chapter.is_a?(ReVIEW::Book::Part)
40
+ num = @chapter.number
41
+ "#{I18n.t('part', num)}#{I18n.t('chapter_postfix')}"
61
42
  else
62
- prefix = @chapter.format_number(false)
43
+ "#{@chapter.format_number}#{I18n.t('chapter_postfix')}"
63
44
  end
64
-
65
- 0.upto(level - 2) do |i|
66
- prefix << ".#{@counter[i]}"
67
- end
68
- prefix << I18n.t("chapter_postfix")
69
- return prefix
45
+ elsif secnolevel >= level
46
+ prefix = if @chapter.is_a?(ReVIEW::Book::Part)
47
+ I18n.t('part_short', @chapter.number)
48
+ else
49
+ @chapter.format_number(false)
50
+ end
51
+ 0.upto(level - 2) { |i| prefix << ".#{@counter[i]}" }
52
+ prefix << I18n.t('chapter_postfix')
53
+ prefix
70
54
  end
71
55
  end
72
56
  end
@@ -4,17 +4,16 @@ module ReVIEW
4
4
  class Template
5
5
  include ERB::Util
6
6
 
7
- TEMPLATE_DIR = File.join(File.dirname(__FILE__), "../../templates")
7
+ TEMPLATE_DIR = File.join(File.dirname(__FILE__), '../../templates')
8
8
 
9
9
  def self.load(filename, mode = 1)
10
10
  self.new(filename, mode)
11
11
  end
12
12
 
13
13
  def initialize(filename = nil, mode = nil)
14
- if filename
15
- content = File.read(filename)
16
- @erb = ERB.new(content, nil, mode)
17
- end
14
+ return unless filename
15
+ content = File.read(filename)
16
+ @erb = ERB.new(content, nil, mode)
18
17
  end
19
18
 
20
19
  def result(bind_data = nil)
@@ -1,6 +1,7 @@
1
1
  # textbuilder.rb
2
2
  #
3
- # Copyright (c) 2010 Kenshi Muto
3
+ # Copyright (c) 2010-2017 Kenshi Muto
4
+ # 2010 Kenshi Muto
4
5
  #
5
6
  # This program is free software.
6
7
  # You can distribute or modify this program under the terms of
@@ -10,8 +11,6 @@
10
11
  require 'review/topbuilder'
11
12
 
12
13
  module ReVIEW
13
-
14
14
  class TEXTBuilder < TOPBuilder
15
15
  end
16
-
17
16
  end # module ReVIEW
@@ -1,4 +1,3 @@
1
- # $Id: textutils.rb 2192 2005-11-13 11:55:42Z aamine $
2
1
  require 'nkf'
3
2
 
4
3
  module ReVIEW
@@ -6,11 +5,11 @@ module ReVIEW
6
5
  def detab(str, ts = 8)
7
6
  add = 0
8
7
  len = nil
9
- str.gsub(/\t/) {
8
+ str.gsub("\t") do
10
9
  len = ts - ($`.size + add) % ts
11
10
  add += len - 1
12
11
  ' ' * len
13
- }
12
+ end
14
13
  end
15
14
 
16
15
  def split_paragraph(lines)
@@ -18,21 +17,16 @@ module ReVIEW
18
17
  post = post_paragraph
19
18
 
20
19
  blocked_lines = [[]]
21
- lines.each {|element|
22
- if element == ""
23
- if blocked_lines.last != []
24
- blocked_lines << []
25
- end
20
+ lines.each do |element|
21
+ if element.empty?
22
+ blocked_lines << [] if blocked_lines.last != []
26
23
  else
27
24
  blocked_lines.last << element
28
25
  end
29
- }
30
-
31
- if !pre.nil? and !post.nil?
32
- blocked_lines.map!{|i| [pre] + i + [post] }
33
26
  end
34
27
 
35
- blocked_lines.map{|l| l.join("")}
28
+ blocked_lines.map! { |i| [pre] + i + [post] } if pre && post
29
+ blocked_lines.map(&:join)
36
30
  end
37
31
  end
38
32
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Copyright (c) 2002-2007 Minero Aoki
3
- # 2008-2016 Minero Aoki, Kenshi Muto
2
+ # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto
3
+ # 2002-2007 Minero Aoki
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -13,9 +13,8 @@ require 'review/book'
13
13
  require 'review/textbuilder'
14
14
 
15
15
  module ReVIEW
16
-
17
16
  class TOCParser
18
- def TOCParser.parse(chap)
17
+ def self.parse(chap)
19
18
  f = StringIO.new(chap.content, 'r:BOM|utf-8')
20
19
  stream = Preprocessor::Strip.new(f)
21
20
  new.parse(stream, chap).map do |root|
@@ -24,24 +23,24 @@ module ReVIEW
24
23
  end
25
24
  end
26
25
 
27
- def TOCParser.chapter_node(chap)
28
- toc = TOCParser.parse(chap)
29
- unless toc.size == 1
30
- $stderr.puts "warning: chapter #{toc.join} contains more than 1 chapter"
31
- end
26
+ def self.chapter_node(chap)
27
+ toc = self.parse(chap)
28
+ $stderr.puts "warning: chapter #{toc.join} contains more than 1 chapter" unless toc.size == 1
32
29
  toc.first
33
30
  end
34
31
 
35
32
  def parse(f, chap)
36
- roots = [] ## list of chapters
33
+ roots = [] # list of chapters
37
34
  node_stack = []
38
35
  filename = chap.path
39
36
  while line = f.gets
40
37
  case line
41
38
  when /\A\#@/
42
39
  # do nothing
40
+ next
43
41
  when /\A\s*\z/
44
42
  # do nothing
43
+ next
45
44
  when /\A(={2,})[\[\s\{]/
46
45
  lev = $1.size
47
46
  error! filename, f.lineno, "section level too deep: #{lev}" if lev > 5
@@ -52,11 +51,9 @@ module ReVIEW
52
51
  node_stack.push dummy_chapter
53
52
  roots.push dummy_chapter
54
53
  end
55
- next if label =~ /\A\[\// # ex) "[/column]"
56
- sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, ""))
57
- until node_stack.last.level < sec.level
58
- node_stack.pop
59
- end
54
+ next if label =~ %r{\A\[/} # ex) "[/column]"
55
+ sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, ''))
56
+ node_stack.pop until node_stack.last.level < sec.level
60
57
  node_stack.last.add_child sec
61
58
  node_stack.push sec
62
59
 
@@ -67,25 +64,24 @@ module ReVIEW
67
64
  node_stack.push new_chapter
68
65
  roots.push new_chapter
69
66
 
70
- when %r<\A//\w+(?:\[.*?\])*\{\s*\z>
71
- if node_stack.empty?
72
- error! filename, f.lineno, 'list found before section label'
73
- end
67
+ when %r{\A//\w+(?:\[.*?\])*\{\s*\z}
68
+ error! filename, f.lineno, 'list found before section label' if node_stack.empty?
74
69
  node_stack.last.add_child(list = List.new)
75
70
  beg = f.lineno
76
71
  list.add line
77
72
  while line = f.gets
78
- break if %r<\A//\}> =~ line
73
+ break if %r{\A//\}} =~ line
79
74
  list.add line
80
75
  end
81
76
  error! filename, beg, 'unterminated list' unless line
82
77
 
83
- when %r<\A//\w>
78
+ when %r{\A//\w}
84
79
  # do nothing
80
+ next
85
81
  else
86
- #if node_stack.empty?
87
- # error! filename, f.lineno, 'text found before section label'
88
- #end
82
+ # if node_stack.empty?
83
+ # error! filename, f.lineno, 'text found before section label'
84
+ # end
89
85
  next if node_stack.empty?
90
86
  node_stack.last.add_child(par = Paragraph.new(chap))
91
87
  par.add line
@@ -108,7 +104,7 @@ module ReVIEW
108
104
  b = ReVIEW::TEXTBuilder.new
109
105
  dummy_book = ReVIEW::Book::Base.load
110
106
  dummy_chapter = ReVIEW::Book::Chapter.new(dummy_book, 1, '-', nil, StringIO.new)
111
- dummy_loc = Location.new("", StringIO.new)
107
+ dummy_loc = Location.new('', StringIO.new)
112
108
  b.bind(ReVIEW::Compiler.new(b), dummy_chapter, dummy_loc)
113
109
  b.compile_inline(line)
114
110
  end
@@ -117,9 +113,7 @@ module ReVIEW
117
113
  raise "#{filename}:#{lineno}: #{msg}"
118
114
  end
119
115
 
120
-
121
116
  class Node
122
-
123
117
  def initialize(children = [])
124
118
  @children = children
125
119
  end
@@ -146,9 +140,7 @@ module ReVIEW
146
140
  end
147
141
 
148
142
  def each_section(&block)
149
- @children.each do |n|
150
- n.yield_section(&block)
151
- end
143
+ @children.each { |n| n.yield_section(&block) }
152
144
  end
153
145
 
154
146
  def each_section_with_index
@@ -161,22 +153,17 @@ module ReVIEW
161
153
 
162
154
  def section_size
163
155
  cnt = 0
164
- @children.each do |n|
165
- n.yield_section { cnt += 1 }
166
- end
156
+ @children.each { |n| n.yield_section { cnt += 1 } }
167
157
  cnt
168
158
  end
169
-
170
159
  end
171
160
 
172
-
173
161
  class Section < Node
174
-
175
162
  def initialize(level, label, path = nil)
176
163
  super()
177
164
  @level = level
178
165
  @label = label
179
- @filename = (path ? real_filename(path) : nil)
166
+ @filename = path ? real_filename(path) : nil
180
167
  end
181
168
 
182
169
  def real_filename(path)
@@ -192,7 +179,7 @@ module ReVIEW
192
179
  attr_reader :label
193
180
 
194
181
  def estimated_lines
195
- @children.inject(0) {|sum, n| sum + n.estimated_lines }
182
+ @children.inject(0) { |sum, n| sum + n.estimated_lines }
196
183
  end
197
184
 
198
185
  def yield_section
@@ -200,14 +187,11 @@ module ReVIEW
200
187
  end
201
188
 
202
189
  def inspect
203
- "\#<#{self.class} level=#{@level} #{@label}>"
190
+ "#<#{self.class} level=#{@level} #{@label}>"
204
191
  end
205
-
206
192
  end
207
193
 
208
-
209
194
  class Chapter < Section
210
-
211
195
  def initialize(label, chap)
212
196
  super 1, label, chap.path
213
197
  @chapter = chap
@@ -229,26 +213,23 @@ module ReVIEW
229
213
  def volume
230
214
  return @volume if @volume
231
215
  @volume = @chapter.volume
232
- @volume.lines = estimated_lines()
216
+ @volume.lines = estimated_lines
233
217
  @volume
234
218
  end
235
219
 
236
220
  def inspect
237
- "\#<#{self.class} #{@filename}>"
221
+ "#<#{self.class} #{@filename}>"
238
222
  end
239
-
240
223
  end
241
224
 
242
-
243
225
  class Paragraph < Node
244
-
245
226
  def initialize(chap)
246
227
  @bytes = 0
247
228
  @page_metric = chap.book.page_metric
248
229
  end
249
230
 
250
231
  def inspect
251
- "\#<#{self.class}>"
232
+ "#<#{self.class}>"
252
233
  end
253
234
 
254
235
  def add(line)
@@ -261,21 +242,18 @@ module ReVIEW
261
242
 
262
243
  def yield_section
263
244
  end
264
-
265
245
  end
266
246
 
267
-
268
247
  class List < Node
269
-
270
248
  def initialize
271
249
  @lines = 0
272
250
  end
273
251
 
274
252
  def inspect
275
- "\#<#{self.class}>"
253
+ "#<#{self.class}>"
276
254
  end
277
255
 
278
- def add(line)
256
+ def add(_line)
279
257
  @lines += 1
280
258
  end
281
259
 
@@ -285,9 +263,6 @@ module ReVIEW
285
263
 
286
264
  def yield_section
287
265
  end
288
-
289
266
  end
290
-
291
267
  end
292
268
  end
293
-
@@ -1,9 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # $Id: tocprinter.rb 4309 2009-07-19 04:15:02Z aamine $
4
- #
5
- # Copyright (c) 2002-2007 Minero Aoki
6
- # 2008-2009 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto
2
+ # 2002-2007 Minero Aoki
7
3
  #
8
4
  # This program is free software.
9
5
  # You can distribute or modify this program under the terms of
@@ -15,10 +11,8 @@ require 'review/htmlutils'
15
11
  require 'review/tocparser'
16
12
 
17
13
  module ReVIEW
18
-
19
14
  class TOCPrinter
20
-
21
- def TOCPrinter.default_upper_level
15
+ def self.default_upper_level
22
16
  99 # no one use 99 level nest
23
17
  end
24
18
 
@@ -29,15 +23,11 @@ module ReVIEW
29
23
  end
30
24
 
31
25
  def print_book(book)
32
- book.each_part do |part|
33
- print_part(part)
34
- end
26
+ book.each_part { |part| print_part(part) }
35
27
  end
36
28
 
37
29
  def print_part(part)
38
- part.each_chapter do |chap|
39
- print_chapter(chap)
40
- end
30
+ part.each_chapter { |chap| print_chapter(chap) }
41
31
  end
42
32
 
43
33
  def print_chapter(chap)
@@ -51,16 +41,14 @@ module ReVIEW
51
41
  end
52
42
  end
53
43
 
54
-
55
44
  class TextTOCPrinter < TOCPrinter
56
-
57
45
  private
58
46
 
59
47
  def print_children(node)
60
48
  return unless print?(node.level + 1)
61
49
  node.each_section_with_index do |section, idx|
62
50
  unless section.blank?
63
- print_node idx+1, section
51
+ print_node idx + 1, section
64
52
  print_children section
65
53
  end
66
54
  end
@@ -85,42 +73,35 @@ module ReVIEW
85
73
  end
86
74
 
87
75
  def volume_columns(level, volstr)
88
- cols = ["", "", "", nil]
76
+ cols = ['', '', '', nil]
89
77
  cols[level - 1] = volstr
90
78
  cols[0, 3] # does not display volume of level-4 section
91
79
  end
92
-
93
80
  end
94
81
 
95
-
96
82
  class HTMLTOCPrinter < TOCPrinter
97
-
98
83
  include HTMLUtils
99
84
 
100
85
  def print_book(book)
101
86
  @out.puts '<ul class="book-toc">'
102
- book.each_part do |part|
103
- print_part(part)
104
- end
87
+ book.each_part { |part| print_part(part) }
105
88
  @out.puts '</ul>'
106
89
  end
107
90
 
108
91
  def print_part(part)
109
- if part.number
110
- @out.puts li(part.title)
111
- end
92
+ @out.puts li(part.title) if part.number
112
93
  super
113
94
  end
114
95
 
115
96
  def print_chapter(chap)
116
97
  chap_node = TOCParser.chapter_node(chap)
117
- ext = chap.book.config["htmlext"] || "html"
118
- path = chap.path.sub(/\.re/, "."+ext)
119
- if chap_node.number && chap.on_CHAPS?
120
- label = "#{chap.number} #{chap.title}"
121
- else
122
- label = chap.title
123
- end
98
+ ext = chap.book.config['htmlext'] || 'html'
99
+ path = chap.path.sub(/\.re/, '.' + ext)
100
+ label = if chap_node.number && chap.on_chaps?
101
+ "#{chap.number} #{chap.title}"
102
+ else
103
+ chap.title
104
+ end
124
105
  @out.puts li(a_name(path, escape_html(label)))
125
106
  return unless print?(2)
126
107
  if print?(3)
@@ -133,14 +114,12 @@ module ReVIEW
133
114
  private
134
115
 
135
116
  def chap_sections_to_s(chap)
136
- return "" if chap.section_size < 1
117
+ return '' if chap.section_size < 1
137
118
  res = []
138
- res << "<ol>"
139
- chap.each_section do |sec|
140
- res << li(escape_html(sec.label))
141
- end
142
- res << "</ol>"
143
- return res.join("\n")
119
+ res << '<ol>'
120
+ chap.each_section { |sec| res << li(escape_html(sec.label)) }
121
+ res << '</ol>'
122
+ res.join("\n")
144
123
  end
145
124
 
146
125
  def chapter_to_s(chap)
@@ -148,15 +127,12 @@ module ReVIEW
148
127
  chap.each_section do |sec|
149
128
  res << li(escape_html(sec.label))
150
129
  next unless print?(4)
151
- if sec.section_size > 0
152
- res << "<ul>"
153
- sec.each_section do |node|
154
- res << li(escape_html(node.label))
155
- end
156
- res << "</ul>"
157
- end
130
+ next unless sec.section_size > 0
131
+ res << '<ul>'
132
+ sec.each_section { |node| res << li(escape_html(node.label)) }
133
+ res << '</ul>'
158
134
  end
159
- return res.join("\n")
135
+ res.join("\n")
160
136
  end
161
137
 
162
138
  def li(content)
@@ -166,7 +142,5 @@ module ReVIEW
166
142
  def a_name(name, label)
167
143
  %Q(<a name="#{name}">#{label}</a>)
168
144
  end
169
-
170
145
  end
171
-
172
146
  end